net472_PropertyGridHelpers.Converters_TypeConverter 1 - dparvin/PropertyGridHelpers GitHub Wiki

TypeConverter<T> class

A generic ExpandableObjectConverter that enables editing of complex types with nested properties directly in a PropertyGrid.

public class TypeConverter<T> : ExpandableObjectConverter
parameter description
T The type to expand in the property grid. This type should expose public properties to be displayed as editable sub-properties.

Public Members

name description
TypeConverter() The default constructor.
override CanConvertFrom(…)
override CanConvertTo(…)
override ConvertFrom(…) Converts from a string to an instance of T, if supported.
override ConvertTo(…) Converts an object of type T to the requested destination type.

Remarks

This converter supports:

  • Expanding nested objects in the property grid for inline editing.
  • Conversion of T to and from string via ToString() and optional parsing if T implements IParsable<T>.
  • Compatibility with .NET 7+ IParsable<T> interface when present.

Examples

public class Size
{
    public int Width { get; set; }
    public int Height { get; set; }
}

[TypeConverter(typeof(TypeConverter<Size>))]
public Size MySize { get; set; }

This will allow MySize to expand in a property grid with separate editors for Width and Height.

See Also

⚠️ **GitHub.com Fallback** ⚠️