Class KnownSubTypeAttribute<TSubType, TShapeProvider>
- 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<TSubType, TShapeProvider> : KnownSubTypeAttribute where TShapeProvider : IShapeable<TSubType>
Type Parameters
TSubType
A class derived from the one to which this attribute is affixed.
TShapeProvider
The class that serves as the shape provider for
TSubType
.
- Inheritance
-
KnownSubTypeAttribute<TSubType, TShapeProvider>
- 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()
Initializes a new instance of the KnownSubTypeAttribute<TSubType, TShapeProvider> class
that uses the FullName of the TSubType
as the alias.
public KnownSubTypeAttribute()
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(int)
Initializes a new instance of the KnownSubTypeAttribute<TSubType, TShapeProvider> class.
public KnownSubTypeAttribute(int alias)
Parameters
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(string)
Initializes a new instance of the KnownSubTypeAttribute<TSubType, TShapeProvider> class.
public KnownSubTypeAttribute(string alias)
Parameters
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 override ITypeShape? Shape { get; }