Skip to content

Commit ece337d

Browse files
committed
merging the AoT compatibility: angularsen@6abb5f4
2 parents eb22805 + 6abb5f4 commit ece337d

14 files changed

Lines changed: 94 additions & 4 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net9.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
<RootNamespace>perftest</RootNamespace>
9+
10+
<PublishAot>true</PublishAot>
11+
</PropertyGroup>
12+
13+
<ItemGroup>
14+
<ProjectReference Include="..\..\UnitsNet\UnitsNet.csproj" />
15+
</ItemGroup>
16+
17+
</Project>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
using UnitsNet;
2+
using UnitsNet.Units;
3+
4+
Console.WriteLine(Power.From(5, PowerUnit.Watt));
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
# shellcheck disable=SC2155
3+
declare -r dirname=$(dirname -- "$0")
4+
5+
pushd "$dirname" || exit
6+
dotnet publish
7+
dotnet timeit "$dirname/timeit.json"
8+
popd || exit
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"warmUpCount": 10,
3+
"count": 20,
4+
"scenarios": [{ "name": "Default" }],
5+
"processName": "../../Artifacts/PerfTest_Startup_Aot/net9.0/win-x64/publish/PerfTest_Startup_Aot.exe",
6+
"workingDirectory": "$(CWD)/",
7+
"processTimeout": 15
8+
}

UnitsNet.NumberExtensions/UnitsNet.NumberExtensions.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
<ImplicitUsings>enable</ImplicitUsings>
2929
<RootNamespace>UnitsNet</RootNamespace>
3030
<TargetFrameworks>netstandard2.0;net8.0;net9.0</TargetFrameworks>
31+
<IsAotCompatible Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net7.0'))">true</IsAotCompatible>
3132
</PropertyGroup>
3233

3334
<ItemGroup>

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

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

3334
<!-- 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.Linq;
78
using Newtonsoft.Json;
89
using Newtonsoft.Json.Linq;
@@ -14,6 +15,10 @@ namespace UnitsNet.Serialization.JsonNet
1415
/// Contains shared functionality used by <see cref="UnitsNetIQuantityJsonConverter"/> and <see cref="UnitsNetIComparableJsonConverter"/>
1516
/// </summary>
1617
/// <typeparam name="T">The type being converted. Should either be <see cref="IQuantity"/> or <see cref="IComparable"/></typeparam>
18+
#if NET
19+
[RequiresDynamicCode("The native code for this instantiation might not be available at runtime.")]
20+
[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.")]
21+
#endif
1722
public abstract class UnitsNetBaseJsonConverter<T> : NullableQuantityConverter<T>
1823
{
1924
private readonly ConcurrentDictionary<string, (Type Quantity, Type Unit)> _registeredTypes = new();

UnitsNet.Serialization.JsonNet/UnitsNetIComparableJsonConverter.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). 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,7 +16,11 @@ 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>
18-
public sealed class UnitsNetIComparableJsonConverter : UnitsNetBaseJsonConverter<IComparable>
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
23+
public sealed class UnitsNetIComparableJsonConverter : UnitsNetBaseJsonConverter<IComparable?>
1924
{
2025
/// <summary>
2126
/// Indicates if this JsonConverter is capable of writing JSON

UnitsNet.Serialization.JsonNet/UnitsNetIQuantityJsonConverter.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). 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,7 +13,11 @@ 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>
15-
public sealed class UnitsNetIQuantityJsonConverter : UnitsNetBaseJsonConverter<IQuantity>
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
20+
public sealed class UnitsNetIQuantityJsonConverter : UnitsNetBaseJsonConverter<IQuantity?>
1621
{
1722
/// <summary>
1823
/// Writes the JSON representation of the object.

UnitsNet.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "PerfTests", "PerfTests", "{
7070
EndProject
7171
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PerfTest_Startup_v4_72_0", "PerfTests\PerfTest_Startup_v4_72_0\PerfTest_Startup_v4_72_0.csproj", "{7131F7CC-BD7F-44EB-AD50-AE80CE38F28E}"
7272
EndProject
73+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PerfTest_Startup_Aot", "PerfTests\PerfTest_Startup_Aot\PerfTest_Startup_Aot.csproj", "{0222DB9C-52B5-4766-A068-617A44B7E3EB}"
74+
EndProject
7375
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitsNet.Serialization.SystemTextJson", "UnitsNet.Serialization.SystemTextJson\UnitsNet.Serialization.SystemTextJson.csproj", "{712419E5-5EAF-9B97-AEAB-CE449D2EAA29}"
7476
EndProject
7577
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitsNet.Serialization.SystemTextJson.Tests", "UnitsNet.Serialization.SystemTextJson.Tests\UnitsNet.Serialization.SystemTextJson.Tests.csproj", "{EF75262E-DE78-005C-0867-2B4D647A141A}"
@@ -124,6 +126,10 @@ Global
124126
{7131F7CC-BD7F-44EB-AD50-AE80CE38F28E}.Debug|Any CPU.Build.0 = Debug|Any CPU
125127
{7131F7CC-BD7F-44EB-AD50-AE80CE38F28E}.Release|Any CPU.ActiveCfg = Release|Any CPU
126128
{7131F7CC-BD7F-44EB-AD50-AE80CE38F28E}.Release|Any CPU.Build.0 = Release|Any CPU
129+
{0222DB9C-52B5-4766-A068-617A44B7E3EB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
130+
{0222DB9C-52B5-4766-A068-617A44B7E3EB}.Debug|Any CPU.Build.0 = Debug|Any CPU
131+
{0222DB9C-52B5-4766-A068-617A44B7E3EB}.Release|Any CPU.ActiveCfg = Release|Any CPU
132+
{0222DB9C-52B5-4766-A068-617A44B7E3EB}.Release|Any CPU.Build.0 = Release|Any CPU
127133
{712419E5-5EAF-9B97-AEAB-CE449D2EAA29}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
128134
{712419E5-5EAF-9B97-AEAB-CE449D2EAA29}.Debug|Any CPU.Build.0 = Debug|Any CPU
129135
{712419E5-5EAF-9B97-AEAB-CE449D2EAA29}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -141,6 +147,7 @@ Global
141147
{BFF3DD22-0F58-4E79-86CD-662D1A174224} = {126F0393-A678-4609-9341-7028F1B2BC2B}
142148
{2E68C361-F6FA-49DC-BB0E-85ADE776391E} = {126F0393-A678-4609-9341-7028F1B2BC2B}
143149
{7131F7CC-BD7F-44EB-AD50-AE80CE38F28E} = {126F0393-A678-4609-9341-7028F1B2BC2B}
150+
{0222DB9C-52B5-4766-A068-617A44B7E3EB} = {126F0393-A678-4609-9341-7028F1B2BC2B}
144151
EndGlobalSection
145152
GlobalSection(ExtensibilityGlobals) = postSolution
146153
SolutionGuid = {554906B2-5972-4EBF-9DD5-EEFA77D735D8}

0 commit comments

Comments
 (0)