मैंने विस्तार विधि GenericExtension
लिखा था। अब मैं एक्सटेंशन विधि Extension
पर कॉल करना चाहता हूं। लेकिन methodInfo
का मान हमेशा शून्य है।प्रतिबिंब के साथ एक सामान्य विस्तार विधि कैसे कॉल करें?
public static class MyClass
{
public static void GenericExtension<T>(this Form a, string b) where T : Form
{
// code...
}
public static void Extension(this Form a, string b, Type c)
{
MethodInfo methodInfo = typeof(Form).GetMethod("GenericExtension", new[] { typeof(string) });
MethodInfo methodInfoGeneric = methodInfo.MakeGenericMethod(new[] { c });
methodInfoGeneric.Invoke(a, new object[] { a, b });
}
private static void Main(string[] args)
{
new Form().Extension("", typeof (int));
}
}
क्या गलत है?
देखें http://stackoverflow.com/questions/5959219/how उपयोग करने के लिए-प्रतिबिंब-से-get-extension-method-on-generic-type? rq = 1 उस पर अधिक जानकारी के लिए। – skarmats