blob: aec09c82a70c7a0de7692a82ce924333a473baac (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.PortableExecutable;
namespace ILVerify
{
public interface IResolver
{
/// <summary>
/// This method should return the same instance when queried multiple times.
/// </summary>
PEReader Resolve(string simpleName);
}
/// <summary>
/// Provides caching logic for implementations of IResolver
/// </summary>
public abstract class ResolverBase : IResolver
{
private readonly Dictionary<string, PEReader> _resolverCache = new Dictionary<string, PEReader>();
public PEReader Resolve(string simpleName)
{
if (_resolverCache.TryGetValue(simpleName, out PEReader peReader))
{
return peReader;
}
PEReader result = ResolveCore(simpleName);
if (result != null)
{
_resolverCache.Add(simpleName, result);
return result;
}
return null;
}
protected abstract PEReader ResolveCore(string simpleName);
}
}
|