public static object CreateFromName(string name, params object[] args) { object obj4; if (name == null) { throw new ArgumentNullException("name"); } Type valueOrDefault = null; InitializeConfigInfo(); lock (InternalSyncObject) { valueOrDefault = appNameHT.GetValueOrDefault(name); } if (valueOrDefault == null) { string typeName = machineNameHT.GetValueOrDefault(name); if (typeName != null) { valueOrDefault = Type.GetType(typeName, false, false); if ((valueOrDefault != null) && !valueOrDefault.IsVisible) { valueOrDefault = null; } } } if (valueOrDefault == null) { object obj3 = DefaultNameHT.GetValueOrDefault(name); if (obj3 != null) { if (obj3 is Type) { valueOrDefault = (Type)obj3; } else if (obj3 is string) { valueOrDefault = Type.GetType((string)obj3, false, false); if ((valueOrDefault != null) && !valueOrDefault.IsVisible) { valueOrDefault = null; } } } } if (valueOrDefault == null) { valueOrDefault = Type.GetType(name, false, false); if ((valueOrDefault != null) && !valueOrDefault.IsVisible) { valueOrDefault = null; } } if (valueOrDefault == null) { return(null); } RuntimeType type2 = valueOrDefault as RuntimeType; if (type2 == null) { return(null); } if (args == null) { args = new object[0]; } MethodBase[] constructors = type2.GetConstructors(BindingFlags.CreateInstance | BindingFlags.Public | BindingFlags.Instance); if (constructors == null) { return(null); } List <MethodBase> list = new List <MethodBase>(); for (int i = 0; i < constructors.Length; i++) { MethodBase item = constructors[i]; if (item.GetParameters().Length == args.Length) { list.Add(item); } } if (list.Count == 0) { return(null); } constructors = list.ToArray(); RuntimeConstructorInfo info = Type.DefaultBinder.BindToMethod(BindingFlags.CreateInstance | BindingFlags.Public | BindingFlags.Instance, constructors, ref args, null, null, null, out obj4) as RuntimeConstructorInfo; if ((info == null) || typeof(Delegate).IsAssignableFrom(info.DeclaringType)) { return(null); } object obj2 = info.Invoke(BindingFlags.CreateInstance | BindingFlags.Public | BindingFlags.Instance, Type.DefaultBinder, args, null); if (obj4 != null) { Type.DefaultBinder.ReorderArgumentArray(ref args, obj4); } return(obj2); }
public override ConstructorInfo[] GetConstructors(BindingFlags bindingAttr) { return(RewriteConstructors(RuntimeType.GetConstructors(bindingAttr))); }
public static object CreateFromName(string name, params object[] args) { if (name == null) throw new ArgumentNullException("name"); Type type = (Type) null; CryptoConfig.InitializeConfigInfo(); lock (CryptoConfig.InternalSyncObject) type = CryptoConfig.appNameHT.GetValueOrDefault(name); if (type == (Type) null) { string valueOrDefault = CryptoConfig.machineNameHT.GetValueOrDefault(name); if (valueOrDefault != null) { type = Type.GetType(valueOrDefault, false, false); if (type != (Type) null && !type.IsVisible) type = (Type) null; } } if (type == (Type) null) { object valueOrDefault = CryptoConfig.DefaultNameHT.GetValueOrDefault(name); if (valueOrDefault != null) { if (valueOrDefault is Type) type = (Type) valueOrDefault; else if (valueOrDefault is string) { type = Type.GetType((string) valueOrDefault, false, false); if (type != (Type) null && !type.IsVisible) type = (Type) null; } } } if (type == (Type) null) { type = Type.GetType(name, false, false); if (type != (Type) null && !type.IsVisible) type = (Type) null; } if (type == (Type) null) return (object) null; RuntimeType runtimeType = type as RuntimeType; if (runtimeType == (RuntimeType) null) return (object) null; if (args == null) args = new object[0]; MethodBase[] methodBaseArray = (MethodBase[]) runtimeType.GetConstructors(BindingFlags.Instance | BindingFlags.Public | BindingFlags.CreateInstance); if (methodBaseArray == null) return (object) null; List<MethodBase> methodBaseList = new List<MethodBase>(); for (int index = 0; index < methodBaseArray.Length; ++index) { MethodBase methodBase = methodBaseArray[index]; if (methodBase.GetParameters().Length == args.Length) methodBaseList.Add(methodBase); } if (methodBaseList.Count == 0) return (object) null; object state; RuntimeConstructorInfo runtimeConstructorInfo = Type.DefaultBinder.BindToMethod(BindingFlags.Instance | BindingFlags.Public | BindingFlags.CreateInstance, methodBaseList.ToArray(), ref args, (ParameterModifier[]) null, (CultureInfo) null, (string[]) null, out state) as RuntimeConstructorInfo; if ((ConstructorInfo) runtimeConstructorInfo == (ConstructorInfo) null || typeof (Delegate).IsAssignableFrom(runtimeConstructorInfo.DeclaringType)) return (object) null; object obj = runtimeConstructorInfo.Invoke(BindingFlags.Instance | BindingFlags.Public | BindingFlags.CreateInstance, Type.DefaultBinder, args, (CultureInfo) null); if (state == null) return obj; Type.DefaultBinder.ReorderArgumentArray(ref args, state); return obj; }