Class ModelSerializer
- Namespace
- NMF.Models.Repository.Serialization
- Assembly
- NMF.Models.dll
Denotes the standard model serializer
public class ModelSerializer : XmiSerializer, IModelSerializer
- Inheritance
-
ModelSerializer
- Implements
- Derived
- Inherited Members
- Extension Methods
Constructors
ModelSerializer()
Creates a new model serializer
public ModelSerializer()
ModelSerializer(XmlSerializationSettings)
Creates a new model serializer
public ModelSerializer(XmlSerializationSettings settings)
Parameters
settings
XmlSerializationSettingsThe serialization settings
ModelSerializer(XmlSerializationSettings, IEnumerable<Type>)
Creates a new serializer and copies settings and known types from the given serializer
public ModelSerializer(XmlSerializationSettings settings, IEnumerable<Type> knownTypes)
Parameters
settings
XmlSerializationSettingsThe serialization settings
knownTypes
IEnumerable<Type>A collection of known types
ModelSerializer(XmlSerializer)
Creates a new serializer and copies settings and known types from the given serializer
public ModelSerializer(XmlSerializer parent)
Parameters
parent
XmlSerializerAn XML serializer to copy settings and known type information from
ModelSerializer(XmlSerializer, XmlSerializationSettings)
Creates a new serializer and copies settings and known types from the given serializer
public ModelSerializer(XmlSerializer parent, XmlSerializationSettings settings)
Parameters
parent
XmlSerializerAn XML serializer to copy settings and known type information from
settings
XmlSerializationSettingsThe serialization settings
Properties
IdAttribute
Gets the attribute used for identifiers
protected override IPropertySerializationInfo IdAttribute { get; }
Property Value
Methods
CreateModelForRoot(object)
Creates the model for the given root element
protected virtual Model CreateModelForRoot(object root)
Parameters
root
objectThe root element
Returns
- Model
The model instance
Exceptions
- InvalidOperationException
Thrown if root is not a model element
CreateSerializationContext(object)
Creates a serialization context for the given root element
protected override XmlSerializationContext CreateSerializationContext(object root)
Parameters
root
objectThe root element of the serialization
Returns
- XmlSerializationContext
A serialization context
Deserialize(Stream, Uri, IModelRepository, bool)
Deserializes the given source into a model
public Model Deserialize(Stream source, Uri modelUri, IModelRepository repository, bool addToRepository)
Parameters
source
Streamthe source stream
modelUri
Urithe URI of the model
repository
IModelRepositorythe repository in the context of which the model is deserialized
addToRepository
booltrue, if the model should be added to the repository, otherwise false
Returns
- Model
the deserialized model
GetAttributeValue(object, ITypeSerializationInfo, bool, XmlSerializationContext)
Gets the serialization of the given attribute value
protected override 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
InitializeElementProperties(XmlReader, ref object, ITypeSerializationInfo, XmlSerializationContext)
Initializes the element properties from the xml reader position
protected override void InitializeElementProperties(XmlReader reader, ref object obj, ITypeSerializationInfo info, XmlSerializationContext context)
Parameters
reader
XmlReaderthe xml reader
obj
objectthe element
info
ITypeSerializationInfothe type serialization information
context
XmlSerializationContextthe serialization context
IsPropertyElement(XmlReader, IPropertySerializationInfo)
Determines whether the element at the current reader position refers to the given property
protected override bool IsPropertyElement(XmlReader reader, IPropertySerializationInfo property)
Parameters
reader
XmlReaderThe reader position
property
IPropertySerializationInfoThe property that should be tested
Returns
- bool
true, if the element is about the property, otherwise false
SelectRoot(object, bool)
Gets the serialization root element
protected override 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
Serialize(Model, Stream)
Serializes the given model to the given target stream
public void Serialize(Model model, Stream target)
Parameters
Serialize(object, XmlWriter, IPropertySerializationInfo, bool, XmlIdentificationMode, XmlSerializationContext)
Serializes the given object
public override void Serialize(object obj, XmlWriter writer, IPropertySerializationInfo property, bool writeInstance, XmlIdentificationMode identificationMode, XmlSerializationContext context)
Parameters
obj
objectThe object to be serialized
writer
XmlWriterThe XmlWriter to write the Xml-code on
property
IPropertySerializationInfoThe property for which the object is serialized
writeInstance
boolA value that indicates whether the serializer should write the element definition
identificationMode
XmlIdentificationModeA value indicating whether it is allowed to the serializer to use identifier
context
XmlSerializationContextThe serialization context
Remarks
If a converter is provided that is able to convert the object to string and convert the string back to this object, just the string-conversion is printed out
SerializeFragment(ModelElement, Stream)
Serialize the given model element as a fragment to the given stream
public void SerializeFragment(ModelElement element, Stream target)
Parameters
element
ModelElementthe model element to serialize
target
Streamthe target stream
WriteElementProperties(XmlWriter, object, ITypeSerializationInfo, XmlSerializationContext)
Writes the element properties of the given object to the provided writer
protected override void WriteElementProperties(XmlWriter writer, object obj, ITypeSerializationInfo info, XmlSerializationContext context)
Parameters
writer
XmlWriterThe xml writer to write to
obj
objectThe element
info
ITypeSerializationInfoThe serialization information of the objects type
context
XmlSerializationContextThe serialization context
WriteIdentifiedObject(XmlWriter, object, XmlIdentificationMode, ITypeSerializationInfo, XmlSerializationContext)
Writes the provided identified object
protected override bool WriteIdentifiedObject(XmlWriter writer, object obj, XmlIdentificationMode identificationMode, ITypeSerializationInfo info, XmlSerializationContext context)
Parameters
writer
XmlWriterThe xml writer to write to
obj
objectThe element
identificationMode
XmlIdentificationModeThe identification mode for the current object
info
ITypeSerializationInfoThe serialization information of the objects type
context
XmlSerializationContextThe serialization context
Returns
- bool
true, if the object could be written as identified object, otherwise false