다음을 통해 공유


IStateSerializer<T> Interface

Definition

Represents a custom serializer for type T.

public interface IStateSerializer<T>
type IStateSerializer<'T> = interface
Public Interface IStateSerializer(Of T)

Type Parameters

T

Type to serialize and deserialize.

Examples

In this example, implementation of the Read and Write overloads simply call their counterpart overloads. The currentValue and baseValue parameters are not set by the platform and should be ignored.

class Order
{
    public byte Warehouse { get; set; }
    public short District { get; set; }
    public int Customer { get; set; }
    public long OrderNumber { get; set; }
}

class OrderSerializer : IStateSerializer<Order>
{
    void Write(Order value, BinaryWriter writer)
    {
        writer.Write(value.Warehouse);
        writer.Write(value.District);
        writer.Write(value.Customer);
        writer.Write(value.OrderNumber);
    }

    Order Read(BinaryReader reader)
    {
        Order value = new Order();

        value.Warehouse = reader.ReadByte();
        value.District = reader.ReadInt16();
        value.Customer = reader.ReadInt32();
        value.OrderNumber = reader.ReadInt64();

        return value;
    }

    void Write(Order currentValue, Order newValue, BinaryWriter writer)
    {
        this.Write(newValue, writer);
    }

    Order Read(Order baseValue, BinaryReader reader)
    {
        return this.Read(reader);
    }
}

Remarks

Use TryAddStateSerializer<T>(IStateSerializer<T>) to register a custom serializer.

Methods

Read(BinaryReader)

Deserializes from the given BinaryReader to T.

Read(T, BinaryReader)

Deserializes from the given BinaryReader to T.

Write(T, BinaryWriter)

Serializes a value and writes it to the given BinaryWriter.

Write(T, T, BinaryWriter)

Serializes an object and writes it to the given BinaryWriter.

Applies to