-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/******************************************************************************** | ||
* InterfaceMap.cs * | ||
* * | ||
* Author: Denes Solti * | ||
********************************************************************************/ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
|
||
namespace Solti.Utils.Proxy.Internals | ||
{ | ||
/// <summary> | ||
/// Cached interface mappings. Intended for private use only. | ||
/// </summary> | ||
public static class InterfaceMap<TInterface, TImplementation> | ||
where TInterface: class | ||
where TImplementation: TInterface | ||
{ | ||
private static IReadOnlyDictionary<MethodInfo, MethodInfo> GetMappings() | ||
{ | ||
Dictionary<MethodInfo, MethodInfo> dict = new(); | ||
|
||
foreach (Type iface in typeof(TInterface).GetHierarchy()) | ||
{ | ||
InterfaceMapping mapping = typeof(TImplementation).GetInterfaceMap(iface); | ||
|
||
for (int i = 0; i < mapping.InterfaceMethods.Length; i++) | ||
{ | ||
dict.Add(mapping.InterfaceMethods[i], mapping.TargetMethods[i]); | ||
} | ||
} | ||
|
||
return dict; | ||
} | ||
|
||
/// <summary> | ||
/// Returns the cached mappings. | ||
/// </summary> | ||
public static IReadOnlyDictionary<MethodInfo, MethodInfo> Mappings { get; } = GetMappings(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters