Table of Contents

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 XmlSerializationSettings

The 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 XmlSerializationSettings

The 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 XmlSerializer

An 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 XmlSerializer

An XML serializer to copy settings and known type information from

settings XmlSerializationSettings

The serialization settings

Properties

IdAttribute

Gets the attribute used for identifiers

protected override IPropertySerializationInfo IdAttribute { get; }

Property Value

IPropertySerializationInfo

Methods

CreateModelForRoot(object)

Creates the model for the given root element

protected virtual Model CreateModelForRoot(object root)

Parameters

root object

The 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 object

The 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 Stream

the source stream

modelUri Uri

the URI of the model

repository IModelRepository

the repository in the context of which the model is deserialized

addToRepository bool

true, 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 object

The value of the attribute

info ITypeSerializationInfo

The serialization information of the type

isCollection bool

True, if the value is added to a collection, otherwise false

context XmlSerializationContext

The 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 XmlReader

the xml reader

obj object

the element

info ITypeSerializationInfo

the type serialization information

context XmlSerializationContext

the 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 XmlReader

The reader position

property IPropertySerializationInfo

The 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 object

The base element that should be serialized

fragment bool

A 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

model Model

the model to serialize

target Stream

the target stream

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 object

The object to be serialized

writer XmlWriter

The XmlWriter to write the Xml-code on

property IPropertySerializationInfo

The property for which the object is serialized

writeInstance bool

A value that indicates whether the serializer should write the element definition

identificationMode XmlIdentificationMode

A value indicating whether it is allowed to the serializer to use identifier

context XmlSerializationContext

The 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 ModelElement

the model element to serialize

target Stream

the 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 XmlWriter

The xml writer to write to

obj object

The element

info ITypeSerializationInfo

The serialization information of the objects type

context XmlSerializationContext

The 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 XmlWriter

The xml writer to write to

obj object

The element

identificationMode XmlIdentificationMode

The identification mode for the current object

info ITypeSerializationInfo

The serialization information of the objects type

context XmlSerializationContext

The serialization context

Returns

bool

true, if the object could be written as identified object, otherwise false