CSharp examples for System.Reflection:MethodInfo
Get Method
using System.Reflection; using System.Linq; using System.Collections.Generic; using System;//from w ww. j a va2s .co m public class Main{ public static MethodInfo GetMethod(this Type type, string name, BindingFlags bindingFlags, object binder, Type[] types, object modifiers) { return type.GetTypeInfo().DeclaredMethods.FirstOrDefault( m => (m.Name == name) && IsConformWithBindingFlags(m, bindingFlags) && TypesAreEqual(m.GetParameters().Select(p => p.ParameterType).ToArray(), types)); } public static MethodInfo GetMethod(this Type type, string name, Type[] types) { return type.GetTypeInfo().DeclaredMethods.FirstOrDefault( m => (m.Name == name) && TypesAreEqual(m.GetParameters().Select(p => p.ParameterType).ToArray(), types)); } public static MethodInfo GetMethod(this Type type, string name, BindingFlags bindingFlags) { return type.GetTypeInfo().DeclaredMethods.FirstOrDefault(m => (m.Name == name) && IsConformWithBindingFlags(m, bindingFlags)); } public static MethodInfo GetMethod(this Type type, string name) { return type.GetTypeInfo().DeclaredMethods.FirstOrDefault(m => m.Name == name); } }