Click or drag to resize

ObjectToDescriptionConverter Class

Takes an object and returns the description taken from it's DescriptionAttribute
Inheritance Hierarchy

Namespace: TomsToolbox.Wpf.Converters
Assembly: TomsToolbox.Wpf (in TomsToolbox.Wpf.dll) Version: 2.21.0+44d18b541fc9419ec3c549350a832394661b2a4d
XMLNS for XAML: Not mapped to an xmlns.
Syntax
[ValueConversionAttribute(typeof(Object), typeof(string))]
public class ObjectToDescriptionConverter : ObjectToAttributeConverter<DescriptionAttribute>

The ObjectToDescriptionConverter type exposes the following members.

Constructors
 NameDescription
Public methodObjectToDescriptionConverterInitializes a new instance of the ObjectToDescriptionConverter class
Top
Properties
 NameDescription
Public propertyConvertBackErrorValue Gets or sets the error value, which is returned whenever the value to convert back produces an error; the default is UnsetValue.
(Inherited from ValueConverter)
Public propertyConvertBackNullValue Gets or sets the null value, which is returned whenever the value to convert back is null; the default is null.
(Inherited from ValueConverter)
Public propertyConvertBackUnsetValue Gets or sets the unset value, which is returned whenever the value to convert back is UnsetValue; the default is UnsetValue.
(Inherited from ValueConverter)
Public propertyConvertErrorValue Gets or sets the error value, which is returned whenever the value to convert produces an error; the default is UnsetValue.
(Inherited from ValueConverter)
Public propertyConvertNullValue Gets or sets the null value, which is returned whenever the value to convert is null; the default is null.
(Inherited from ValueConverter)
Public propertyConvertUnsetValue Gets or sets the unset value, which is returned whenever the value to convert is UnsetValue; the default is UnsetValue.
(Inherited from ValueConverter)
Top
Methods
 NameDescription
Public methodStatic memberConvert(Object) Converts the specified value to the description taken from it's DescriptionAttribute
Public methodStatic memberConvert(Object, Type) Converts the specified value to the description taken from it's DescriptionAttribute
Protected methodConvert(Object, Type, Object, CultureInfo) Converts a value. UnSet is unchanged, null becomes an empty string.
(Overrides ObjectToAttributeConverterTConvert(Object, Type, Object, CultureInfo))
Protected methodConvertBack Converts a value.
(Inherited from ValueConverter)
Public methodProvideValue When implemented in a derived class, returns an object that is provided as the value of the target property for this markup extension.
(Inherited from ValueConverter)
Top
Fields
 NameDescription
Public fieldStatic memberDefault The singleton instance of the converter.
Top
Extension Methods
 NameDescription
Public Extension MethodSafeCastT Performs a cast from object to T, avoiding possible null violations if T is a value type.
(Defined by ObjectExtensions)
Top
Remarks
Works with any object; for enum types the attribute of the field is returned.
Example
C#
enum Items
{
    [Description("This is item 1")]
    Item1,
    [Description("This is item 2")]
    Item2
}

Assert.Equals("This is item 1", ObjectToDescriptionConverter.Convert(Items.Item1));
See Also