TypeConverter.CreateInstance 方法

定義

重新建立 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.

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

參數

context
ITypeDescriptorContext

提供格式內容的 ITypeDescriptorContextAn ITypeDescriptorContext that provides a format context.

propertyValues
IDictionary

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

傳回

代表指定 IDictionaryObject;如果無法建立物件,則為 nullAn Object representing the given IDictionary, or null if the object cannot be created. 這個方法一律會傳回 nullThis method always returns null.

備註

如果物件是不可變的, 但您想要提供可變更的屬性, 請使用這個方法。Use this method for objects that are immutable, but for which you want to provide changeable properties.

給繼承者的注意事項

如果您想要轉換的類型必須重新建立物件以變更其值, 請覆寫這個方法。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).

另請參閱

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

參數

propertyValues
IDictionary

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

傳回

代表指定 IDictionaryObject;如果無法建立物件,則為 nullAn Object representing the given IDictionary, or null if the object cannot be created. 這個方法一律會傳回 nullThis method always returns null.

備註

如果物件是不可變的, 但您想要提供可變更的屬性, 請使用這個方法。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.

另請參閱

適用於