Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CodeGen/Generators/UnitsNetGen/QuantityGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public string Generate()
using System.Globalization;
using System.Linq;
using System.Runtime.Serialization;
using UnitsNet.InternalHelpers;
using UnitsNet.Units;
#if NET
using System.Numerics;
Expand Down Expand Up @@ -156,7 +157,7 @@ private void GenerateStaticConstructor()

Writer.WL($@"
BaseUnit = {_unitEnumName}.{_quantity.BaseUnit};
Units = Enum.GetValues(typeof({_unitEnumName})).Cast<{_unitEnumName}>().ToArray();
Units = EnumHelpers.GetValues<{_unitEnumName}>();
Zero = new {_quantity.Name}(0, BaseUnit);
Info = new QuantityInfo<{_unitEnumName}>(""{_quantity.Name}"",
new UnitInfo<{_unitEnumName}>[]
Expand Down
8 changes: 8 additions & 0 deletions CodeGen/Generators/UnitsNetGen/StaticQuantityGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@ internal static IEnumerable<Type> GetQuantityTypes()
yield return typeof({quantity.Name});");
Writer.WL(@"
}

internal static void RegisterDefaultConversions(UnitConverter unitConverter)
{");
foreach (var quantity in _quantities)
Writer.WL($@"
{quantity.Name}.RegisterDefaultConversions(unitConverter);");
Writer.WL(@"
}
}
}");
return Writer.ToString();
Expand Down
3 changes: 2 additions & 1 deletion CodeGen/Generators/UnitsNetGen/UnitTestBaseClassGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ public string Generate()
using UnitsNet.Tests.Helpers;
using UnitsNet.Tests.TestsBase;
using UnitsNet.Units;
using UnitsNet.InternalHelpers;
using Xunit;

// Disable build warning CS1718: Comparison made to same variable; did you mean to compare something else?
Expand Down Expand Up @@ -1011,7 +1012,7 @@ public void EqualsReturnsFalseOnNull()
[Fact]
public void HasAtLeastOneAbbreviationSpecified()
{{
var units = Enum.GetValues(typeof({_unitEnumName})).Cast<{_unitEnumName}>();
var units = EnumHelpers.GetValues<{_unitEnumName}>();
foreach (var unit in units)
{{
var defaultAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit);
Expand Down
1 change: 1 addition & 0 deletions UnitsNet.NumberExtensions/UnitsNet.NumberExtensions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<Nullable>enable</Nullable>
<RootNamespace>UnitsNet</RootNamespace>
<TargetFrameworks>netstandard2.0;net8.0;net9.0</TargetFrameworks>
<IsAotCompatible Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net7.0'))">true</IsAotCompatible>
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 4 additions & 0 deletions UnitsNet.Serialization.JsonNet/AbbreviatedUnitsConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ namespace UnitsNet.Serialization.JsonNet
/// </code>
/// </example>
/// <inheritdoc />
#if NET
[RequiresDynamicCode("The native code for this instantiation might not be available at runtime.")]
[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.")]
#endif
public class AbbreviatedUnitsConverter : JsonConverter<IQuantity>
{
private const string ValueProperty = "Value";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<Nullable>enable</Nullable>
<RootNamespace>UnitsNet.Serialization.JsonNet</RootNamespace>
<TargetFrameworks>netstandard2.0;net8.0;net9.0</TargetFrameworks>
<IsAotCompatible Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net7.0'))">true</IsAotCompatible>
</PropertyGroup>

<!-- Strong name signing -->
Expand Down
5 changes: 5 additions & 0 deletions UnitsNet.Serialization.JsonNet/UnitsNetBaseJsonConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Concurrent;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
using Newtonsoft.Json;
Expand All @@ -15,6 +16,10 @@ namespace UnitsNet.Serialization.JsonNet
/// Contains shared functionality used by <see cref="UnitsNetIQuantityJsonConverter"/> and <see cref="UnitsNetIComparableJsonConverter"/>
/// </summary>
/// <typeparam name="T">The type being converted. Should either be <see cref="IQuantity"/> or <see cref="IComparable"/></typeparam>
#if NET
[RequiresDynamicCode("The native code for this instantiation might not be available at runtime.")]
[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.")]
#endif
public abstract class UnitsNetBaseJsonConverter<T> : JsonConverter<T>
{
private readonly ConcurrentDictionary<string, (Type Quantity, Type Unit)> _registeredTypes = new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet.

using System;
using System.Diagnostics.CodeAnalysis;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

Expand All @@ -15,6 +16,10 @@ namespace UnitsNet.Serialization.JsonNet
/// Should only be used when UnitsNet types are assigned to properties of type IComparable.
/// Requires TypeNameHandling on <see cref="JsonSerializerSettings"/> to be set to something other than <see cref="TypeNameHandling.None"/> so that it outputs $type when serializing.
/// </summary>
#if NET
[RequiresDynamicCode("The native code for this instantiation might not be available at runtime.")]
[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.")]
#endif
public sealed class UnitsNetIComparableJsonConverter : UnitsNetBaseJsonConverter<IComparable?>
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet.

using System;
using System.Diagnostics.CodeAnalysis;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

Expand All @@ -12,6 +13,10 @@ namespace UnitsNet.Serialization.JsonNet
/// JSON.net converter for IQuantity types (e.g. all units in UnitsNet)
/// Use this converter to serialize and deserialize UnitsNet types to and from JSON
/// </summary>
#if NET
[RequiresDynamicCode("The native code for this instantiation might not be available at runtime.")]
[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.")]
#endif
public sealed class UnitsNetIQuantityJsonConverter : UnitsNetBaseJsonConverter<IQuantity?>
{
/// <summary>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion UnitsNet.Tests/GeneratedCode/TestsBase/AngleTestsBase.g.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion UnitsNet.Tests/GeneratedCode/TestsBase/AreaTestsBase.g.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion UnitsNet.Tests/GeneratedCode/TestsBase/BitRateTestsBase.g.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion UnitsNet.Tests/GeneratedCode/TestsBase/DensityTestsBase.g.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading