Class Serializer
- Namespace
- NMF.Serialization
- Assembly
- NMF.Serialization.dll
Denotes the base class for a serializer
public class Serializer
- Inheritance
-
Serializer
- Derived
- Inherited Members
Constructors
Serializer()
Creates a new XmlSerializer with default settings and no preloaded types
public Serializer()
Serializer(Serializer)
Creates a new XmlSerializer and copies settings and known types from the given serializer
public Serializer(Serializer parent)
Parameters
parentSerializerAn XML serializer to copy settings and known type information from
Serializer(Serializer, XmlSerializationSettings)
Creates a new XmlSerializer and copies settings and known types from the given serializer
public Serializer(Serializer parent, XmlSerializationSettings settings)
Parameters
parentSerializerAn XML serializer to copy settings and known type information from
settingsXmlSerializationSettingsNew settings
Serializer(Serializer, XmlSerializationSettings, IEnumerable<Type>)
Creates a new XmlSerializer and copies settings and known types from the given serializer
public Serializer(Serializer parent, XmlSerializationSettings settings, IEnumerable<Type> additionalTypes)
Parameters
parentSerializerAn XML serializer to copy settings and known type information from
settingsXmlSerializationSettingsNew settings
additionalTypesIEnumerable<Type>Set of types to load into the serializer
Serializer(XmlSerializationSettings)
Creates a new XmlSerializer with the specified settings
public Serializer(XmlSerializationSettings settings)
Parameters
settingsXmlSerializationSettingsSerializer-settings for the serializer. Can be null or Nothing in Visual Basic. In this case, the default settings will be used.
Serializer(XmlSerializationSettings, IEnumerable<Type>)
Creates a new XmlSerializer with the specified settings and the given preloaded types
public Serializer(XmlSerializationSettings settings, IEnumerable<Type> additionalTypes)
Parameters
settingsXmlSerializationSettingsThe settings to use for the serializer
additionalTypesIEnumerable<Type>Set of types to load into the serializer
Remarks
The types will be loaded with the specified settings
Serializer(IEnumerable<Type>)
Creates a new XmlSerializer with default settings
public Serializer(IEnumerable<Type> additionalTypes)
Parameters
additionalTypesIEnumerable<Type>Set of types to preload into the serializer
Remarks
Types will be loaded with default settings
Properties
KnownTypes
The set of types that are known to the serializer
public ICollection<Type> KnownTypes { get; }
Property Value
Settings
The settings to be used in the serializer
public XmlSerializationSettings Settings { get; }
Property Value
Methods
ConvertString(string, IPropertySerializationInfo, XmlSerializationContext)
Converts the given string to a value
protected object ConvertString(string text, IPropertySerializationInfo info, XmlSerializationContext context)
Parameters
textstringthe string that needs to be parsed
infoIPropertySerializationInfothe property for which the string is parsed
contextXmlSerializationContextthe context in which the string is parsed
Returns
- object
the parsed object
CreateAddToPropertyDelay(IPropertySerializationInfo, object, string, XmlSerializationContext)
Adds a delay to add an item to a property collection
protected static void CreateAddToPropertyDelay(IPropertySerializationInfo property, object obj, string text, XmlSerializationContext context)
Parameters
propertyIPropertySerializationInfothe property for which the item is added
objobjectthe target object
textstringthe original text in the JSON document
contextXmlSerializationContextthe context in which the deserialization is done
CreateSerializationContext(object)
Creates a serialization context for the given root element
protected virtual XmlSerializationContext CreateSerializationContext(object root)
Parameters
rootobjectThe root element of the serialization
Returns
- XmlSerializationContext
A serialization context
CreateSetPropertyDelay(IPropertySerializationInfo, object, string, XmlSerializationContext)
Adds a delay to set a property directly from a resolved text
protected static void CreateSetPropertyDelay(IPropertySerializationInfo property, object obj, string text, XmlSerializationContext context)
Parameters
propertyIPropertySerializationInfothe property that should be set,
objobjectthe target object
textstringthe original text in the JSON document
contextXmlSerializationContextthe context in which the deserialization is done
CreateTypeSerializationInfoFor(Type)
Creates the type serialization information for the given type
protected virtual ITypeSerializationInfo CreateTypeSerializationInfoFor(Type type)
Parameters
typeTypethe system type for which the serialization information should be created
Returns
- ITypeSerializationInfo
a type serialization info
GetAttributeValue(object, ITypeSerializationInfo, bool, XmlSerializationContext)
Gets the serialization of the given attribute value
protected virtual string GetAttributeValue(object value, ITypeSerializationInfo info, bool isCollection, XmlSerializationContext context)
Parameters
valueobjectThe value of the attribute
infoITypeSerializationInfoThe serialization information of the type
isCollectionboolTrue, if the value is added to a collection, otherwise false
contextXmlSerializationContextThe serialization context
Returns
- string
The serialized value of the attribute
GetSerializationInfo(Type, bool)
Gets the serialization information for the given type
public ITypeSerializationInfo GetSerializationInfo(Type type, bool createIfNecessary)
Parameters
typeTypeThe type
createIfNecessaryboolIf true, the serialization information is added if missing
Returns
- ITypeSerializationInfo
The type serialization information
GetSerializationInfoForInstance(object, bool)
Gets the serialization information for the provided instance
public virtual ITypeSerializationInfo GetSerializationInfoForInstance(object instance, bool createIfNecessary)
Parameters
instanceobjectThe instance
createIfNecessaryboolIf true, the serialization information is added if missing
Returns
- ITypeSerializationInfo
The type serialization information
GetTypeInfo(string, string)
Gets the type serialization info corresponding to the provided pair of namespace and local name
public ITypeSerializationInfo GetTypeInfo(string ns, string localName)
Parameters
Returns
- ITypeSerializationInfo
the type serialization info
HandleUnknownType(IPropertySerializationInfo, string, string)
Handles the case that the type of the element is not known
protected virtual ITypeSerializationInfo HandleUnknownType(IPropertySerializationInfo property, string ns, string localName)
Parameters
propertyIPropertySerializationInfoThe property for which the type was requested
nsstringThe namespace at the current position
localNamestringThe local name of the type
Returns
- ITypeSerializationInfo
The type serialization information received for this type or null, if no type could be resolved
InitializeTypeSerializationInfo(Type, ITypeSerializationInfo)
Initializes the given type serialization information for the given type
protected virtual void InitializeTypeSerializationInfo(Type type, ITypeSerializationInfo serializationInfo)
Parameters
typeTypethe system type
serializationInfoITypeSerializationInfothe serialization information object
OnConverterException(ConverterExceptionEventArgs)
Gets called when the ConverterException event should be raised
protected virtual void OnConverterException(ConverterExceptionEventArgs eventArgs)
Parameters
eventArgsConverterExceptionEventArgsThe event data
OnUnknownAttribute(UnknownAttributeEventArgs)
Fires the UnknownAttribute event
protected virtual void OnUnknownAttribute(UnknownAttributeEventArgs e)
Parameters
eUnknownAttributeEventArgsthe event data
OnUnknownElement(UnknownElementEventArgs)
Fires the UnknownElement event
protected virtual void OnUnknownElement(UnknownElementEventArgs e)
Parameters
eUnknownElementEventArgsthe event data
OnUnknownType(UnknownTypeEventArgs)
Handles the UnknownType event
protected virtual void OnUnknownType(UnknownTypeEventArgs e)
Parameters
eUnknownTypeEventArgsthe event data
RegisterNamespace(ITypeSerializationInfo, string)
Registers the given type serialization info for a namespace lookup
protected void RegisterNamespace(ITypeSerializationInfo info, string ns)
Parameters
infoITypeSerializationInfothe type serialization info
nsstringthe namespace for which the type should be registered
SelectRoot(object, bool)
Gets the serialization root element
protected virtual object SelectRoot(object graph, bool fragment)
Parameters
graphobjectThe base element that should be serialized
fragmentboolA value indicating whether only a fragment should be written
Returns
- object
The root element for serialization
Events
ConverterException
Gets raised when a converter used by the serializer ran into an exception
public event EventHandler<ConverterExceptionEventArgs> ConverterException
Event Type
UnknownAttribute
Get raised when the serializer finds an attribute that is not known
public event EventHandler<UnknownAttributeEventArgs> UnknownAttribute
Event Type
UnknownElement
Gets raised when the serializer finds an element that is not known
public event EventHandler<UnknownElementEventArgs> UnknownElement
Event Type
UnknownType
Gets raised when the serializer finds a type that is not known
public event EventHandler<UnknownTypeEventArgs> UnknownType