/
JsonNumberHandlingAttribute.cs
30 lines (28 loc) · 1.21 KB
/
JsonNumberHandlingAttribute.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
namespace System.Text.Json.Serialization
{
/// <summary>
/// When placed on a type, property, or field, indicates what <see cref="JsonNumberHandling"/>
/// settings should be used when serializing or deserializing numbers.
/// </summary>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)]
public sealed class JsonNumberHandlingAttribute : JsonAttribute
{
/// <summary>
/// Indicates what settings should be used when serializing or deserializing numbers.
/// </summary>
public JsonNumberHandling Handling { get; }
/// <summary>
/// Initializes a new instance of <see cref="JsonNumberHandlingAttribute"/>.
/// </summary>
public JsonNumberHandlingAttribute(JsonNumberHandling handling)
{
if (!JsonSerializer.IsValidNumberHandlingValue(handling))
{
throw new ArgumentOutOfRangeException(nameof(handling));
}
Handling = handling;
}
}
}