Skip to content
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

♻️Allow custom units to set UnitInfo.QuantityName #1420

Merged
merged 1 commit into from
Aug 31, 2024
Merged
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
15 changes: 10 additions & 5 deletions UnitsNet/UnitInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ public class UnitInfo
/// <param name="value">The enum value for this class, for example <see cref="LengthUnit.Meter"/>.</param>
/// <param name="pluralName">The plural name of the unit, such as "Centimeters".</param>
/// <param name="baseUnits">The <see cref="BaseUnits"/> for this unit.</param>
[Obsolete("Use the constructor that also takes a quantityName parameter.")]
public UnitInfo(Enum value, string pluralName, BaseUnits baseUnits)
{
Value = value ?? throw new ArgumentNullException(nameof(value));
Name = value.ToString();
PluralName = pluralName;
PluralName = pluralName ?? throw new ArgumentNullException(nameof(pluralName));
BaseUnits = baseUnits ?? throw new ArgumentNullException(nameof(baseUnits));
}

Expand All @@ -38,10 +39,13 @@ public UnitInfo(Enum value, string pluralName, BaseUnits baseUnits)
/// <param name="pluralName">The plural name of the unit, such as "Centimeters".</param>
/// <param name="baseUnits">The <see cref="BaseUnits"/> for this unit.</param>
/// <param name="quantityName">The quantity name that this unit is for.</param>
internal UnitInfo(Enum value, string pluralName, BaseUnits baseUnits, string quantityName) :
this(value, pluralName, baseUnits)
public UnitInfo(Enum value, string pluralName, BaseUnits baseUnits, string quantityName)
{
QuantityName = quantityName;
Value = value ?? throw new ArgumentNullException(nameof(value));
Name = value.ToString();
PluralName = pluralName ?? throw new ArgumentNullException(nameof(pluralName));
BaseUnits = baseUnits ?? throw new ArgumentNullException(nameof(baseUnits));
QuantityName = quantityName ?? throw new ArgumentNullException(nameof(quantityName));
}

/// <summary>
Expand Down Expand Up @@ -81,14 +85,15 @@ public class UnitInfo<TUnit> : UnitInfo
where TUnit : Enum
{
/// <inheritdoc />
[Obsolete("Use the constructor that also takes a quantityName parameter.")]
public UnitInfo(TUnit value, string pluralName, BaseUnits baseUnits) :
base(value, pluralName, baseUnits)
{
Value = value;
}

/// <inheritdoc />
internal UnitInfo(TUnit value, string pluralName, BaseUnits baseUnits, string quantityName) :
public UnitInfo(TUnit value, string pluralName, BaseUnits baseUnits, string quantityName) :
base(value, pluralName, baseUnits, quantityName)
{
Value = value;
Expand Down