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
parent
SerializerAn 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
parent
SerializerAn XML serializer to copy settings and known type information from
settings
XmlSerializationSettingsNew 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
parent
SerializerAn XML serializer to copy settings and known type information from
settings
XmlSerializationSettingsNew settings
additionalTypes
IEnumerable<Type>Set of types to load into the serializer
Serializer(XmlSerializationSettings)
Creates a new XmlSerializer with the specified settings
public Serializer(XmlSerializationSettings settings)
Parameters
settings
XmlSerializationSettingsSerializer-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
settings
XmlSerializationSettingsThe settings to use for the serializer
additionalTypes
IEnumerable<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
additionalTypes
IEnumerable<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
text
stringthe string that needs to be parsed
info
IPropertySerializationInfothe property for which the string is parsed
context
XmlSerializationContextthe 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
property
IPropertySerializationInfothe property for which the item is added
obj
objectthe target object
text
stringthe original text in the JSON document
context
XmlSerializationContextthe 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
root
objectThe 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
property
IPropertySerializationInfothe property that should be set,
obj
objectthe target object
text
stringthe original text in the JSON document
context
XmlSerializationContextthe 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
type
Typethe 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
value
objectThe value of the attribute
info
ITypeSerializationInfoThe serialization information of the type
isCollection
boolTrue, if the value is added to a collection, otherwise false
context
XmlSerializationContextThe 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
type
TypeThe type
createIfNecessary
boolIf 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
instance
objectThe instance
createIfNecessary
boolIf 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
property
IPropertySerializationInfoThe property for which the type was requested
ns
stringThe namespace at the current position
localName
stringThe 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
type
Typethe system type
serializationInfo
ITypeSerializationInfothe serialization information object
OnConverterException(ConverterExceptionEventArgs)
Gets called when the ConverterException event should be raised
protected virtual void OnConverterException(ConverterExceptionEventArgs eventArgs)
Parameters
eventArgs
ConverterExceptionEventArgsThe event data
OnUnknownAttribute(UnknownAttributeEventArgs)
Fires the UnknownAttribute event
protected virtual void OnUnknownAttribute(UnknownAttributeEventArgs e)
Parameters
e
UnknownAttributeEventArgsthe event data
OnUnknownElement(UnknownElementEventArgs)
Fires the UnknownElement event
protected virtual void OnUnknownElement(UnknownElementEventArgs e)
Parameters
e
UnknownElementEventArgsthe event data
OnUnknownType(UnknownTypeEventArgs)
Handles the UnknownType event
protected virtual void OnUnknownType(UnknownTypeEventArgs e)
Parameters
e
UnknownTypeEventArgsthe event data
RegisterNamespace(ITypeSerializationInfo, string)
Registers the given type serialization info for a namespace lookup
protected void RegisterNamespace(ITypeSerializationInfo info, string ns)
Parameters
info
ITypeSerializationInfothe type serialization info
ns
stringthe 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
graph
objectThe base element that should be serialized
fragment
boolA 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