Show / Hide Table of Contents

Class SerializationExtensions

Extensions to serialize/deserialize graphs.

Inheritance
System.Object
SerializationExtensions
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: QuikGraph.Serialization
Assembly: QuikGraph.Serialization.dll
Syntax
public static class SerializationExtensions

Methods

| Improve this Doc View Source

DeserializeFromBinary<TVertex, TEdge, TGraph>(Stream, SerializationBinder)

Deserializes a graph instance from a stream that was serialized using the .NET serialization binary formatter.

Declaration
public static TGraph DeserializeFromBinary<TVertex, TEdge, TGraph>(this Stream stream, SerializationBinder binder = null)
    where TEdge : IEdge<TVertex> where TGraph : IGraph<TVertex, TEdge>
Parameters
Type Name Description
System.IO.Stream stream

Stream from which deserializing the graph.

System.Runtime.Serialization.SerializationBinder binder

System.Runtime.Serialization.SerializationBinder used during deserialization. It can be used to check/filter/replace/upgrade types that are loaded.

It is also useful in security scenarios.

By default no binder is used.

Returns
Type Description
TGraph

Deserialized graph.

Type Parameters
Name Description
TVertex

Vertex type.

TEdge

Edge type.

TGraph

Graph type.

Exceptions
Type Condition
System.ArgumentNullException

stream is null.

System.ArgumentException

stream is not readable.

| Improve this Doc View Source

DeserializeFromXml<TVertex, TEdge, TGraph>(XmlReader, Predicate<XmlReader>, Predicate<XmlReader>, Predicate<XmlReader>, Func<XmlReader, TGraph>, Func<XmlReader, TVertex>, Func<XmlReader, TEdge>)

Deserializes a graph instance from a generic XML stream, using an System.Xml.XmlReader.

Declaration
public static TGraph DeserializeFromXml<TVertex, TEdge, TGraph>(this XmlReader reader, Predicate<XmlReader> graphPredicate, Predicate<XmlReader> vertexPredicate, Predicate<XmlReader> edgePredicate, Func<XmlReader, TGraph> graphFactory, Func<XmlReader, TVertex> vertexFactory, Func<XmlReader, TEdge> edgeFactory)
    where TEdge : IEdge<TVertex> where TGraph : class, IMutableVertexAndEdgeSet<TVertex, TEdge>
Parameters
Type Name Description
System.Xml.XmlReader reader

Input XML reader.

System.Predicate<System.Xml.XmlReader> graphPredicate

Predicate that returns a value indicating if the current XML node is a graph. The first match is considered.

System.Predicate<System.Xml.XmlReader> vertexPredicate

Predicate that returns a value indicating if the current XML node is a vertex.

System.Predicate<System.Xml.XmlReader> edgePredicate

Predicate that returns a value indicating if the current XML node is an edge.

System.Func<System.Xml.XmlReader, TGraph> graphFactory

Delegate that instantiates the empty graph instance, given the graph node.

System.Func<System.Xml.XmlReader, TVertex> vertexFactory

Delegate that instantiates a vertex instance, given the vertex node.

System.Func<System.Xml.XmlReader, TEdge> edgeFactory

Delegate that instantiates an edge instance, given the edge node.

Returns
Type Description
TGraph

Deserialized graph.

Type Parameters
Name Description
TVertex

Vertex type.

TEdge

Edge type.

TGraph

Graph type.

Exceptions
Type Condition
System.ArgumentNullException

reader is null.

System.ArgumentNullException

graphPredicate is null.

System.ArgumentNullException

vertexPredicate is null.

System.ArgumentNullException

edgePredicate is null.

System.ArgumentNullException

graphFactory is null.

System.ArgumentNullException

vertexFactory is null or creates null vertex.

System.ArgumentNullException

edgeFactory is null or creates null edge.

System.InvalidOperationException

If the graph node cannot be found.

| Improve this Doc View Source

DeserializeFromXml<TVertex, TEdge, TGraph>(XmlReader, String, String, String, String, Func<XmlReader, TGraph>, Func<XmlReader, TVertex>, Func<XmlReader, TEdge>)

Deserializes a graph from a generic XML stream, using an System.Xml.XmlReader.

Declaration
public static TGraph DeserializeFromXml<TVertex, TEdge, TGraph>(this XmlReader reader, string graphElementName, string vertexElementName, string edgeElementName, string namespaceUri, Func<XmlReader, TGraph> graphFactory, Func<XmlReader, TVertex> vertexFactory, Func<XmlReader, TEdge> edgeFactory)
    where TEdge : IEdge<TVertex> where TGraph : class, IMutableVertexAndEdgeSet<TVertex, TEdge>
Parameters
Type Name Description
System.Xml.XmlReader reader

Input XML reader.

System.String graphElementName

Name of the XML node holding graph information. The first node is considered.

System.String vertexElementName

Name of the XML node holding vertex information.

System.String edgeElementName

Name of the XML node holding edge information.

System.String namespaceUri

XML namespace.

System.Func<System.Xml.XmlReader, TGraph> graphFactory

Delegate that instantiates the empty graph instance, given the graph node.

System.Func<System.Xml.XmlReader, TVertex> vertexFactory

Delegate that instantiates a vertex instance, given the vertex node.

System.Func<System.Xml.XmlReader, TEdge> edgeFactory

Delegate that instantiates an edge instance, given the edge node.

Returns
Type Description
TGraph

Deserialized graph.

Type Parameters
Name Description
TVertex

Vertex type.

TEdge

Edge type.

TGraph

Graph type.

Exceptions
Type Condition
System.ArgumentNullException

reader is null.

System.ArgumentNullException

namespaceUri is null.

System.ArgumentNullException

graphFactory is null.

System.ArgumentNullException

vertexFactory is null or creates null vertex.

System.ArgumentNullException

edgeFactory is null or creates null edge.

System.ArgumentException

graphElementName is null or empty.

System.ArgumentException

vertexElementName is null or empty.

System.ArgumentException

edgeElementName is null or empty.

System.InvalidOperationException

If the graph node cannot be found.

| Improve this Doc View Source

DeserializeFromXml<TVertex, TEdge, TGraph>(IXPathNavigable, String, String, String, Func<XPathNavigator, TGraph>, Func<XPathNavigator, TVertex>, Func<XPathNavigator, TEdge>)

Deserializes a graph instance from a generic XML stream, using an System.Xml.XPath.XPathDocument.

Declaration
public static TGraph DeserializeFromXml<TVertex, TEdge, TGraph>(this IXPathNavigable document, string graphXPath, string vertexXPath, string edgeXPath, Func<XPathNavigator, TGraph> graphFactory, Func<XPathNavigator, TVertex> vertexFactory, Func<XPathNavigator, TEdge> edgeFactory)
    where TEdge : IEdge<TVertex> where TGraph : IMutableVertexAndEdgeSet<TVertex, TEdge>
Parameters
Type Name Description
System.Xml.XPath.IXPathNavigable document

Input XML document.

System.String graphXPath

XPath expression to the graph node. The first node is considered.

System.String vertexXPath

XPath expression from the graph node to the vertex nodes.

System.String edgeXPath

XPath expression from the graph node to the edge nodes.

System.Func<System.Xml.XPath.XPathNavigator, TGraph> graphFactory

Delegate that instantiates the empty graph instance, given the graph node.

System.Func<System.Xml.XPath.XPathNavigator, TVertex> vertexFactory

Delegate that instantiates a vertex instance, given the vertex node.

System.Func<System.Xml.XPath.XPathNavigator, TEdge> edgeFactory

Delegate that instantiates an edge instance, given the edge node.

Returns
Type Description
TGraph

Deserialized graph.

Type Parameters
Name Description
TVertex

Vertex type.

TEdge

Edge type.

TGraph

Graph type.

Exceptions
Type Condition
System.ArgumentNullException

document is null.

System.ArgumentNullException

graphFactory is null.

System.ArgumentNullException

vertexFactory is null or creates null vertex.

System.ArgumentNullException

edgeFactory is null or creates null edge.

System.ArgumentException

graphXPath is null or empty.

System.ArgumentException

vertexXPath is null or empty.

System.ArgumentException

edgeXPath is null or empty.

System.InvalidOperationException

If the document does not allow to get an XML navigator or if the graphXPath does not allow to get graph node.

| Improve this Doc View Source

SerializeToBinary<TVertex, TEdge>(IGraph<TVertex, TEdge>, Stream)

Serializes the graph to the stream using the .NET serialization binary formatter.

Declaration
public static void SerializeToBinary<TVertex, TEdge>(this IGraph<TVertex, TEdge> graph, Stream stream)
    where TEdge : IEdge<TVertex>
Parameters
Type Name Description
IGraph<TVertex, TEdge> graph

The graph to serialize.

System.IO.Stream stream

Stream in which serializing the graph.

Type Parameters
Name Description
TVertex

Vertex type.

TEdge

Edge type.

Exceptions
Type Condition
System.ArgumentNullException

graph is null.

System.ArgumentNullException

stream is null.

System.ArgumentException

stream is not writable.

| Improve this Doc View Source

SerializeToXml<TVertex, TEdge, TGraph>(TGraph, XmlWriter, VertexIdentity<TVertex>, EdgeIdentity<TVertex, TEdge>, String, String, String, String)

Serializes a graph instance to a generic XML stream, using an System.Xml.XmlWriter.

Declaration
public static void SerializeToXml<TVertex, TEdge, TGraph>(this TGraph graph, XmlWriter writer, VertexIdentity<TVertex> vertexIdentity, EdgeIdentity<TVertex, TEdge> edgeIdentity, string graphElementName, string vertexElementName, string edgeElementName, string namespaceUri)
    where TEdge : IEdge<TVertex> where TGraph : IEdgeListGraph<TVertex, TEdge>
Parameters
Type Name Description
TGraph graph

Graph to serialize.

System.Xml.XmlWriter writer

XML writer.

VertexIdentity<TVertex> vertexIdentity

The vertex identity.

EdgeIdentity<TVertex, TEdge> edgeIdentity

The edge identity.

System.String graphElementName

Name of the graph element.

System.String vertexElementName

Name of the vertex element.

System.String edgeElementName

Name of the edge element.

System.String namespaceUri

XML namespace.

Type Parameters
Name Description
TVertex

Vertex type.

TEdge

Edge type.

TGraph

Graph type.

Exceptions
Type Condition
System.ArgumentNullException

graph is null.

System.ArgumentNullException

writer is null.

System.ArgumentNullException

namespaceUri is null.

System.ArgumentNullException

vertexIdentity is null.

System.ArgumentNullException

edgeIdentity is null.

System.ArgumentException

graphElementName is null or empty.

System.ArgumentException

vertexElementName is null or empty.

System.ArgumentException

edgeElementName is null or empty.

| Improve this Doc View Source

SerializeToXml<TVertex, TEdge, TGraph>(TGraph, XmlWriter, VertexIdentity<TVertex>, EdgeIdentity<TVertex, TEdge>, String, String, String, String, Action<XmlWriter, TGraph>, Action<XmlWriter, TVertex>, Action<XmlWriter, TEdge>)

Serializes a graph instance to a generic XML stream, using an System.Xml.XmlWriter.

Declaration
public static void SerializeToXml<TVertex, TEdge, TGraph>(this TGraph graph, XmlWriter writer, VertexIdentity<TVertex> vertexIdentity, EdgeIdentity<TVertex, TEdge> edgeIdentity, string graphElementName, string vertexElementName, string edgeElementName, string namespaceUri, Action<XmlWriter, TGraph> writeGraphAttributes, Action<XmlWriter, TVertex> writeVertexAttributes, Action<XmlWriter, TEdge> writeEdgeAttributes)
    where TEdge : IEdge<TVertex> where TGraph : IEdgeListGraph<TVertex, TEdge>
Parameters
Type Name Description
TGraph graph

Graph to serialize.

System.Xml.XmlWriter writer

XML writer.

VertexIdentity<TVertex> vertexIdentity

The vertex identity.

EdgeIdentity<TVertex, TEdge> edgeIdentity

The edge identity.

System.String graphElementName

Name of the graph element.

System.String vertexElementName

Name of the vertex element.

System.String edgeElementName

Name of the edge element.

System.String namespaceUri

XMl namespace.

System.Action<System.Xml.XmlWriter, TGraph> writeGraphAttributes

Delegate to write graph attributes (optional).

System.Action<System.Xml.XmlWriter, TVertex> writeVertexAttributes

Delegate to write vertex attributes (optional).

System.Action<System.Xml.XmlWriter, TEdge> writeEdgeAttributes

Delegate to write edge attributes (optional).

Type Parameters
Name Description
TVertex

Vertex type.

TEdge

Edge type.

TGraph

Graph type.

Exceptions
Type Condition
System.ArgumentNullException

graph is null.

System.ArgumentNullException

writer is null.

System.ArgumentNullException

namespaceUri is null.

System.ArgumentNullException

vertexIdentity is null.

System.ArgumentNullException

edgeIdentity is null.

System.ArgumentException

graphElementName is null or empty.

System.ArgumentException

vertexElementName is null or empty.

System.ArgumentException

edgeElementName is null or empty.

  • Improve this Doc
  • View Source
In This Article
Back to top QuikGraph