public static CreateInstance ( IServiceProvider provider, |
||
provider | IServiceProvider | |
objectType | ||
argTypes | ||
args | object | |
Résultat | object |
/// <summary>Creates an instance of the specified type.</summary> /// <returns>A new instance of the type.</returns> /// <param name="type">A <see cref="T:System.Type" /> that represents the type to create. </param> protected object CreateInstance(Type type) { if (type == null || this.PropertyType == null) { return(null); } Type[] array = new Type[] { typeof(Type) }; ConstructorInfo constructor = type.GetConstructor(array); object result; if (constructor != null) { object[] args = new object[] { this.PropertyType }; result = TypeDescriptor.CreateInstance(null, type, array, args); } else { result = TypeDescriptor.CreateInstance(null, type, null, null); } return(result); }
protected object CreateInstance(Type type) { Type[] types = new Type[] { typeof(Type) }; if (type.GetConstructor(types) != null) { return(TypeDescriptor.CreateInstance(null, type, types, new object[] { this.PropertyType })); } return(TypeDescriptor.CreateInstance(null, type, null, null)); }
/// <summary> /// Creates an instance of the specified type. /// </summary> protected object CreateInstance(Type type) { Type[] typeArgs = new Type[] { typeof(Type) }; ConstructorInfo ctor = type.GetConstructor(typeArgs); if (ctor != null) { return TypeDescriptor.CreateInstance(null, type, typeArgs, new object[] { PropertyType }); } return TypeDescriptor.CreateInstance(null, type, null, null); }
/// <summary> /// Creates an instance of the specified type. /// </summary> protected object?CreateInstance( [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type type) { Type[] typeArgs = new Type[] { typeof(Type) }; ConstructorInfo?ctor = type.GetConstructor(typeArgs); if (ctor != null) { return(TypeDescriptor.CreateInstance(null, type, typeArgs, new object[] { PropertyType })); } return(TypeDescriptor.CreateInstance(null, type, null, null)); }
protected object CreateInstance(Type type) { if (type == null || PropertyType == null) { return(null); } object instance = null; Type[] paramTypes = new Type[] { typeof(Type) }; ConstructorInfo ctor = type.GetConstructor(paramTypes); if (ctor != null) { object[] parameters = new object[] { PropertyType }; instance = TypeDescriptor.CreateInstance(null, type, paramTypes, parameters); } else { instance = TypeDescriptor.CreateInstance(null, type, null, null); } return(instance); }
/// <summary>Creates an instance of the specified type.</summary> /// <returns>A new instance of the type.</returns> /// <param name="type">A <see cref="T:System.Type" /> that represents the type to create. </param> protected object CreateInstance(Type type) { if (type == null || PropertyType == null) { return(null); } object obj = null; Type[] array = new Type[1] { typeof(Type) }; ConstructorInfo constructor = type.GetConstructor(array); if (constructor != null) { object[] args = new object[1] { PropertyType }; return(TypeDescriptor.CreateInstance(null, type, array, args)); } return(TypeDescriptor.CreateInstance(null, type, null, null)); }