468,256 Members | 1,423 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,256 developers. It's quick & easy.

Calling extension method using reflection

How to call extension method using reflection ?

I tried this code but methodInfo is null.

Andrus.
using System.Reflection;
using System.Windows.Forms;

public class Customer { }

public static class CustomerExtension {
public static string FindById(this Customer c, string id) {
return "";
}
}

class Program {

static void Main() {
MethodInfo methodInfo = typeof(Customer).GetMethod("FindById",
BindingFlags.Public | BindingFlags.FlattenHierarchy
| BindingFlags.Static);
MessageBox.Show((methodInfo == null).ToString());
}

}
Jan 5 '08 #1
1 6812
Andrus <ko********@hot.eewrote:
How to call extension method using reflection ?
Find the static method and call it like any other static method.

Extension methods are entirely a compile-time deal.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Jan 5 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by jacew | last post: by
7 posts views Thread by Jorgen Haukland, Norway | last post: by
1 post views Thread by jens Jensen | last post: by
15 posts views Thread by =?Utf-8?B?VG9tIENvcmNvcmFu?= | last post: by
7 posts views Thread by =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.