Breyta

Deila með


ValueSerializer.GetSerializerFor Method

Definition

Gets the ValueSerializer for an object.

Overloads

GetSerializerFor(PropertyDescriptor)

Gets the ValueSerializer declared for a property, by passing a CLR property descriptor for the property.

GetSerializerFor(Type)

Gets the ValueSerializer declared for the specified type.

GetSerializerFor(PropertyDescriptor, IValueSerializerContext)

Gets the ValueSerializer declared for the specified property, using the specified context.

GetSerializerFor(Type, IValueSerializerContext)

Gets the ValueSerializer declared for the specified type, using the specified context.

GetSerializerFor(PropertyDescriptor)

Gets the ValueSerializer declared for a property, by passing a CLR property descriptor for the property.

public:
 static System::Windows::Markup::ValueSerializer ^ GetSerializerFor(System::ComponentModel::PropertyDescriptor ^ descriptor);
public static System.Windows.Markup.ValueSerializer GetSerializerFor (System.ComponentModel.PropertyDescriptor descriptor);
static member GetSerializerFor : System.ComponentModel.PropertyDescriptor -> System.Windows.Markup.ValueSerializer
Public Shared Function GetSerializerFor (descriptor As PropertyDescriptor) As ValueSerializer

Parameters

descriptor
PropertyDescriptor

The CLR property descriptor for the property to be serialized.

Returns

The serializer associated with the specified property. May return null.

Exceptions

descriptor is null.

Remarks

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:

Note

The following are special cases: DateTime types return a DateTimeValueSerializer; String types return an internal but functional serializer (StringValueSerializer).

Applies to

GetSerializerFor(Type)

Gets the ValueSerializer declared for the specified type.

public:
 static System::Windows::Markup::ValueSerializer ^ GetSerializerFor(Type ^ type);
public static System.Windows.Markup.ValueSerializer GetSerializerFor (Type type);
static member GetSerializerFor : Type -> System.Windows.Markup.ValueSerializer
Public Shared Function GetSerializerFor (type As Type) As ValueSerializer

Parameters

type
Type

The type to get the ValueSerializer for.

Returns

The serializer associated with the specified type. May return null.

Exceptions

type is null.

Remarks

A ValueSerializer for a type is indicated by applying the ValueSerializerAttribute attribute on the 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 specified type. null might be returned if no such serializer exists. null might also be returned if a type 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:

Note

The following are special cases: DateTime types return a DateTimeValueSerializer; String types return an internal but functional serializer (StringValueSerializer).

Applies to

GetSerializerFor(PropertyDescriptor, IValueSerializerContext)

Gets the ValueSerializer declared for the specified property, using the specified context.

public:
 static System::Windows::Markup::ValueSerializer ^ GetSerializerFor(System::ComponentModel::PropertyDescriptor ^ descriptor, System::Windows::Markup::IValueSerializerContext ^ context);
public static System.Windows.Markup.ValueSerializer GetSerializerFor (System.ComponentModel.PropertyDescriptor descriptor, System.Windows.Markup.IValueSerializerContext context);
static member GetSerializerFor : System.ComponentModel.PropertyDescriptor * System.Windows.Markup.IValueSerializerContext -> System.Windows.Markup.ValueSerializer
Public Shared Function GetSerializerFor (descriptor As PropertyDescriptor, context As IValueSerializerContext) As ValueSerializer

Parameters

descriptor
PropertyDescriptor

Descriptor for the property to be serialized.

context
IValueSerializerContext

Context information that is used for conversion.

Returns

The serializer associated with the specified property.

Exceptions

descriptor is null.

Remarks

Rather than relying purely on attributes reported in the CLR type system, this overload uses the context as a service, and calls the service's implementation of IValueSerializerContext.GetValueSerializerFor. The IValueSerializerContext.GetValueSerializerFor implementation would typically also rely on the descriptor, but might implement special behavior for certain contexts.

This method should be called when the caller has an available IValueSerializerContext from a service. This will ensure that the correct ValueSerializer is returned for the specific context.

If the context returns null from its IValueSerializerContext.GetValueSerializerFor for your specified descriptor, or if the context you specify is null, then behavior is identical to calling the GetSerializerFor(PropertyDescriptor) overload.

Applies to

GetSerializerFor(Type, IValueSerializerContext)

Gets the ValueSerializer declared for the specified type, using the specified context.

public:
 static System::Windows::Markup::ValueSerializer ^ GetSerializerFor(Type ^ type, System::Windows::Markup::IValueSerializerContext ^ context);
public static System.Windows.Markup.ValueSerializer GetSerializerFor (Type type, System.Windows.Markup.IValueSerializerContext context);
static member GetSerializerFor : Type * System.Windows.Markup.IValueSerializerContext -> System.Windows.Markup.ValueSerializer
Public Shared Function GetSerializerFor (type As Type, context As IValueSerializerContext) As ValueSerializer

Parameters

type
Type

The type to get the ValueSerializer for.

context
IValueSerializerContext

Context information that is used for conversion.

Returns

The serializer associated with the specified type.

Exceptions

type is null.

Remarks

Rather than relying purely on attributes reported in the CLR type system, this overload uses the context as a service, and calls the service's implementation of IValueSerializerContext.GetValueSerializerFor. The IValueSerializerContext.GetValueSerializerFor implementation would typically also rely on the type, but might implement special behavior for certain contexts.

This method should be called when the caller has an available IValueSerializerContext from a service. This will ensure that the correct ValueSerializer is returned for the specific context.

If the context returns null from its IValueSerializerContext.GetValueSerializerFor for your specified type, or if the context you specify is null, then behavior is identical to calling the GetSerializerFor(Type) overload.

Applies to