reflection - Invoke Generic Extension method on an Object? -


I have created a common extension method for the DataRow object. The method does not take any arguments, I use the methodInfo, through the medium of reflection I want to invite generic method. I can do this for normal public ways, but in some way I can not find a reference to the general extension method.

Whatever I have read is related to my query but no luck is in this way.

Keep in mind that the extension methods are compiler moves if you see the static method of the static class where the extension method If it is defined then you can bring it properly.

Now, if you have an object and you can find the extension method by searching for all your stable classes in the app domain, in which special Code> System.Runtime.CompilerServices.ExtensionAttribute and the absolute sequence in the specific method name and question

If two extension classes define an extension method with the same name and signature, this approach fails Will go It will also fail if the assembly is not loaded in the AP domain.

The simple approach is this (assuming you are looking for a common method):

  Fixed class extensions {public static t echo & lt; T & gt; (This T. OBJ) {return obj; }} Class Program {Static Wide Men (String [] ARGs) {Console.WriteLine ("Hello" .Echo ()); Var mi = typef (extension) .GetMethod ("Echo"); Var general = mi.MakeGenericMethod (typef (string)); Console.witline (normal infoc (empty, new object [] {"hello"})); Console.ReadKey (); }}  

Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -