Skip to content

Commit

Permalink
use some primary constructors (#1348)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp authored Feb 15, 2024
1 parent 3f0a4ce commit 9b95c05
Show file tree
Hide file tree
Showing 19 changed files with 60 additions and 156 deletions.
37 changes: 11 additions & 26 deletions src/Humanizer.Tests.Shared/EnumUnderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,45 +40,30 @@ public class EnumTestsResources
public static string MemberWithLocalizedDisplayAttribute { get { return "Localized description from Display attribute"; } }
}

public class ImposterDescriptionAttribute : Attribute
public class ImposterDescriptionAttribute(int description) :
Attribute
{
public int Description { get; set; }

public ImposterDescriptionAttribute(int description)
{
Description = description;
}
public int Description { get; set; } = description;
}

public class CustomDescriptionAttribute : Attribute
public class CustomDescriptionAttribute(string description) :
Attribute
{
public string Description { get; set; }

public CustomDescriptionAttribute(string description)
{
Description = description;
}
public string Description { get; set; } = description;
}

public class DescriptionSubclassAttribute : DescriptionAttribute
public class DescriptionSubclassAttribute(string description) :
DescriptionAttribute(description)
{
public DescriptionSubclassAttribute(string description) : base(description)
{
}

public override string Description
{
get { return "Overridden " + base.Description; }
}
}

public class CustomPropertyAttribute : Attribute
public class CustomPropertyAttribute(string info) :
Attribute
{
public string Info { get; set; }

public CustomPropertyAttribute(string info)
{
Info = info;
}
public string Info { get; set; } = info;
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
namespace Humanizer.Localisation.CollectionFormatters
{
internal class OxfordStyleCollectionFormatter : DefaultCollectionFormatter
internal class OxfordStyleCollectionFormatter(string defaultSeparator) :
DefaultCollectionFormatter(defaultSeparator ?? "and")
{
public OxfordStyleCollectionFormatter(string defaultSeparator)
: base(defaultSeparator ?? "and")
{
}

protected override string GetConjunctionFormatString(int itemCount) => itemCount > 2 ? "{0}, {1} {2}" : "{0} {1} {2}";
}
}
}
8 changes: 2 additions & 6 deletions src/Humanizer/Localisation/Formatters/ArabicFormatter.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
namespace Humanizer.Localisation.Formatters
{
internal class ArabicFormatter : DefaultFormatter
internal class ArabicFormatter() :
DefaultFormatter("ar")
{
private const string DualPostfix = "_Dual";
private const string PluralPostfix = "_Plural";

public ArabicFormatter()
: base("ar")
{
}

protected override string GetResourceKey(string resourceKey, int number)
{
//In Arabic pluralization 2 entities gets a different word.
Expand Down
8 changes: 2 additions & 6 deletions src/Humanizer/Localisation/Formatters/CroatianFormatter.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
namespace Humanizer.Localisation.Formatters
{
internal class CroatianFormatter : DefaultFormatter
internal class CroatianFormatter() :
DefaultFormatter("hr")
{
private const string DualTrialQuadralPostfix = "_DualTrialQuadral";

public CroatianFormatter()
: base("hr")
{
}

protected override string GetResourceKey(string resourceKey, int number)
{
if ((number % 10 == 2 || number % 10 == 3 || number % 10 == 4) && number != 12 && number != 13 && number != 14)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
namespace Humanizer.Localisation.Formatters
{
internal class CzechSlovakPolishFormatter : DefaultFormatter
internal class CzechSlovakPolishFormatter(string localeCode) :
DefaultFormatter(localeCode)
{
private const string PaucalPostfix = "_Paucal";

public CzechSlovakPolishFormatter(string localeCode)
: base(localeCode)
{
}

protected override string GetResourceKey(string resourceKey, int number)
{
if (number > 1 && number < 5)
Expand Down
8 changes: 2 additions & 6 deletions src/Humanizer/Localisation/Formatters/FrenchFormatter.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
namespace Humanizer.Localisation.Formatters
{
internal class FrenchFormatter : DefaultFormatter
internal class FrenchFormatter(string localeCode) :
DefaultFormatter(localeCode)
{
private const string DualPostfix = "_Dual";

public FrenchFormatter(string localeCode)
: base(localeCode)
{
}

protected override string GetResourceKey(string resourceKey, int number)
{
if (number == 2 && resourceKey is "DateHumanize_MultipleDaysAgo" or "DateHumanize_MultipleDaysFromNow")
Expand Down
8 changes: 2 additions & 6 deletions src/Humanizer/Localisation/Formatters/GermanFormatter.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
namespace Humanizer.Localisation.Formatters
{
internal class GermanFormatter : DefaultFormatter
internal class GermanFormatter() :
DefaultFormatter("de")
{
public GermanFormatter()
: base("de")
{
}

/// <inheritdoc />
public override string DataUnitHumanize(DataUnit dataUnit, double count, bool toSymbol = true)
{
Expand Down
10 changes: 3 additions & 7 deletions src/Humanizer/Localisation/Formatters/HebrewFormatter.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
namespace Humanizer.Localisation.Formatters
{
internal class HebrewFormatter : DefaultFormatter
internal class HebrewFormatter() :
DefaultFormatter("he")
{
private const string DualPostfix = "_Dual";
private const string PluralPostfix = "_Plural";

public HebrewFormatter()
: base("he")
{
}

protected override string GetResourceKey(string resourceKey, int number)
{
//In Hebrew pluralization 2 entities gets a different word.
Expand All @@ -28,4 +24,4 @@ protected override string GetResourceKey(string resourceKey, int number)
return resourceKey;
}
}
}
}
11 changes: 4 additions & 7 deletions src/Humanizer/Localisation/Formatters/IcelandicFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@

namespace Humanizer.Localisation.Formatters
{
internal class IcelandicFormatter : DefaultFormatter
internal class IcelandicFormatter() :
DefaultFormatter(LocaleCode)
{
private const string LocaleCode = "is";
private readonly CultureInfo _localCulture;
public IcelandicFormatter()
: base(LocaleCode)
{
_localCulture = new CultureInfo(LocaleCode);
}
private readonly CultureInfo _localCulture = new(LocaleCode);

public override string DataUnitHumanize(DataUnit dataUnit, double count, bool toSymbol = true)
{
return base.DataUnitHumanize(dataUnit, count, toSymbol)?.TrimEnd('s');
Expand Down
8 changes: 2 additions & 6 deletions src/Humanizer/Localisation/Formatters/LithuanianFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@

namespace Humanizer.Localisation.Formatters
{
internal class LithuanianFormatter : DefaultFormatter
internal class LithuanianFormatter() :
DefaultFormatter("lt")
{
public LithuanianFormatter()
: base("lt")
{
}

protected override string GetResourceKey(string resourceKey, int number)
{
if (resourceKey == "TimeSpanHumanize_Zero")
Expand Down
11 changes: 3 additions & 8 deletions src/Humanizer/Localisation/Formatters/LuxembourgishFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,16 @@

namespace Humanizer.Localisation.Formatters;

internal class LuxembourgishFormatter : DefaultFormatter
internal class LuxembourgishFormatter() :
DefaultFormatter(LocaleCode)
{
private const string LocaleCode = "lb";
private readonly CultureInfo _localCulture;
private readonly CultureInfo _localCulture = new(LocaleCode);
private const string DualPostfix = "_Dual";
// https://lb.wikipedia.org/wiki/Eifeler_Reegel
private const char EifelerRuleSuffix = 'n';
private const string EifelerRuleCharacters = "unitedzohay";

public LuxembourgishFormatter()
: base(LocaleCode)
{
_localCulture = new CultureInfo(LocaleCode);
}

public override string DataUnitHumanize(DataUnit dataUnit, double count, bool toSymbol = true)
{
return base.DataUnitHumanize(dataUnit, count, toSymbol)?.TrimEnd('s');
Expand Down
8 changes: 2 additions & 6 deletions src/Humanizer/Localisation/Formatters/MalteseFormatter.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace Humanizer.Localisation.Formatters
{
internal class MalteseFormatter : DefaultFormatter
internal class MalteseFormatter(string localeCode) :
DefaultFormatter(localeCode)
{
private const string DualPostfix = "_Dual";

Expand All @@ -12,11 +13,6 @@ internal class MalteseFormatter : DefaultFormatter
"TimeSpanHumanize_MultipleWeeks"
};

public MalteseFormatter(string localeCode)
: base(localeCode)
{
}

protected override string GetResourceKey(string resourceKey, int number)
{
if (number == 2 && DualResourceKeys.Contains(resourceKey))
Expand Down
11 changes: 3 additions & 8 deletions src/Humanizer/Localisation/Formatters/RomanianFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
using System;
using System.Globalization;

internal class RomanianFormatter : DefaultFormatter
internal class RomanianFormatter() :
DefaultFormatter(RomanianCultureCode)
{
private const int PrepositionIndicatingDecimals = 2;
private const int MaxNumeralWithNoPreposition = 19;
Expand All @@ -13,13 +14,7 @@ internal class RomanianFormatter : DefaultFormatter

private static readonly double Divider = Math.Pow(10, PrepositionIndicatingDecimals);

private readonly CultureInfo _romanianCulture;

public RomanianFormatter()
: base(RomanianCultureCode)
{
_romanianCulture = new CultureInfo(RomanianCultureCode);
}
private readonly CultureInfo _romanianCulture = new(RomanianCultureCode);

protected override string Format(string resourceKey, int number, bool toWords = false)
{
Expand Down
10 changes: 3 additions & 7 deletions src/Humanizer/Localisation/Formatters/RussianFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@

namespace Humanizer.Localisation.Formatters
{
internal class RussianFormatter : DefaultFormatter
internal class RussianFormatter() :
DefaultFormatter("ru")
{
public RussianFormatter()
: base("ru")
{
}

protected override string GetResourceKey(string resourceKey, int number)
{
var grammaticalNumber = RussianGrammaticalNumberDetector.Detect(number);
Expand All @@ -31,4 +27,4 @@ private string GetSuffix(RussianGrammaticalNumber grammaticalNumber)
return "";
}
}
}
}
8 changes: 2 additions & 6 deletions src/Humanizer/Localisation/Formatters/SerbianFormatter.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
namespace Humanizer.Localisation.Formatters
{
internal class SerbianFormatter : DefaultFormatter
internal class SerbianFormatter(string localeCode) :
DefaultFormatter(localeCode)
{
private const string PaucalPostfix = "_Paucal";

public SerbianFormatter(string localeCode)
: base(localeCode)
{
}

protected override string GetResourceKey(string resourceKey, int number)
{
var mod10 = number % 10;
Expand Down
8 changes: 2 additions & 6 deletions src/Humanizer/Localisation/Formatters/SlovenianFormatter.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
namespace Humanizer.Localisation.Formatters
{
internal class SlovenianFormatter : DefaultFormatter
internal class SlovenianFormatter() :
DefaultFormatter("sl")
{
private const string DualPostfix = "_Dual";
private const string TrialQuadralPostfix = "_TrialQuadral";

public SlovenianFormatter()
: base("sl")
{
}

protected override string GetResourceKey(string resourceKey, int number)
{
if (number == 2)
Expand Down
9 changes: 2 additions & 7 deletions src/Humanizer/Localisation/Formatters/UkrainianFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@

namespace Humanizer.Localisation.Formatters
{
internal class UkrainianFormatter : DefaultFormatter
internal class UkrainianFormatter() : DefaultFormatter("uk")
{
public UkrainianFormatter()
: base("uk")
{
}

protected override string GetResourceKey(string resourceKey, int number)
{
var grammaticalNumber = RussianGrammaticalNumberDetector.Detect(number);
Expand All @@ -31,4 +26,4 @@ private string GetSuffix(RussianGrammaticalNumber grammaticalNumber)
return "";
}
}
}
}
Loading

0 comments on commit 9b95c05

Please sign in to comment.