void DeserializeCollection <T>(ref T deserializedObject, string propName, string propValue) { propValue = propValue.Remove(0, 1); propValue = propValue.Remove(propValue.Length - 1, 1); PropertyInfo propInfo = deserializedObject.GetType().GetProperty(propName); var property = TypeDescriptor.CreateInstance(null, propInfo.PropertyType, null, null); var type = property.GetType(); bool isPrimitiveType = (property.GetType().GetGenericArguments().Length != 0) ? property.GetType().GetGenericArguments().Single().IsPrimitive : property.GetType().GetElementType().IsPrimitive; bool isStringType = (property.GetType().GetGenericArguments().Length != 0) ? property.GetType().GetGenericArguments().Single().Equals(typeof(string)) : property.GetType().GetElementType().Equals(typeof(string)); if (!isPrimitiveType && !isStringType) { } else { List <string> splitCollectionSingleProps = propValue.Split(',').ToList(); } //List<string> splitCollectionCollectionProps; //while (propName.Contains('[')) //{ //} }
/// <summary> /// This method is called to create an instance of the given type. If the type is a component /// this will search for a constructor of type IContainer first, and then an empty constructor. /// </summary> protected internal virtual object CreateInstance(Type type) { ArgumentNullException.ThrowIfNull(type); // Locate an appropriate constructor for IComponents. object instance = null; ConstructorInfo ctor = TypeDescriptor.GetReflectionType(type).GetConstructor(Array.Empty <Type>()); if (ctor is not null) { instance = TypeDescriptor.CreateInstance(this, type, Array.Empty <Type>(), Array.Empty <object>()); } else { if (typeof(IComponent).IsAssignableFrom(type)) { ctor = TypeDescriptor.GetReflectionType(type).GetConstructor(BindingFlags.Public | BindingFlags.Instance | BindingFlags.ExactBinding, null, new Type[] { typeof(IContainer) }, null); } if (ctor is not null) { instance = TypeDescriptor.CreateInstance(this, type, new Type[] { typeof(IContainer) }, new object[] { ComponentContainer }); } } if (instance is null) { instance = Activator.CreateInstance(type, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.CreateInstance, null, null, null); } return(instance); }
public void Should_Randomize_Order(Type shufflerType) { // A decent test injection framework like AutoMoq would do this much better, but we'll // just hack it in here to avoid pulling in another library. var shuffler = (IShuffler)TypeDescriptor.CreateInstance(null, shufflerType, null, null); var shuffledDeck = shuffler.Shuffle(Deck); var shuffledDeckEnumerator = shuffledDeck.GetEnumerator(); // It's tough to prove that a sequence is random, so we'll just // prove that it's not sorted anymore. foreach (var suit in Suit.All) { foreach (var rank in Rank.All) { shuffledDeckEnumerator.MoveNext(); // Exit the test on the first card we find that's out of order if (suit != shuffledDeckEnumerator.Current.Suit || rank != shuffledDeckEnumerator.Current.Rank) { return; } } } throw new Xunit.Sdk.XunitException("Sequence is not randomized"); }
protected internal virtual object CreateInstance(Type type) { if (type == null) { throw new ArgumentNullException("type"); } ConstructorInfo constructor = null; object obj2 = null; constructor = TypeDescriptor.GetReflectionType(type).GetConstructor(new Type[0]); if (constructor != null) { obj2 = TypeDescriptor.CreateInstance(this, type, new Type[0], new object[0]); } else { if (typeof(IComponent).IsAssignableFrom(type)) { constructor = TypeDescriptor.GetReflectionType(type).GetConstructor(BindingFlags.ExactBinding | BindingFlags.Public | BindingFlags.Instance, null, new Type[] { typeof(IContainer) }, null); } if (constructor != null) { obj2 = TypeDescriptor.CreateInstance(this, type, new Type[] { typeof(IContainer) }, new object[] { this.ComponentContainer }); } } if (obj2 == null) { obj2 = Activator.CreateInstance(type, BindingFlags.CreateInstance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, null, null); } return(obj2); }
/// <summary> /// This method is called to create an instance of the given type. If the type is a component /// this will search for a constructor of type IContainer first, and then an empty constructor. /// </summary> protected internal virtual object CreateInstance(Type type) { if (type == null) { throw new ArgumentNullException(nameof(type)); } // Locate an appropriate constructor for IComponents. object instance = null; ConstructorInfo ctor = TypeDescriptor.GetReflectionType(type).GetConstructor(new Type[0]); if (ctor != null) { instance = TypeDescriptor.CreateInstance(this, type, new Type[0], new object[0]); } else { if (typeof(IComponent).IsAssignableFrom(type)) { ctor = TypeDescriptor.GetReflectionType(type).GetConstructor(BindingFlags.Public | BindingFlags.Instance | BindingFlags.ExactBinding, null, new Type[] { typeof(IContainer) }, null); } if (ctor != null) { instance = TypeDescriptor.CreateInstance(this, type, new Type[] { typeof(IContainer) }, new object[] { ComponentContainer }); } } if (instance == null) { instance = Activator.CreateInstance(type, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.CreateInstance, null, null, null); } return(instance); }
/// <summary> /// The implementation of VsShell.ISelectionContainer.GetObjects in /// ModelingWindowPane calls either GetSelectedObjects() or GetAllObjects() /// - base calls to ModelingWindowPane /// </summary> /// <returns></returns> protected override void GetSelectedObjects(uint count, object[] objects) { // call the base class version first; objects will be populated with a // collection of DSL ModelElements base.GetSelectedObjects(count, objects); if (IsArtifactDesignerSafe() == false) { if (EdmUtils.ShouldShowByRefDebugHelpers()) { if (Context != null) { var artifact = EditingContextManager.GetArtifact(Context) as EntityDesignArtifact; if (artifact != null) { // Show at least the EFEntityModelDescriptor so we can see the by-reference property extensions // for the hydrated model var descriptor = (ObjectDescriptor)TypeDescriptor.CreateInstance(null, typeof(EFEntityModelDescriptor), null, null); descriptor.Initialize(artifact.ConceptualModel, Context, true); objects[0] = descriptor; } } } else { for (var i = 0; i < objects.Length; i++) { objects[i] = null; } } } // only show properties for single selection else { // now change this into an array of our item descriptors. var selectedModelObjects = ConvertDslModelElementArrayToItemDescriptors(objects, false); // if there are more than 1 selected object, convert the item descriptors to linked-item-descriptors. // This is so that property update can be done in 1 transaction. if (selectedModelObjects.Count > 1) { var tempSelectedModelObjects = new ArrayList(); var contextItem = new LinkedDescriptorContextItem(); foreach (var customTypeDescriptor in selectedModelObjects.ToArray().OfType <ICustomTypeDescriptor>()) { tempSelectedModelObjects.Add(new LinkedPropertyTypeDescriptor(customTypeDescriptor, contextItem)); } selectedModelObjects = tempSelectedModelObjects; } // if the lengths are not the same, then there are items (like compartments) // that are being selected, so don't change the object array if (objects.Length == selectedModelObjects.Count) { selectedModelObjects.CopyTo(objects, 0); } } }
public override object CreateInstance(object[] arguments) { if (this.Type != null) { return(TypeDescriptor.CreateInstance(null, this.Type, null, arguments)); } return(base.CreateInstance(arguments)); }
public void CreateInstancePassesCtorParameters() { var expectedString = "expected string"; var component = TypeDescriptor.CreateInstance(null, typeof(DescriptorTestComponent), new[] { expectedString.GetType() }, new[] { expectedString }); Assert.NotNull(component); Assert.IsType(typeof(DescriptorTestComponent), component); Assert.Equal(expectedString, (component as DescriptorTestComponent).StringProperty); }
public static ResourceReaderBase CreateReader(String resourceID, PsdReader reader, Int64 length) { Type readerType = typeof(EmptyResourceReader); if (readers.ContainsKey(resourceID) == true) { readerType = readers[resourceID]; } return(TypeDescriptor.CreateInstance(null, readerType, new Type[] { typeof(PsdReader), typeof(Int64), }, new Object[] { reader, length, }) as ResourceReaderBase); }
public void Should_Have_Distinct_Cards(Type shufflerType) { var shuffler = (IShuffler)TypeDescriptor.CreateInstance(null, shufflerType, null, null); var shuffledDeck = shuffler.Shuffle(Deck); var originalCardCount = Deck.Count(); var distinctShuffledCardCount = shuffledDeck .Distinct() .Count(); Assert.Equal(originalCardCount, distinctShuffledCardCount); }
public object CreateInstance(Type type, Type protype) { Type[] typeArray = { typeof(Type) }; if (!(type.GetConstructor(typeArray) != null)) { return(TypeDescriptor.CreateInstance(null, type, null, null)); } return(TypeDescriptor.CreateInstance(null, type, typeArray, new object[] { protype })); }
public static IValidator CreateFor(Type type) { Type vType; if (_defaultValidators.TryGetValue(type, out vType)) { return((IValidator)TypeDescriptor.CreateInstance( null, vType, null, null )); } return(new DefaultValidator(type)); }
private static object ParseArray(CommandMemberDescriptor descriptor, string arg) { System.Collections.IList list; if (descriptor.MemberType.IsArray == true) { list = new System.Collections.ArrayList() as System.Collections.IList; } else { list = TypeDescriptor.CreateInstance(null, descriptor.MemberType, null, null) as System.Collections.IList; } var itemType = GetItemType(descriptor.MemberType); if (itemType == null) { throw new NotSupportedException(); } var segments = arg.Split(new char[] { CommandSettings.ItemSperator }); try { var converter = TypeDescriptor.GetConverter(itemType); foreach (var item in segments) { var s = item.Trim(); if (s.Length == 0) { continue; } var element = converter.ConvertFromString(s); list.Add(element); } if (descriptor.MemberType.IsArray == true) { var array = Array.CreateInstance(itemType, list.Count); list.CopyTo(array, 0); list = array as System.Collections.IList; } else { } } catch (Exception e) { throw new ArgumentException(Resources.Exception_InvalidArgumentType, descriptor.Name, e); } return(list); }
private object LocateForView(object view) { object viewModel = this.locateForView(view); if (viewModel != null) return viewModel; if (TypeDescriptor.GetAttributes(view)[typeof(ModelAttribute)] is ModelAttribute attr) { if (attr.ModelType.IsInterface == true) return this.GetInstance(attr.ModelType, null); return TypeDescriptor.CreateInstance(null, attr.ModelType, null, null); } return viewModel; }
// protected override IComponent[] CreateComponentsCore(IDesignerHost host) { Type typeOfComponent = GetType(host, AssemblyName, TypeName, true); if (typeOfComponent == null && host != null) { typeOfComponent = host.GetType(TypeName); } if (typeOfComponent == null) { ITypeProviderCreator tpc = null; if (host != null) { tpc = (ITypeProviderCreator)host.GetService(typeof(ITypeProviderCreator)); } if (tpc != null) { System.Reflection.Assembly assembly = tpc.GetTransientAssembly(this.AssemblyName); if (assembly != null) { typeOfComponent = assembly.GetType(this.TypeName); } } if (typeOfComponent == null) { typeOfComponent = GetType(host, AssemblyName, TypeName, true); } } ArrayList comps = new ArrayList(); if (typeOfComponent != null) { if (typeof(IComponent).IsAssignableFrom(typeOfComponent)) { comps.Add(TypeDescriptor.CreateInstance(null, typeOfComponent, null, null)); } } IComponent[] temp = new IComponent[comps.Count]; comps.CopyTo(temp, 0); return(temp); }
public static IResourceBlock CreateReader(string resourceID, PsdReader reader, long length) { IResourceBlock resourceBlock; Type readerType = typeof(EmptyResource); if (readers.ContainsKey(resourceID) == true) { readerType = readers[resourceID]; resourceBlock = TypeDescriptor.CreateInstance(null, readerType, new Type[] { typeof(PsdReader), typeof(long), }, new object[] { reader, length, }) as IResourceBlock; } else { var empty = new EmptyResource(reader, length); empty.Id = resourceID; resourceBlock = empty; } return(resourceBlock); }
protected virtual object CreateInstance(Type itemType) { object instance = null; if (typeof(IComponent).IsAssignableFrom(itemType)) { IDesignerHost host = GetService(typeof(IDesignerHost)) as IDesignerHost; if (host != null) { instance = host.CreateComponent(itemType); } } if (instance == null) { instance = TypeDescriptor.CreateInstance(provider, itemType, null, null); } return(instance); }
private void method_0(object object_0) { try { if (this.iapplication_0.CurrentTool != null) { ICommand command = TypeDescriptor.CreateInstance(null, this.iapplication_0.CurrentTool.GetType(), null, null) as ICommand; command.OnCreate(this.axSceneControl1.Object); (this.axSceneControl1.Object as ISceneControlDefault).CurrentTool = (command as ITool); } else { (this.axSceneControl1.Object as ISceneControlDefault).CurrentTool = null; } } catch { } }
public static object ParseArray(Type propertyType, IEnumerable <string> args) { System.Collections.IList list; if (propertyType.IsArray == true) { list = new System.Collections.ArrayList() as System.Collections.IList; } else { list = TypeDescriptor.CreateInstance(null, propertyType, null, null) as System.Collections.IList; } var itemType = GetItemType(propertyType); if (itemType == null) { throw new NotSupportedException(); } var converter = TypeDescriptor.GetConverter(itemType); foreach (var item in args) { var s = item.Trim(); if (s.Length == 0) { continue; } var element = converter.ConvertFromString(s); list.Add(element); } if (propertyType.IsArray == true) { var array = Array.CreateInstance(itemType, list.Count); list.CopyTo(array, 0); list = array as System.Collections.IList; } else { } return(list); }
public static PropertyEditorBase GetEditor(Type propertyType) { Type editorType; for (Type t = propertyType; t != typeof(Object); t = t.BaseType) { if (_map.TryGetValue(t, out editorType)) { Object o = TypeDescriptor.CreateInstance(null, editorType, null, null); return((PropertyEditorBase)o); } } ValidatingStringEditor defaultEditor = new ValidatingStringEditor(); defaultEditor.Validator = Platinum.Validators.DefaultValidator.CreateFor(propertyType); return(defaultEditor); }
protected virtual IComponent[] CreateComponentsCore(IDesignerHost host) { ArrayList list = new ArrayList(); Type componentClass = this.GetType(host, this.AssemblyName, this.TypeName, true); if (componentClass != null) { if (host != null) { list.Add(host.CreateComponent(componentClass)); } else if (typeof(IComponent).IsAssignableFrom(componentClass)) { list.Add(TypeDescriptor.CreateInstance(null, componentClass, null, null)); } } IComponent[] array = new IComponent[list.Count]; list.CopyTo(array, 0); return(array); }
private void frmSecondaryViewer_Load(object sender, EventArgs e) { this.axSceneControl1.SceneViewer.Caption = this.Text; if (this.iscene_0 != null) { for (int i = this.iscene_0.LayerCount - 1; i >= 0; i--) { this.axSceneControl1.Scene.AddLayer(this.iscene_0.get_Layer(i), false); } if (this.itool_0 != null) { ICommand command = TypeDescriptor.CreateInstance(null, this.itool_0.GetType(), null, null) as ICommand; command.OnCreate(this.axSceneControl1.Object); (this.axSceneControl1.Object as ISceneControlDefault).CurrentTool = (command as ITool); } else { (this.axSceneControl1.Object as ISceneControlDefault).CurrentTool = null; } } }
/// <include file='doc\ToolboxItem.uex' path='docs/doc[@for="ToolboxItem.CreateComponentsCore"]/*' /> /// <devdoc> /// Creates objects from the type contained in this toolbox item. If designerHost is non-null /// this will also add them to the designer. /// </devdoc> protected virtual IComponent[] CreateComponentsCore(IDesignerHost host) { ArrayList comps = new ArrayList(); Type createType = GetType(host, AssemblyName, TypeName, true); if (createType != null) { if (host != null) { comps.Add(host.CreateComponent(createType)); } else if (typeof(IComponent).IsAssignableFrom(createType)) { comps.Add(TypeDescriptor.CreateInstance(null, createType, null, null)); } } IComponent[] temp = new IComponent[comps.Count]; comps.CopyTo(temp, 0); return(temp); }
protected override IComponent[] CreateComponentsCore(IDesignerHost host) { Type c = this.GetType(host, base.AssemblyName, base.TypeName, true); if ((c == null) && (host != null)) { c = host.GetType(base.TypeName); } if (c == null) { ITypeProviderCreator service = null; if (host != null) { service = (ITypeProviderCreator)host.GetService(typeof(ITypeProviderCreator)); } if (service != null) { Assembly transientAssembly = service.GetTransientAssembly(base.AssemblyName); if (transientAssembly != null) { c = transientAssembly.GetType(base.TypeName); } } if (c == null) { c = this.GetType(host, base.AssemblyName, base.TypeName, true); } } ArrayList list = new ArrayList(); if ((c != null) && typeof(IComponent).IsAssignableFrom(c)) { list.Add(TypeDescriptor.CreateInstance(null, c, null, null)); } IComponent[] array = new IComponent[list.Count]; list.CopyTo(array, 0); return(array); }
static public ObjectPoolSettingItem GetDefaultSetting(Type type) { ObjectPoolSettingItem setting; var mi = type.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static).SingleOrDefault(c => typeof(ObjectPoolSettingItem) == c.ReturnType && null != Attribute.GetCustomAttribute(c, typeof(OnPoolRegisterAttribute))); if (null != mi) { setting = (ObjectPoolSettingItem)mi.Invoke(null, Array.Empty <object>()); } else { setting = new ObjectPoolSettingItem() { PoolType = type, Creator = () => TypeDescriptor.CreateInstance(null, type, null, null), }; mi = type.GetMethods(BindingFlags.Public | BindingFlags.NonPublic).SingleOrDefault(c => typeof(bool) == c.ReturnType && null != Attribute.GetCustomAttribute(c, typeof(OnPoolEnteringAttribute))); if (null != mi) { setting.EnterPool = c => (bool)mi.Invoke(c, Array.Empty <object>()); } } return(setting); }
protected virtual IUsageDescriptionProvider CreateInstance(Type type) { return(TypeDescriptor.CreateInstance(null, this.ProviderType, null, null) as IUsageDescriptionProvider); }
protected virtual Task <T> CreateServiceAsync(IPeer peer, U callback) { return(Task.Run(() => TypeDescriptor.CreateInstance(null, this.ServiceType, null, null) as T)); }
protected virtual object CreateInstance(Type type, ICollection arguments, string name, bool addToContainer) { object[] array = null; if ((arguments != null) && (arguments.Count > 0)) { array = new object[arguments.Count]; arguments.CopyTo(array, 0); } object obj2 = null; if (this.RecycleInstances && (name != null)) { if (this.instancesByName != null) { obj2 = this.instancesByName[name]; } if (((obj2 == null) && addToContainer) && (this.Container != null)) { obj2 = this.Container.Components[name]; } if (((obj2 != null) && this.ValidateRecycledTypes) && (obj2.GetType() != type)) { obj2 = null; } } if ((((obj2 == null) && addToContainer) && typeof(IComponent).IsAssignableFrom(type)) && (((array == null) || (array.Length == 0)) || ((array.Length == 1) && (array[0] == this.Container)))) { IDesignerHost service = this.GetService(typeof(IDesignerHost)) as IDesignerHost; if ((service != null) && (service.Container == this.Container)) { bool flag = false; if ((!this.PreserveNames && (name != null)) && (this.Container.Components[name] != null)) { flag = true; } if ((name == null) || flag) { obj2 = service.CreateComponent(type); } else { obj2 = service.CreateComponent(type, name); } } } if (obj2 == null) { try { try { obj2 = TypeDescriptor.CreateInstance(this.provider, type, null, array); } catch (MissingMethodException exception) { Type[] typeArray = new Type[array.Length]; for (int i = 0; i < array.Length; i++) { if (array[i] != null) { typeArray[i] = array[i].GetType(); } } object[] args = new object[array.Length]; foreach (ConstructorInfo info in TypeDescriptor.GetReflectionType(type).GetConstructors(BindingFlags.CreateInstance | BindingFlags.Public | BindingFlags.Instance)) { ParameterInfo[] parameters = info.GetParameters(); if ((parameters != null) && (parameters.Length == typeArray.Length)) { bool flag2 = true; for (int j = 0; j < typeArray.Length; j++) { if ((typeArray[j] == null) || parameters[j].ParameterType.IsAssignableFrom(typeArray[j])) { args[j] = array[j]; } else { if (array[j] is IConvertible) { try { args[j] = ((IConvertible)array[j]).ToType(parameters[j].ParameterType, null); goto Label_0217; } catch (InvalidCastException) { } } flag2 = false; break; Label_0217 :; } } if (flag2) { obj2 = TypeDescriptor.CreateInstance(this.provider, type, null, args); break; } } } if (obj2 == null) { throw exception; } } } catch (MissingMethodException) { StringBuilder builder = new StringBuilder(); foreach (object obj3 in array) { if (builder.Length > 0) { builder.Append(", "); } if (obj3 != null) { builder.Append(obj3.GetType().Name); } else { builder.Append("null"); } } Exception exception2 = new SerializationException(System.Design.SR.GetString("SerializationManagerNoMatchingCtor", new object[] { type.FullName, builder.ToString() })) { HelpLink = "SerializationManagerNoMatchingCtor" }; throw exception2; } if ((!addToContainer || !(obj2 is IComponent)) || (this.Container == null)) { return(obj2); } bool flag3 = false; if ((!this.PreserveNames && (name != null)) && (this.Container.Components[name] != null)) { flag3 = true; } if ((name == null) || flag3) { this.Container.Add((IComponent)obj2); return(obj2); } this.Container.Add((IComponent)obj2, name); } return(obj2); }
// <summary> // Returns a wrapper for the specified EFObject. The wrapper is the type descriptor // that describes the properties that should be displayed for the EFObject. // The returned wrapper should be handed to a property window control // </summary> public static ObjectDescriptor GetObjectDescriptor(EFObject obj, EditingContext editingContext, bool runningInVS) { if (obj != null) { Type objectDescriptorType; if (ObjectDescriptorTypes.TryGetValue(obj.GetType(), out objectDescriptorType)) { // create the descriptor wrapper for the EFObject object var descriptor = (ObjectDescriptor)TypeDescriptor.CreateInstance(null, objectDescriptorType, null, null); descriptor.Initialize(obj, editingContext, runningInVS); return(descriptor); } else { // special case for Property var property = obj as Property; if (property != null) { ObjectDescriptor descriptor = null; if (property is ComplexConceptualProperty) { descriptor = (ObjectDescriptor)TypeDescriptor.CreateInstance(null, typeof(EFComplexPropertyDescriptor), null, null); } else if (property.EntityModel.IsCSDL) { descriptor = (ObjectDescriptor)TypeDescriptor.CreateInstance(null, typeof(EFPropertyDescriptor), null, null); } else { descriptor = (ObjectDescriptor)TypeDescriptor.CreateInstance(null, typeof(EFSPropertyDescriptor), null, null); } descriptor.Initialize(obj, editingContext, runningInVS); return(descriptor); } // special case for Parameter var parameter = obj as Parameter; if (parameter != null) { ObjectDescriptor descriptor = null; if (parameter.Parent is FunctionImport) { descriptor = (ObjectDescriptor)TypeDescriptor.CreateInstance(null, typeof(EFParameterDescriptor), null, null); descriptor.Initialize(obj, editingContext, runningInVS); return(descriptor); } else if (parameter.Parent is Function) { //Stored procedure parameter descriptor (EFSParameterDescriptor) descriptor = (ObjectDescriptor)TypeDescriptor.CreateInstance(null, typeof(EFSParameterDescriptor), null, null); descriptor.Initialize(obj, editingContext, runningInVS); return(descriptor); } } } } return(null); }
/// <summary>Creates an instance of a type.</summary> /// <returns>A new instance of the type specified by <paramref name="type" />.</returns> /// <param name="type">The type to create an instance of.</param> /// <param name="arguments">The parameters of the type’s constructor. This can be null or an empty collection to invoke the default constructor.</param> /// <param name="name">A name to give the object. If null, the object will not be given a name, unless the object is added to a container and the container gives the object a name.</param> /// <param name="addToContainer">true to add the object to the container if the object implements <see cref="T:System.ComponentModel.IComponent" />; otherwise, false.</param> /// <exception cref="T:System.Runtime.Serialization.SerializationException"> /// <paramref name="type" /> does not have a constructor that takes parameters contained in <paramref name="arguments" />.</exception> protected virtual object CreateInstance(Type type, ICollection arguments, string name, bool addToContainer) { object[] array = null; if (arguments != null && arguments.Count > 0) { array = new object[arguments.Count]; arguments.CopyTo(array, 0); } object obj = null; if (this.RecycleInstances && name != null) { if (this.instancesByName != null) { obj = this.instancesByName[name]; } if ((obj == null & addToContainer) && this.Container != null) { obj = this.Container.Components[name]; } if (obj != null && this.ValidateRecycledTypes && obj.GetType() != type) { obj = null; } } if ((obj == null & addToContainer) && typeof(IComponent).IsAssignableFrom(type) && (array == null || array.Length == 0 || (array.Length == 1 && array[0] == this.Container))) { if (this.GetService(typeof(IDesignerHost)) is IDesignerHost designerHost && designerHost.Container == this.Container) { bool flag = false; if (!this.PreserveNames && name != null && this.Container.Components[name] != null) { flag = true; } if (name == null | flag) { obj = designerHost.CreateComponent(type); } else { obj = designerHost.CreateComponent(type, name); } } } if (obj == null) { try { try { obj = TypeDescriptor.CreateInstance(this.provider, type, null, array); } catch (MissingMethodException ex) { Type[] array2 = new Type[array.Length]; for (int i = 0; i < array.Length; i++) { if (array[i] != null) { array2[i] = array[i].GetType(); } } object[] array3 = new object[array.Length]; ConstructorInfo[] constructors = TypeDescriptor.GetReflectionType(type).GetConstructors(BindingFlags.Instance | BindingFlags.Public | BindingFlags.CreateInstance); for (int j = 0; j < constructors.Length; j++) { ConstructorInfo constructorInfo = constructors[j]; ParameterInfo[] parameters = constructorInfo.GetParameters(); if (parameters != null && parameters.Length == array2.Length) { bool flag2 = true; for (int k = 0; k < array2.Length; k++) { if (!(array2[k] == null) && !parameters[k].ParameterType.IsAssignableFrom(array2[k])) { if (array[k] is IConvertible) { try { array3[k] = ((IConvertible)array[k]).ToType(parameters[k].ParameterType, null); goto IL_219; } catch (InvalidCastException) { } } flag2 = false; break; } array3[k] = array[k]; IL_219 :; } if (flag2) { obj = TypeDescriptor.CreateInstance(this.provider, type, null, array3); break; } } } if (obj == null) { throw ex; } } } catch (MissingMethodException) { StringBuilder stringBuilder = new StringBuilder(); object[] array4 = array; for (int l = 0; l < array4.Length; l++) { object obj2 = array4[l]; if (stringBuilder.Length > 0) { stringBuilder.Append(", "); } if (obj2 != null) { stringBuilder.Append(obj2.GetType().Name); } else { stringBuilder.Append("null"); } } throw new SerializationException(SR.GetString("SerializationManagerNoMatchingCtor", new object[] { type.FullName, stringBuilder.ToString() })) { HelpLink = "SerializationManagerNoMatchingCtor" }; } if (addToContainer && obj is IComponent && this.Container != null) { bool flag3 = false; if (!this.PreserveNames && name != null && this.Container.Components[name] != null) { flag3 = true; } if (name == null | flag3) { this.Container.Add((IComponent)obj); } else { this.Container.Add((IComponent)obj, name); } } } return(obj); }