Skip to content

Cleaning up some unused code and adding ValueTuple support to make un… #529

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 17, 2018
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@
<PackageReference Include="JetBrains.Annotations">
<Version>11.1.0</Version>
</PackageReference>
<PackageReference Include="System.ValueTuple">
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this dependency add any extra constraints for consumers?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No nuget dependencies listed on these at least. If I understand this nuget correctly, it is a Roslyn package that extends C# language capabilities and should look no different to consumers than ValueTuple<T1,T2,...> so if we used this on a public API consumers can still use Item1, Item2 etc. so I think it should be safe.

https://www.nuget.org/packages/System.ValueTuple/
https://blog.marcgravell.com/2017/04/exploring-tuples-as-library-author.html

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct!

<Version>4.5.0</Version>
</PackageReference>
</ItemGroup>
<ItemGroup />
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
Expand Down
4 changes: 2 additions & 2 deletions UnitsNet/CustomCode/UnitAbbreviationsCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ private void LoadGeneratedAbbreviations()
{
foreach(var localization in GeneratedLocalizations)
{
var culture = new CultureInfo(localization.Item1);
MapUnitToAbbreviation(localization.Item2, localization.Item3, culture, localization.Item4);
var culture = new CultureInfo(localization.CultureName);
MapUnitToAbbreviation(localization.UnitType, localization.UnitValue, culture, localization.UnitAbbreviations);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aw, much better!

}
}

Expand Down
1,990 changes: 993 additions & 997 deletions UnitsNet/GeneratedCode/UnitAbbreviationsCache.g.cs

Large diffs are not rendered by default.

39 changes: 0 additions & 39 deletions UnitsNet/I18n/AbbreviationsForCulture.cs

This file was deleted.

39 changes: 0 additions & 39 deletions UnitsNet/I18n/CulturesForEnumValue.cs

This file was deleted.

40 changes: 0 additions & 40 deletions UnitsNet/I18n/UnitLocalization.cs

This file was deleted.

10 changes: 3 additions & 7 deletions UnitsNet/Scripts/Include-GenerateUnitSystemDefaultSourceCode.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@
// THE SOFTWARE.

using System;
using System.Globalization;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using UnitsNet.I18n;
using UnitsNet.Units;

// ReSharper disable RedundantCommaInArrayInitializer
Expand All @@ -52,8 +48,8 @@ namespace UnitsNet
{
public partial class UnitAbbreviationsCache
{
private static readonly Tuple<string, Type, int, string[]>[] GeneratedLocalizations
= new Tuple<string, Type, int, string[]>[]
private static readonly (string CultureName, Type UnitType, int UnitValue, string[] UnitAbbreviations)[] GeneratedLocalizations
= new []
{
"@;
foreach ($quantity in $quantities)
Expand All @@ -70,7 +66,7 @@ namespace UnitsNet
$cultureName = $localization.Culture;
$abbreviationParams = $localization.Abbreviations -join '", "'
@"
Tuple.Create(`"$cultureName`", typeof($unitEnumName), (int)$unitEnumName.$enumValue, new string[]{`"$abbreviationParams`"}),
(`"$cultureName`", typeof($unitEnumName), (int)$unitEnumName.$enumValue, new string[]{`"$abbreviationParams`"}),
"@;
}
}
Expand Down
1 change: 1 addition & 0 deletions UnitsNet/UnitsNet.Common.props
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<!-- NuGet references that work for both signed and unsigned -->
<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="10.4.0" PrivateAssets="All" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup>

<!-- Exclude obj folder from default inclusion pattern -->
Expand Down