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
settingsXmlSerializationSettingsThe 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
settingsXmlSerializationSettingsThe serialization settings
knownTypesIEnumerable<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
parentXmlSerializerAn 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
parentXmlSerializerAn XML serializer to copy settings and known type information from
settingsXmlSerializationSettingsThe 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
rootobjectThe 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
rootobjectThe 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
sourceStreamthe source stream
modelUriUrithe URI of the model
repositoryIModelRepositorythe repository in the context of which the model is deserialized
addToRepositorybooltrue, 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
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
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
readerXmlReaderthe xml reader
objobjectthe element
infoITypeSerializationInfothe type serialization information
contextXmlSerializationContextthe 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
readerXmlReaderThe reader position
propertyIPropertySerializationInfoThe 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
graphobjectThe base element that should be serialized
fragmentboolA 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
objobjectThe object to be serialized
writerXmlWriterThe XmlWriter to write the Xml-code on
propertyIPropertySerializationInfoThe property for which the object is serialized
writeInstanceboolA value that indicates whether the serializer should write the element definition
identificationModeXmlIdentificationModeA value indicating whether it is allowed to the serializer to use identifier
contextXmlSerializationContextThe 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
elementModelElementthe model element to serialize
targetStreamthe 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
writerXmlWriterThe xml writer to write to
objobjectThe element
infoITypeSerializationInfoThe serialization information of the objects type
contextXmlSerializationContextThe 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
writerXmlWriterThe xml writer to write to
objobjectThe element
identificationModeXmlIdentificationModeThe identification mode for the current object
infoITypeSerializationInfoThe serialization information of the objects type
contextXmlSerializationContextThe serialization context
Returns
- bool
true, if the object could be written as identified object, otherwise false