如何使用反射调用方法

时间:2016-06-14 11:04:25

标签: c#

如何使用反射来调用此方法。

using System.Reflection

public static string NotSoObvius<V>(V show) where V : class
    {
        return string.Format("This is it", show);
    }

1 个答案:

答案 0 :(得分:-1)

你应该尝试这样的事情:

Type myType = Type.GetType("MyClass");
MethodInfo notSoObviusInfo = myType.GetMethod("NotSoObvius");
Type[] types = new Type[]{typeof(YourDesiredTypeHere)};
notSoObviusInfo = notSoObviusInfo.MakeGenericMethod(types);
string myReturn = (string)notSoObviusInfo.Invoke(null, new[]{new YourDesiredTypeHere()});

来自:https://msdn.microsoft.com/pt-br/library/a89hcwhh(v=vs.110).aspx