public static ConstructorInfo GetConstructorSmart(this Type type, Type[] parameterTypes) { if (type.IsGenericType && type.ContainsTypeBuilders()) { var genericDefinition = type.GetGenericTypeDefinition(); var constructorInfo = genericDefinition.GetConstructor(parameterTypes); return TypeBuilder.GetConstructor(type, constructorInfo); } return type.GetConstructor(parameterTypes); }
public static MethodInfo GetMethodSmart(this Type type, string methodName) { if (type.IsGenericType && type.ContainsTypeBuilders()) { var genericDefinition = type.GetGenericTypeDefinition(); var methodInfo = genericDefinition.GetMethod(methodName); return TypeBuilder.GetMethod(type, methodInfo); } return type.GetMethod(methodName); }
//获取 public static MethodInfo GetMethodSmart(this Type type, Func<MethodInfo, bool> isCorrectMethod) { if (type.IsGenericType && type.ContainsTypeBuilders()) { var genericDefinition = type.GetGenericTypeDefinition(); var methodInfo = genericDefinition.GetMethods().Single(isCorrectMethod); return TypeBuilder.GetMethod(type, methodInfo); } return type.GetMethods().Single(isCorrectMethod); }