Table of Contents

Class ValueTypeConverter<T>

Namespace
NanoByte.Common.Values.Design
Assembly
NanoByte.Common.dll

Abstract base-class for easily creating a TypeConverter for a struct (value type).

[RequiresUnreferencedCode("Uses reflection to discover properties.")]
public abstract class ValueTypeConverter<T> : TypeConverter where T : struct

Type Parameters

T

The struct to create the TypeConverter for.

Inheritance
object
ValueTypeConverter<T>
Inherited Members
Extension Methods

Examples

Add this attribute to the struct:

[TypeConverter(typeof(ClassDerivedFromThisOne))]

Remarks

Providing a TypeConverter for a struct improves the runtime experience with PropertyGrids.

Constructors

ValueTypeConverter()

protected ValueTypeConverter()

Properties

NoArguments

The number of arguments the constructor of T has.

protected abstract int NoArguments { get; }

Property Value

int

Methods

CanConvertFrom(ITypeDescriptorContext?, Type)

public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType)

Parameters

context ITypeDescriptorContext
sourceType Type

Returns

bool

CanConvertTo(ITypeDescriptorContext?, Type?)

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

Parameters

context ITypeDescriptorContext
destinationType Type

Returns

bool

ConvertFrom(ITypeDescriptorContext?, CultureInfo?, object)

public override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value)

Parameters

context ITypeDescriptorContext
culture CultureInfo
value object

Returns

object

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

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

Parameters

context ITypeDescriptorContext
culture CultureInfo
value object
destinationType Type

Returns

object

CreateInstance(ITypeDescriptorContext?, IDictionary)

public override object CreateInstance(ITypeDescriptorContext? context, IDictionary propertyValues)

Parameters

context ITypeDescriptorContext
propertyValues IDictionary

Returns

object

GetArguments(T)

protected abstract object[] GetArguments(T value)

Parameters

value T

Returns

object[]

The arguments for the constructor of T.

GetConstructor()

protected abstract ConstructorInfo GetConstructor()

Returns

ConstructorInfo

The constructor used to create new instances of T (deserialization).

GetCreateInstanceSupported(ITypeDescriptorContext?)

public override bool GetCreateInstanceSupported(ITypeDescriptorContext? context)

Parameters

context ITypeDescriptorContext

Returns

bool

GetElementSeparator(CultureInfo)

The separator to place between individual elements.

protected virtual string GetElementSeparator(CultureInfo culture)

Parameters

culture CultureInfo

Returns

string

GetObject(IDictionary)

protected abstract T GetObject(IDictionary propertyValues)

Parameters

propertyValues IDictionary

Returns

T

A new instance of T.

GetObject(string[], CultureInfo)

protected abstract T GetObject(string[] values, CultureInfo culture)

Parameters

values string[]
culture CultureInfo

Returns

T

A new instance of T.

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

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

Parameters

context ITypeDescriptorContext
value object
attributes Attribute[]

Returns

PropertyDescriptorCollection

GetPropertiesSupported(ITypeDescriptorContext?)

public override bool GetPropertiesSupported(ITypeDescriptorContext? context)

Parameters

context ITypeDescriptorContext

Returns

bool

GetValues(T, ITypeDescriptorContext?, CultureInfo)

protected abstract string[] GetValues(T value, ITypeDescriptorContext? context, CultureInfo culture)

Parameters

value T
context ITypeDescriptorContext
culture CultureInfo

Returns

string[]

The elements of T converted to strings.