I am not sure, but you can only get an extension method from the static class using reflection. Extension methods are not truly added to the class, therefore can't be retrieved with GetMethod.
Thanks, I suppose I need to call GetMethod this way: typeof(StringEx). GetMethod("Like", new {typeof(string)}); but how I have to inject my parameters in Expression. Call?
– CodeAddicted Dec 1 at 7:27 See @Lonli-Lokli's answer below. – Minustar Dec 1 at 11:43.
Use var like = typeof(StringEx). GetMethod("Like", new {typeof(string),typeof(string)}); ie. Retrieve it from the extending type, not from the extended type.
Thanks a lot, but this throws an argument exception: Need null instance for static method, so I need some magic with BindingFlags. Static, but this is outside from my comprehension( – CodeAddicted Dec 1 at 7:33.
If you want to get your extension method worked you must do like this: string str = "some string"; str. Like("second string").
Try this public class Person { public string Name { get; set; } } public static class StringEx { public static bool Like(this string a, string b) { return a.ToLower(). Contains(b.ToLower()); } } Person p = new Person(){Name = "Me"}; var prop = Expression. Property(Expression.
Constant(p), "Name"); var value = Expression. Constant("me"); var like = typeof(StringEx). GetMethod("Like", BindingFlags.
Static | BindingFlags. Public | BindingFlags. NonPublic); var comparer = Expression.
Call(null, like, prop, value ); var vvv = (Func) Expression. Lambda(comparer).Compile(); bool isEquals = vvv.Invoke().
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.