lundi 9 septembre 2019

where is the interface saved?

Here is my test code:

The extension method GetInstructions is from here: https://gist.github.com/jbevain/104001

using System;
using System.Linq;
using System.Reflection;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var methods = typeof(TestClass)
                 .GetMethod("TestMethod")
                 .GetInstructions()
                 .Select(x => x.Operand as MethodInfo)
                 .Where(x => x != null)
                 .ToList();

            methods.ForEach(method => Console.WriteLine(method));

            Console.ReadLine();
        }
    }

    interface IBase
    {
        void Hello();
    }

    interface IFoo : IBase
    {

    }

    interface IBar : IBase
    {

    }

    class HelloWorld
    {
        public static void Say<T>() where T : IBase
        {
            Console.WriteLine($"Hello from {typeof(T)}.");
        }
    }
    class TestClass
    {
        public void TestMethod()
        {
            HelloWorld.Say<IFoo>();
        }
    }
}

The Instruction.Operand shows correct method calls:

Void Say[IFoo]()

but my question is:

where is the information of interface IFoo stored inside the object Instruction.Operand?

Thanks a lot.

enter image description here





Aucun commentaire:

Enregistrer un commentaire