diff --git a/SRC/Private/InterfaceMap.cs b/SRC/Private/InterfaceMap.cs new file mode 100644 index 0000000..d8ce957 --- /dev/null +++ b/SRC/Private/InterfaceMap.cs @@ -0,0 +1,41 @@ +/******************************************************************************** +* InterfaceMap.cs * +* * +* Author: Denes Solti * +********************************************************************************/ +using System; +using System.Collections.Generic; +using System.Reflection; + +namespace Solti.Utils.Proxy.Internals +{ + /// + /// Cached interface mappings. Intended for private use only. + /// + public static class InterfaceMap + where TInterface: class + where TImplementation: TInterface + { + private static IReadOnlyDictionary GetMappings() + { + Dictionary 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; + } + + /// + /// Returns the cached mappings. + /// + public static IReadOnlyDictionary Mappings { get; } = GetMappings(); + } +} diff --git a/SRC/PublicAPI/netstandard2.0/PublicAPI.Unshipped.txt b/SRC/PublicAPI/netstandard2.0/PublicAPI.Unshipped.txt index 0ea77bf..f10ec57 100644 --- a/SRC/PublicAPI/netstandard2.0/PublicAPI.Unshipped.txt +++ b/SRC/PublicAPI/netstandard2.0/PublicAPI.Unshipped.txt @@ -2,4 +2,6 @@ Solti.Utils.Proxy.InterfaceInterceptor Solti.Utils.Proxy.InterfaceInterceptor.InterfaceInterceptor(TTarget? target) -> void Solti.Utils.Proxy.InterfaceInterceptor.Proxy.set -> void Solti.Utils.Proxy.InterfaceInterceptor.Target.get -> TTarget? +Solti.Utils.Proxy.Internals.InterfaceMap +static Solti.Utils.Proxy.Internals.InterfaceMap.Mappings.get -> System.Collections.Generic.IReadOnlyDictionary! virtual Solti.Utils.Proxy.InterfaceInterceptor.Invoke(Solti.Utils.Proxy.InvocationContext! context) -> object? \ No newline at end of file diff --git a/SRC/PublicAPI/netstandard2.1/PublicAPI.Unshipped.txt b/SRC/PublicAPI/netstandard2.1/PublicAPI.Unshipped.txt index 0ea77bf..f10ec57 100644 --- a/SRC/PublicAPI/netstandard2.1/PublicAPI.Unshipped.txt +++ b/SRC/PublicAPI/netstandard2.1/PublicAPI.Unshipped.txt @@ -2,4 +2,6 @@ Solti.Utils.Proxy.InterfaceInterceptor Solti.Utils.Proxy.InterfaceInterceptor.InterfaceInterceptor(TTarget? target) -> void Solti.Utils.Proxy.InterfaceInterceptor.Proxy.set -> void Solti.Utils.Proxy.InterfaceInterceptor.Target.get -> TTarget? +Solti.Utils.Proxy.Internals.InterfaceMap +static Solti.Utils.Proxy.Internals.InterfaceMap.Mappings.get -> System.Collections.Generic.IReadOnlyDictionary! virtual Solti.Utils.Proxy.InterfaceInterceptor.Invoke(Solti.Utils.Proxy.InvocationContext! context) -> object? \ No newline at end of file