Skip to end of metadata
Go to start of metadata

A utility class for serializing UI objects into Xaml such as controls and DependencyObjects. Understands concepts like Bindings, StaticResources, Styles, and Templates.

Definition

public class UiXamlSerializer : XamlSerializer

Summary

The following table summarizes the members exposed in this class.

Public Constructors

UiXamlSerializer Constructor(bool, bool) Constructs a UiXamlSerializer.

Protected Methods

GetPropertyOrder(PropertyInfo) Gets a string for a property used to determine the order in which properties will be serialized.
IsInlinable(object, object, MemberInfo, ISet<object>) Determines whether the given property can be written inline (as an attribute) rather than using object-element syntax.
PostSerialize(object, String&) Called after serialization (and can be used for cleanup).
PreSerialize(object, Dictionary<string, string>, ISet<object>) Called before serialization (and can be used for initialization).
ShouldSerialize(object, object, PropertyInfo) Determines whether a property should be serialized (based upon the DefaultAttribute and ShouldSerialize methods).
VisitAfterAttributes(object, XmlWriter, IDictionary<string, string>, ISet<object>) Called after all properties that can be written as attributes (rather than in object-element syntax) are written, but before an object-element content is written. Use this virtual as an opportunity to inject additional attributes before the object is written.
VisitAfterBeginElement(object, XmlWriter, IDictionary<string, string>, ISet<object>) Called immediately after the BeginElement for the object being serialized has been written.
VisitAlternateContent(object, XmlWriter, IDictionary<string, string>, ISet<object>) Called when an object's Content property was not set, allowing special types (e.g. Templates) whose content properties are not discoverable publicly, to be serialized.
VisitAttachedProperty(object, object, string, MethodInfo, MethodInfo, XmlWriter, IDictionary<string, string>, ISet<object>) Serializes an attached property on an object.
VisitBeforeEndElement(object, XmlWriter, IDictionary<string, string>, ISet<object>) Called immediately before the EndElement for the object being serialized is called. Can be used for cleanup.
VisitDictionaryContents(IDictionary, XmlWriter, IDictionary<string, string>, ISet<object>) Serializes the contents of a dictionary.
VisitProperty(object, object, PropertyInfo, bool, XmlWriter, IDictionary<string, string>, ISet<object>) Serializes a property.
VisitPropertyPath(string, string, string, XmlWriter, IDictionary<string, string>, ISet<object>) Serializes a PropertyPath.
VisitRootAttribute(object, XmlWriter, IDictionary<string, string>, ISet<object>) Called during attribute serialization on the root object. Can be used for global namespace declaration.

Public Constructors

public UiXamlSerializer(bool serializeBindings, bool includeUnsetValues)

Constructs a UiXamlSerializer.

Parameters

serializeBindings Determines whether bindings will be serialized.
includeUnsetValues Determines whether unset dependency properties will be serialized.

Protected Methods

protected string GetPropertyOrder(PropertyInfo prop)

Gets a string for a property used to determine the order in which properties will be serialized.

Parameters

prop The property being serialized.

Return Types

A sortable string representation for the property.

protected bool IsInlinable(object obj, object propValue, MemberInfo inf, ISet<object> cycleCheckObjects)

Determines whether the given property can be written inline (as an attribute) rather than using object-element syntax.

Parameters

obj The object on which the property is being set.
propValue The value of the property being set.
inf The identifier for the property being set (a PropertyInfo for a property, and the getter MethodInfo for an attached property).
cycleCheckObjects The set of objects on the stack (for cycle detection).

protected void PostSerialize(object obj, String& str)

Called after serialization (and can be used for cleanup).

Parameters

obj The object being serialized.
str The serialized Xaml, which can be modified for cleanup during this method.

protected void PreSerialize(object obj, Dictionary<string, string> prefixMappings, ISet<object> cycleCheckObjects)

Called before serialization (and can be used for initialization).

Parameters

obj The object being serialized.
prefixMappings The initial dictionary of prefixes, which can be primed for custom serializers.
cycleCheckObjects The set of objects on the stack, which can be primed if certain objects must be avoided.

protected bool ShouldSerialize(object obj, object propValue, PropertyInfo prop)

Determines whether a property should be serialized (based upon the DefaultAttribute and ShouldSerialize methods).

Parameters

obj The object being serialized.
propValue The value of the property being serialized.
prop The property being serialized.

Return Types

true if the property should be serialized, false otherwise.

protected void VisitAfterAttributes(object obj, XmlWriter writer, IDictionary<string, string> prefixMappings, ISet<object> cycleCheckObjects)

Called after all properties that can be written as attributes (rather than in object-element syntax) are written, but before an object-element content is written. Use this virtual as an opportunity to inject additional attributes before the object is written.

Parameters

obj The object being serialized.
writer The writer being used for serialization.
prefixMappings A mapping of xml namespaces to prefixes.
cycleCheckObjects The set of objects on the stack (for cycle detection).

protected void VisitAfterBeginElement(object obj, XmlWriter writer, IDictionary<string, string> prefixMappings, ISet<object> cycleCheckObjects)

Called immediately after the BeginElement for the object being serialized has been written.

Parameters

obj The object being serialized.
writer The writer being used for serialization.
prefixMappings A mapping of xml namespaces to prefixes.
cycleCheckObjects The set of objects on the stack (for cycle detection).

protected void VisitAlternateContent(object obj, XmlWriter writer, IDictionary<string, string> prefixMappings, ISet<object> cycleCheckObjects)

Called when an object's Content property was not set, allowing special types (e.g. Templates) whose content properties are not discoverable publicly, to be serialized.

Parameters

obj The object being serialized.
writer The writer being used for serialization.
prefixMappings A mapping of xml namespaces to prefixes.
cycleCheckObjects The set of objects on the stack (for cycle detection).

protected void VisitAttachedProperty(object obj, object propValue, string propertyName, MethodInfo getter, MethodInfo setter, XmlWriter writer, IDictionary<string, string> prefixMappings, ISet<object> cycleCheckObjects)

Serializes an attached property on an object.

Parameters

obj The object on which the attached property is set.
propValue The value of the attached property.
propertyName The name of the attached property.
getter The getter method for the attached property.
setter The setter method for the attached property.
writer The writer being used to serialize the object.
prefixMappings A mapping of xml namespaces to prefixes.
cycleCheckObjects The set of objects currently on the stack (for cycle detection).

protected void VisitBeforeEndElement(object obj, XmlWriter writer, IDictionary<string, string> prefixMappings, ISet<object> cycleCheckObjects)

Called immediately before the EndElement for the object being serialized is called. Can be used for cleanup.

Parameters

obj The object being serialized.
writer The writer being used for serialization.
prefixMappings A mapping of xml namespaces to prefixes.
cycleCheckObjects The set of objects on the stack (for cycle detection).

protected void VisitDictionaryContents(IDictionary dict, XmlWriter writer, IDictionary<string, string> prefixMappings, ISet<object> cycleCheckObjects)

Serializes the contents of a dictionary.

Parameters

dict The dictionary being serialized.
writer The writer being used for serialization.
prefixMappings A mapping of xml namespaces to prefixes.
cycleCheckObjects The set of objects on the stack (for cycle detection).

protected void VisitProperty(object obj, object propValue, PropertyInfo prop, bool isContentProperty, XmlWriter writer, IDictionary<string, string> prefixMappings, ISet<object> cycleCheckObjects)

Serializes a property.

Parameters

obj The object on which the property is set.
propValue The value of the property.
prop The property being set.
isContentProperty A value indicating that the property is the ContentProperty for the object, and thus no property elements need to be generated.
writer The writer being used for serialization.
prefixMappings A mapping of xml namespaces to prefixes.
cycleCheckObjects The set of objects on the stack (for cycle detection).

protected void VisitPropertyPath(string path, string propertyName, string propNs, XmlWriter writer, IDictionary<string, string> prefixMappings, ISet<object> cycleCheckObjects)

Serializes a PropertyPath.

Parameters

path The path being serialized.
propertyName The name of the property being serialized.
propNs The namespace for the property being serialized.
writer The writer being used for serialization.
prefixMappings A mapping of xml namespaces to prefixes.
cycleCheckObjects The set of objects on the stack (for cycle detection).

protected void VisitRootAttribute(object obj, XmlWriter writer, IDictionary<string, string> prefixMappings, ISet<object> cycleCheckObjects)

Called during attribute serialization on the root object. Can be used for global namespace declaration.

Parameters

obj The root object.
writer The writer being used for serialization.
prefixMappings A mapping of xml namespaces to prefixes.
cycleCheckObjects The set of objects on the stack (for cycle detection).
  • No labels