Table of Contents

Class KnownSubTypeAttribute

Namespace
Nerdbank.MessagePack
Assembly
Nerdbank.MessagePack.dll

Specifies that where the class to which this attribute is applied is the declared type in an object graph that certain derived types are recorded in the serialized data as well and allowed to be deserialized back as their derived types.

[AttributeUsage(AttributeTargets.Class|AttributeTargets.Interface, Inherited = false, AllowMultiple = true)]
public class KnownSubTypeAttribute : Attribute
Inheritance
KnownSubTypeAttribute
Derived
Inherited Members

Remarks

A type with one or more of these attributes applied serializes to a different schema than the same type without any attributes applied. The serialized data will include a special header that indicates the runtime type. Consider version compatibility issues when adding the first or removing the last attribute from a type.

Each type referenced by this attribute must have GenerateShapeAttribute applied to it or a witness class.

Constructors

KnownSubTypeAttribute(Type)

Initializes a new instance of the KnownSubTypeAttribute class that uses the FullName of the subType as the alias.

[Obsolete("Use the generic version of this attribute instead.")]
public KnownSubTypeAttribute(Type subType)

Parameters

subType Type
The derived-type that the alias represents.

Remarks

Consider cross-platform compatibility when using this constructor, particularly when the serialized form may be exchanged with non-.NET programs where the FullName has no meaning.

KnownSubTypeAttribute(Type, int)

Initializes a new instance of the KnownSubTypeAttribute class.

[Obsolete("Use the generic version of this attribute instead.")]
public KnownSubTypeAttribute(Type subType, int alias)

Parameters

subType Type

The derived-type that the alias represents.

alias int

A value that identifies the subtype in the serialized data. Must be unique among all the attributes applied to the same class.

KnownSubTypeAttribute(Type, string)

Initializes a new instance of the KnownSubTypeAttribute class.

[Obsolete("Use the generic version of this attribute instead.")]
public KnownSubTypeAttribute(Type subType, string alias)

Parameters

subType Type

The derived-type that the alias represents.

alias string

A value that identifies the subtype in the serialized data. Must be unique among all the attributes applied to the same class.

Properties

Shape

Gets the shape that describes the subtype.

public virtual ITypeShape? Shape { get; }

Property Value

ITypeShape

SubType

Gets the sub-type.

public Type SubType { get; }

Property Value

Type