Skip to content

Instantly share code, notes, and snippets.

@ForNeVeR
Last active April 27, 2022 16:17
Show Gist options
  • Save ForNeVeR/a0da2ffc4fd569c5d5e24ed19493321c to your computer and use it in GitHub Desktop.
Save ForNeVeR/a0da2ffc4fd569c5d5e24ed19493321c to your computer and use it in GitHub Desktop.

Revisions

  1. ForNeVeR renamed this gist Apr 27, 2022. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. ForNeVeR created this gist Oct 15, 2019.
    27 changes: 27 additions & 0 deletions Program.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    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
    }
    }