ValueSerializer::GetSerializerFor Method (PropertyDescriptor^)
Gets the ValueSerializer declared for a property, by passing a CLR property descriptor for the property.
Assembly: System.Xaml (in System.Xaml.dll)
Parameters
- descriptor
-
Type:
System.ComponentModel::PropertyDescriptor^
The CLR property descriptor for the property to be serialized.
Return Value
Type: System.Windows.Markup::ValueSerializer^The serializer associated with the specified property. May return null.
| Exception | Condition |
|---|---|
| ArgumentNullException | descriptor is null. |
A ValueSerializer for a property, or for a type that is used as the value for a property, is indicated by applying the ValueSerializerAttribute attribute on the property or type declaration. The GetSerializerFor method is a utility method that reads the CLR type system information and returns a new ValueSerializer class based on the attribute if found on the property, or then if found on the property's type. null might be returned if no such serializer exists. null might also be returned if a type or property is deliberately attributed with a null-value ValueSerializerAttribute.
Another mode that GetSerializerFor supports is returning the internal TypeConverterValueSerializer class, which is a ValueSerializer implementation that wraps a TypeConverter and translates the Convert methods to Convert*String methods (for instance TypeConverter::ConvertTo is called with input of the String type, and translates to ConvertToString. This is done only in cases where all of the following are true:
A TypeConverterAttribute is found on the relevant property, or the relevant property's type.
The indicated TypeConverter can be successfully constructed.
The TypeConverter returns true for TypeConverter::ConvertTo, called referencing the String type.
The TypeConverter returns true for TypeConverter::CanConvertTo, called referencing the String type.
The TypeConverter returns true for TypeConverter::CanConvertFrom, called referencing the String type.
Note |
|---|
The following are special cases: DateTime types return a DateTimeValueSerializer; String types return an internal but functional serializer (StringValueSerializer). |
Available since 3.0
