Last active
April 27, 2022 16:17
-
-
Save ForNeVeR/a0da2ffc4fd569c5d5e24ed19493321c to your computer and use it in GitHub Desktop.
Shows how interface maps work for implicit and explicit interface implementations in C#.
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
using System; | |
using System.Reflection; | |
public interface ITest | |
{ | |
void TestFun(int arg); | |
} | |
public class TestClass : ITest | |
{ | |
void ITest.TestFun(int a) | |
{ | |
Console.WriteLine("xxx"); | |
} | |
} | |
class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
InterfaceMapping interfaceMap = typeof(TestClass).GetInterfaceMap(typeof(ITest)); | |
MethodInfo methodInfo = interfaceMap.TargetMethods[0]; | |
MethodInfo methodInfo2 = interfaceMap.InterfaceMethods[0]; | |
Console.WriteLine(methodInfo.Name); // ITest.TestFun | |
Console.WriteLine(methodInfo2.Name); // TestFun | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment