| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | namespace System.Text.Json.Serialization |
| | | 5 | | { |
| | | 6 | | /// <summary> |
| | | 7 | | /// When placed on a type declaration, indicates that the specified subtype should be opted into polymorphic seriali |
| | | 8 | | /// </summary> |
| | | 9 | | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface, AllowMultiple = true, Inherited = false)] |
| | | 10 | | public class JsonDerivedTypeAttribute : JsonAttribute |
| | | 11 | | { |
| | | 12 | | /// <summary> |
| | | 13 | | /// Initializes a new attribute with specified parameters. |
| | | 14 | | /// </summary> |
| | | 15 | | /// <param name="derivedType">A derived type that should be supported in polymorphic serialization of the declar |
| | 0 | 16 | | public JsonDerivedTypeAttribute(Type derivedType) |
| | 0 | 17 | | { |
| | 0 | 18 | | DerivedType = derivedType; |
| | 0 | 19 | | } |
| | | 20 | | |
| | | 21 | | /// <summary> |
| | | 22 | | /// Initializes a new attribute with specified parameters. |
| | | 23 | | /// </summary> |
| | | 24 | | /// <param name="derivedType">A derived type that should be supported in polymorphic serialization of the declar |
| | | 25 | | /// <param name="typeDiscriminator">The type discriminator identifier to be used for the serialization of the su |
| | 0 | 26 | | public JsonDerivedTypeAttribute(Type derivedType, string typeDiscriminator) |
| | 0 | 27 | | { |
| | 0 | 28 | | DerivedType = derivedType; |
| | 0 | 29 | | TypeDiscriminator = typeDiscriminator; |
| | 0 | 30 | | } |
| | | 31 | | |
| | | 32 | | /// <summary> |
| | | 33 | | /// Initializes a new attribute with specified parameters. |
| | | 34 | | /// </summary> |
| | | 35 | | /// <param name="derivedType">A derived type that should be supported in polymorphic serialization of the declar |
| | | 36 | | /// <param name="typeDiscriminator">The type discriminator identifier to be used for the serialization of the su |
| | 0 | 37 | | public JsonDerivedTypeAttribute(Type derivedType, int typeDiscriminator) |
| | 0 | 38 | | { |
| | 0 | 39 | | DerivedType = derivedType; |
| | 0 | 40 | | TypeDiscriminator = typeDiscriminator; |
| | 0 | 41 | | } |
| | | 42 | | |
| | | 43 | | /// <summary> |
| | | 44 | | /// A derived type that should be supported in polymorphic serialization of the declared base type. |
| | | 45 | | /// </summary> |
| | 0 | 46 | | public Type DerivedType { get; } |
| | | 47 | | |
| | | 48 | | /// <summary> |
| | | 49 | | /// The type discriminator identifier to be used for the serialization of the subtype. |
| | | 50 | | /// </summary> |
| | 0 | 51 | | public object? TypeDiscriminator { get; } |
| | | 52 | | } |
| | | 53 | | } |