mardi 21 septembre 2021

Reflection in .NET

class Program
{
    static void Main(string[] args)
    {
        Type doub = typeof(Doub);
        object result = doub.InvokeMember("Call", BindingFlags.InvokeMethod, null, null, new object[] { });
    }
}

public class Doub
{
    public Collection<string> Call()
    {
        Collection<string> collection = new Collection<string>();
        return collection;
    }

    public Collection<T> Call<T>()
    {
        Collection<T> collection = new Collection<T>();
        return collection;
    }
}

I tried to call the Call method, but the program cannot figure out which method to call. Error: (System.Reflection.AmbiguousMatchException: "Ambiguous match found). How can you call exactly the Call() method of the class?





Aucun commentaire:

Enregistrer un commentaire