dimanche 10 décembre 2017

Check MethodInfo instance is implementation of interface generic method

I has interface

public interface ITest
{
    Task<bool> MyMethod<T>(string key, out T value);
}

And they implementation

public class TestImpl : ITest
{
    public Task<bool> MyMethod<T>(string key, out T value) // Implements interface
    {
        // Skipped
    }

    public Task<bool> MyMethod<T>(string key, T value) // Does not implements interface
    {
        // Skipped
    }
}

I need to check that specified instance of MethodInfo is method implementation of ITest interface.

For example:

foreach (var methodInfo in typeof(TestImpl).GetMethods())
{
    // Check methodInfo is implementation of MyMethod declared in ITest interface
}

How to do that?





Aucun commentaire:

Enregistrer un commentaire