TypeConverter.CreateInstance Method

Definition

在给定 Object 的一组属性值的情况下重新创建该对象。Re-creates an Object given a set of property values for the object.

Overloads

CreateInstance(ITypeDescriptorContext, IDictionary)

给定该对象的一组属性值,使用指定上下文创建与此 TypeConverter 相关联的类型的实例。Creates an instance of the type that this TypeConverter is associated with, using the specified context, given a set of property values for the object.

CreateInstance(IDictionary)

在给定 Object 的一组属性值的情况下重新创建该对象。Re-creates an Object given a set of property values for the object.

CreateInstance(ITypeDescriptorContext, IDictionary)

给定该对象的一组属性值,使用指定上下文创建与此 TypeConverter 相关联的类型的实例。Creates an instance of the type that this TypeConverter is associated with, using the specified context, given a set of property values for the object.

public:
 virtual System::Object ^ CreateInstance(System::ComponentModel::ITypeDescriptorContext ^ context, System::Collections::IDictionary ^ propertyValues);
public virtual object CreateInstance (System.ComponentModel.ITypeDescriptorContext context, System.Collections.IDictionary propertyValues);
abstract member CreateInstance : System.ComponentModel.ITypeDescriptorContext * System.Collections.IDictionary -> obj
override this.CreateInstance : System.ComponentModel.ITypeDescriptorContext * System.Collections.IDictionary -> obj
Public Overridable Function CreateInstance (context As ITypeDescriptorContext, propertyValues As IDictionary) As Object

Parameters

context
ITypeDescriptorContext

一个 ITypeDescriptorContext,用于提供格式上下文。An ITypeDescriptorContext that provides a format context.

propertyValues
IDictionary

新属性值的 IDictionaryAn IDictionary of new property values.

Returns

Object

如果表示给定 IDictionary,则为 Object,或如果无法创建对象,则为 nullAn Object representing the given IDictionary, or null if the object cannot be created. 此方法始终返回 nullThis method always returns null.

Remarks

此方法可用于不可变的对象,但要为其提供可变属性的对象。Use this method for objects that are immutable, but for which you want to provide changeable properties.

Notes to Inheritors

如果要转换的类型必须重新创建要更改其值的对象,请重写此方法。Override this method if the type you want to convert must re-create the object to change its value.

使用 context 参数提取有关调用此转换器的环境的附加信息。Use the context parameter to extract additional information about the environment from which this converter is invoked. 此参数可以 null,因此请始终选中此参数。This parameter can be null, so always check it. 同样,上下文对象的属性可以返回 nullAlso, properties on the context object can return null.

propertyValues 参数提供的字典包含一系列名称/值对,其中每个属性都是从 GetProperties(Object)返回的每个属性。The dictionary provided by the propertyValues parameter has a series of name/value pairs, one for each property returned from GetProperties(Object).

See also

CreateInstance(IDictionary)

在给定 Object 的一组属性值的情况下重新创建该对象。Re-creates an Object given a set of property values for the object.

public:
 System::Object ^ CreateInstance(System::Collections::IDictionary ^ propertyValues);
public object CreateInstance (System.Collections.IDictionary propertyValues);
member this.CreateInstance : System.Collections.IDictionary -> obj
Public Function CreateInstance (propertyValues As IDictionary) As Object

Parameters

propertyValues
IDictionary

一个 IDictionary,表示新属性值的字典。An IDictionary that represents a dictionary of new property values.

Returns

Object

如果表示给定 IDictionary,则为 Object,或如果无法创建对象,则为 nullAn Object representing the given IDictionary, or null if the object cannot be created. 此方法始终返回 nullThis method always returns null.

Remarks

此方法可用于不可变的对象,但要为其提供可变属性的对象。Use this method for objects that are immutable, but for which you want to provide changeable properties.

propertyValues 参数提供的字典包含一系列名称/值对,其中每个属性都是从 GetProperties返回的每个属性。The dictionary provided by the propertyValues parameter has a series of name/value pairs, one for each property returned from GetProperties.

See also

Applies to