SerializationNodeInfo Class

Represents a node in the serialization graph and provides information about the type, name, and other metadata required during serialization and deserialization.

Syntax

public sealed class SerializationNodeInfo
{
    public SerializationNodeInfo(Type type, string name);
    public string Name { get; }
    public Type Type { get; }
    public bool IsComplex { get; }
    public SerializationNodeInfo[] Children { get; }
    public object GetValue(object obj);
    public void SetValue(object obj, object value);
}

Properties

NameTypeDescription
NamestringThe serialization name of the node.
TypeTypeThe CLR type of the node.
IsComplexboolIndicates whether the node represents a complex type (i.e., not a primitive).
ChildrenSerializationNodeInfo[]Child nodes for complex types.

Methods

SignatureDescription
SerializationNodeInfo(Type type, string name)Initializes a new instance with the specified type and name.
object GetValue(object obj)Gets the value of the node from the supplied object.
void SetValue(object obj, object value)Sets the node's value on the supplied object.

Examples

The following example demonstrates how to inspect a serialization graph using SerializationNodeInfo:

// Example: Inspecting a serialization graph
using System;
using System.Runtime.Serialization;

public class Person
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public int Age { get; set; }
}

class Demo
{
    static void Main()
    {
        var formatter = new NetDataContractSerializer();
        var person = new Person { FirstName = "John", LastName = "Doe", Age = 30 };
        var stream = new System.IO.MemoryStream();
        formatter.Serialize(stream, person);
        stream.Position = 0;

        var context = new StreamingContext(StreamingContextStates.All);
        var nodeInfo = (SerializationNodeInfo)formatter.GetObjectData(person, context);

        PrintNode(nodeInfo, 0);
    }

    static void PrintNode(SerializationNodeInfo node, int indent)
    {
        Console.WriteLine($"{new string(' ', indent * 2)}- {node.Name} : {node.Type.Name}");
        if (node.Children != null)
        {
            foreach (var child in node.Children)
                PrintNode(child, indent + 1);
        }
    }
}

Remarks

Instances of SerializationNodeInfo are typically created by serialization infrastructure and provide a read‑only view of the data contract. Use the GetValue and SetValue methods to manipulate object data during custom serialization scenarios.

See also