In This Article

ExpandableCollectionConverter Class

Represents a type converter that is capable of expanding various collection types.

public class ExpandableCollectionConverter : TypeConverter, ICollectionTypeConverter
Inheritance:
object TypeConverter object
Implements:
ICollectionTypeConverter

Constructors

ExpandableCollectionConverter()

Initializes an instance of the class.

public ExpandableCollectionConverter()

ExpandableCollectionConverter(bool, bool)

Initializes an instance of the class.

public ExpandableCollectionConverter(bool isCollectionReadOnly, bool areItemsReadOnly)
Parameter Type Description
isCollectionReadOnly bool

Whether items can be added to or removed from the collection.

areItemsReadOnly bool

Whether the values of the items in the collection are read-only and cannot be changed.

Properties

AreItemsReadOnly

Indicates whether the values of the items in the collection are read-only and cannot be changed.

public bool AreItemsReadOnly { get; }

Property Value

bool:

true if the values of the items in the collection are read-only and cannot be changed; otherwise, false.

IsCollectionReadOnly

Indicates whether items can be added to or removed from the collection.

public bool IsCollectionReadOnly { get; }

Property Value

bool:

true if items can be added to or removed from the collection; otherwise, false.

MultipleItemsFormat

The format for text to return when there are multiple items.

public string MultipleItemsFormat { get; set; }

Property Value

string:

The default value is "{0} items".

NoItemsText

The text to return when there are no items.

public string NoItemsText { get; set; }

Property Value

string:

The default value is "No items".

OneItemText

The text to return when there is one item.

public string OneItemText { get; set; }

Property Value

string:

The default value is "1 item".

Methods

AddItem(IPropertyModel, object?)

Adds the specified item into to the collection.

public virtual bool AddItem(IPropertyModel propertyModel, object? item)
Parameter Type Description
propertyModel IPropertyModel

The IPropertyModel associated with the collection.

item object

The item that should be added.

Returns

bool:

true if the item was added to the collection; otherwise, false.

CanAddItem(IPropertyModel)

Returns whether a new item can be added to the collection.

public virtual bool CanAddItem(IPropertyModel propertyModel)
Parameter Type Description
propertyModel IPropertyModel

The IPropertyModel associated with the collection.

Returns

bool:

true if a new item can be added to the collection; otherwise, false.

CanConvertTo(ITypeDescriptorContext?, Type?)

Returns whether this converter can convert the object to the specified type, using the specified context.

public override bool CanConvertTo(ITypeDescriptorContext? context, Type? destinationType)
Parameter Type Description
context ITypeDescriptorContext

An ITypeDescriptorContext that provides a format context.

destinationType Type

A Type that represents the type you want to convert to.

Returns

bool:

true if this converter can perform the conversion; otherwise, false.

ConvertTo(ITypeDescriptorContext?, CultureInfo?, object?, Type)

Converts the given value object to the specified type, using the specified context and culture information.

public override object? ConvertTo(ITypeDescriptorContext? context, CultureInfo? culture, object? value, Type destinationType)
Parameter Type Description
context ITypeDescriptorContext

An ITypeDescriptorContext that provides a format context.

culture CultureInfo

A CultureInfo. If null is passed, the current culture is assumed.

value object

The object to convert.

destinationType Type

The Type to convert the value parameter to.

Returns

object:

An object that represents the converted value.

Exceptions

Type Condition
ArgumentNullException

The destinationType parameter is null.

NotSupportedException

The conversion cannot be performed.

CreateCollectionItemPropertyDescriptor(ITypeDescriptorContext?, Attribute[]?, ICollection, int, object, Type)

Creates an instance of PropertyDescriptor for the collection item.

protected virtual PropertyDescriptor CreateCollectionItemPropertyDescriptor(ITypeDescriptorContext? context, Attribute[]? attributes, ICollection collection, int index, object item, Type itemType)
Parameter Type Description
context ITypeDescriptorContext

An ITypeDescriptorContext that provides a format context.

attributes Attribute[]

An array of type Attribute that will be used as a filter.

collection ICollection

The collection that contains the item.

index int

The index of the item in the collection.

item object

The item in the collection.

itemType Type

Type of the item.

Returns

PropertyDescriptor:

An instance of PropertyDescriptor for the collection item.

CreateDictionaryItemPropertyDescriptor(ITypeDescriptorContext?, Attribute[]?, IDictionary, object, Type)

Creates an instance of PropertyDescriptor for the dictionary item.

protected virtual PropertyDescriptor CreateDictionaryItemPropertyDescriptor(ITypeDescriptorContext? context, Attribute[]? attributes, IDictionary dictionary, object key, Type itemType)
Parameter Type Description
context ITypeDescriptorContext

An ITypeDescriptorContext that provides a format context.

attributes Attribute[]

An array of type Attribute that will be used as a filter.

dictionary IDictionary

The dictionary that contains the item.

key object

The key of the item in the dictionary.

itemType Type

Type of the item.

Returns

PropertyDescriptor:

An instance of PropertyDescriptor for the dictionary item.

CreateItem(IPropertyModel)

Creates a new item that can be added into to the collection.

public virtual object? CreateItem(IPropertyModel propertyModel)
Parameter Type Description
propertyModel IPropertyModel

The IPropertyModel associated with the collection.

Returns

object:

The item that was created.

CreateListItemPropertyDescriptor(ITypeDescriptorContext?, Attribute[]?, IList, int, Type)

Creates an instance of PropertyDescriptor for the list item.

protected virtual PropertyDescriptor CreateListItemPropertyDescriptor(ITypeDescriptorContext? context, Attribute[]? attributes, IList list, int index, Type itemType)
Parameter Type Description
context ITypeDescriptorContext

An ITypeDescriptorContext that provides a format context.

attributes Attribute[]

An array of type Attribute that will be used as a filter.

list IList

The list that contains the item.

index int

The index of the item in the list.

itemType Type

Type of the item.

Returns

PropertyDescriptor:

An instance of PropertyDescriptor for the list item.

GetCollectionProperties(ITypeDescriptorContext?, Attribute[]?, ICollection)

Returns a collection of properties for the specified collection using the specified context and attributes.

protected virtual PropertyDescriptor[]? GetCollectionProperties(ITypeDescriptorContext? context, Attribute[]? attributes, ICollection collection)
Parameter Type Description
context ITypeDescriptorContext

An ITypeDescriptorContext that provides a format context.

attributes Attribute[]

An array of type Attribute that will be used as a filter.

collection ICollection

The collection whose properties should be returned.

Returns

PropertyDescriptor[]:

A PropertyDescriptor array with the properties associated with the specified collection, or null if there are no properties.

GetDictionaryProperties(ITypeDescriptorContext?, Attribute[]?, IDictionary)

Returns a collection of properties for the specified dictionary using the specified context and attributes.

protected virtual PropertyDescriptor[]? GetDictionaryProperties(ITypeDescriptorContext? context, Attribute[]? attributes, IDictionary dictionary)
Parameter Type Description
context ITypeDescriptorContext

An ITypeDescriptorContext that provides a format context.

attributes Attribute[]

An array of type Attribute that will be used as a filter.

dictionary IDictionary

The dictionary whose properties should be returned.

Returns

PropertyDescriptor[]:

A PropertyDescriptor array with the properties associated with the specified dictionary, or null if there are no properties.

GetListProperties(ITypeDescriptorContext?, Attribute[]?, IList)

Returns a collection of properties for the specified list using the specified context and attributes.

protected virtual PropertyDescriptor[]? GetListProperties(ITypeDescriptorContext? context, Attribute[]? attributes, IList list)
Parameter Type Description
context ITypeDescriptorContext

An ITypeDescriptorContext that provides a format context.

attributes Attribute[]

An array of type Attribute that will be used as a filter.

list IList

The list whose properties should be returned.

Returns

PropertyDescriptor[]:

A PropertyDescriptor array with the properties associated with the specified list, or null if there are no properties.

GetProperties(ITypeDescriptorContext?, object, Attribute[]?)

Returns a collection of properties for the type of array specified by the value parameter, using the specified context and attributes.

public override PropertyDescriptorCollection? GetProperties(ITypeDescriptorContext? context, object value, Attribute[]? attributes)
Parameter Type Description
context ITypeDescriptorContext

An ITypeDescriptorContext that provides a format context.

value object

An object that specifies the type of array for which to get properties.

attributes Attribute[]

An array of type Attribute that is used as a filter.

Returns

PropertyDescriptorCollection:

A PropertyDescriptorCollection with the properties that are exposed for this data type, or null if there are no properties.

GetPropertiesSupported(ITypeDescriptorContext?)

Returns whether this object supports properties, using the specified context.

public override bool GetPropertiesSupported(ITypeDescriptorContext? context)
Parameter Type Description
context ITypeDescriptorContext

An ITypeDescriptorContext that provides a format context.

Returns

bool:

true if GetProperties(object) should be called to find the properties of this object; otherwise, false.

Remarks

The default method implementation always returns true since child items should be accessible as nested properties.

Inherited Members

Extension Methods