c# - Determine if MethodInfo represents a lambda expression -


how 1 determine if methodinfo represents metadata lambda expression?

i think talking anonymous methods.so, can write extension method , check whether name of method contains invalid chars.because compiler generated methods contains invalid chars, can use feature determine whether method anonymous or not:

public static bool isanonymous(this methodinfo method) {      var invalidchars = new[] {'<', '>'};      return method.name.any(invalidchars.contains); } 

test:

func<int> f = () => 23;  console.write(f.method.isanonymous());  // true 

more elegant why validating method name using isvalidlanguageindependentidentifier method, (method this answer):

public static bool isanonymous(this methodinfo method) {     return !codegenerator.isvalidlanguageindependentidentifier(method.name); } 

remember in order access isvalidlanguageindependentidentifier method need include system.codedom.compiler namespace.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -