Skip to content

Commit c0dde6a

Browse files
committed
Annotate JsonNet project with IsAotCompatible
1 parent 7c86c39 commit c0dde6a

File tree

5 files changed

+20
-0
lines changed

5 files changed

+20
-0
lines changed

UnitsNet.Serialization.JsonNet/AbbreviatedUnitsConverter.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ namespace UnitsNet.Serialization.JsonNet
2121
/// </code>
2222
/// </example>
2323
/// <inheritdoc />
24+
#if NET
25+
[RequiresDynamicCode("The native code for this instantiation might not be available at runtime.")]
26+
[RequiresUnreferencedCode("If some of the generic arguments are annotated (either with DynamicallyAccessedMembersAttribute, or generic constraints), trimming can't validate that the requirements of those annotations are met.")]
27+
#endif
2428
public class AbbreviatedUnitsConverter : JsonConverter<IQuantity>
2529
{
2630
private const string ValueProperty = "Value";

UnitsNet.Serialization.JsonNet/UnitsNet.Serialization.JsonNet.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<Nullable>enable</Nullable>
2626
<RootNamespace>UnitsNet.Serialization.JsonNet</RootNamespace>
2727
<TargetFrameworks>netstandard2.0;net8.0;net9.0</TargetFrameworks>
28+
<IsAotCompatible Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net7.0'))">true</IsAotCompatible>
2829
</PropertyGroup>
2930

3031
<!-- Strong name signing -->

UnitsNet.Serialization.JsonNet/UnitsNetBaseJsonConverter.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Collections.Concurrent;
6+
using System.Diagnostics.CodeAnalysis;
67
using System.Globalization;
78
using System.Linq;
89
using Newtonsoft.Json;
@@ -15,6 +16,10 @@ namespace UnitsNet.Serialization.JsonNet
1516
/// Contains shared functionality used by <see cref="UnitsNetIQuantityJsonConverter"/> and <see cref="UnitsNetIComparableJsonConverter"/>
1617
/// </summary>
1718
/// <typeparam name="T">The type being converted. Should either be <see cref="IQuantity"/> or <see cref="IComparable"/></typeparam>
19+
#if NET
20+
[RequiresDynamicCode("The native code for this instantiation might not be available at runtime.")]
21+
[RequiresUnreferencedCode("If some of the generic arguments are annotated (either with DynamicallyAccessedMembersAttribute, or generic constraints), trimming can't validate that the requirements of those annotations are met.")]
22+
#endif
1823
public abstract class UnitsNetBaseJsonConverter<T> : JsonConverter<T>
1924
{
2025
private readonly ConcurrentDictionary<string, (Type Quantity, Type Unit)> _registeredTypes = new();

UnitsNet.Serialization.JsonNet/UnitsNetIComparableJsonConverter.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Copyright 2013 Andreas Gullberg Larsen ([email protected]). Maintained at https://github.com/angularsen/UnitsNet.
33

44
using System;
5+
using System.Diagnostics.CodeAnalysis;
56
using Newtonsoft.Json;
67
using Newtonsoft.Json.Linq;
78

@@ -15,6 +16,10 @@ namespace UnitsNet.Serialization.JsonNet
1516
/// Should only be used when UnitsNet types are assigned to properties of type IComparable.
1617
/// Requires TypeNameHandling on <see cref="JsonSerializerSettings"/> to be set to something other than <see cref="TypeNameHandling.None"/> so that it outputs $type when serializing.
1718
/// </summary>
19+
#if NET
20+
[RequiresDynamicCode("The native code for this instantiation might not be available at runtime.")]
21+
[RequiresUnreferencedCode("If some of the generic arguments are annotated (either with DynamicallyAccessedMembersAttribute, or generic constraints), trimming can't validate that the requirements of those annotations are met.")]
22+
#endif
1823
public sealed class UnitsNetIComparableJsonConverter : UnitsNetBaseJsonConverter<IComparable?>
1924
{
2025
/// <summary>

UnitsNet.Serialization.JsonNet/UnitsNetIQuantityJsonConverter.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Copyright 2013 Andreas Gullberg Larsen ([email protected]). Maintained at https://github.com/angularsen/UnitsNet.
33

44
using System;
5+
using System.Diagnostics.CodeAnalysis;
56
using Newtonsoft.Json;
67
using Newtonsoft.Json.Linq;
78

@@ -12,6 +13,10 @@ namespace UnitsNet.Serialization.JsonNet
1213
/// JSON.net converter for IQuantity types (e.g. all units in UnitsNet)
1314
/// Use this converter to serialize and deserialize UnitsNet types to and from JSON
1415
/// </summary>
16+
#if NET
17+
[RequiresDynamicCode("The native code for this instantiation might not be available at runtime.")]
18+
[RequiresUnreferencedCode("If some of the generic arguments are annotated (either with DynamicallyAccessedMembersAttribute, or generic constraints), trimming can't validate that the requirements of those annotations are met.")]
19+
#endif
1520
public sealed class UnitsNetIQuantityJsonConverter : UnitsNetBaseJsonConverter<IQuantity?>
1621
{
1722
/// <summary>

0 commit comments

Comments
 (0)