Skip to content

[API Proposal]: Add Order property to KnownTypeAttribute #116412

Open
@weitzhandler

Description

@weitzhandler

Background and motivation

In some serialization systems (e.g. protobuf), any member, including those of derived types require a unique order indicator.

It would thus be beneficial to include the Order property in the KnownType attribute as well, so the serializer knows how to order to items of the derived types.

API Proposal

 public sealed class KnownTypeAttribute : Attribute
 {
     public string? MethodName { get; }
     public Type? Type { get; }
+    public int Order { get; set; }
 }

API Usage

[DataContract]
[KnownType(typeof(Dog), Order = 100)]
public class Animal
{
    [DataMember(Order = 1)]
    public string Name { get; set; }
}

[DataContract]
public class Dog
{
    [DataMember(Order = 1)]
    public int TailLength { get; set; }
}

Alternative Designs

No response

Risks

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-suggestionEarly API idea and discussion, it is NOT ready for implementationarea-SerializationuntriagedNew issue has not been triaged by the area owner

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions