@@ -94,11 +94,7 @@ public static string GetLocalization(this string culture, Dictionary<string, str
94
94
return defaultValue ;
95
95
}
96
96
var baseCulture = culture . Substring ( 0 , index ) ;
97
- if ( localizations . TryGetValue ( baseCulture , out var baseLocalization ) )
98
- {
99
- return baseLocalization ;
100
- }
101
- return defaultValue ;
97
+ return localizations . GetValueOrDefault ( baseCulture , defaultValue ) ;
102
98
}
103
99
104
100
#endregion
@@ -393,11 +389,11 @@ public static T ObjectValueJson<T>(this string json, string objectKey, T default
393
389
}
394
390
395
391
var dictionary = ConvertJson < Dictionary < string , object > > ( json ) ;
396
- if ( ! dictionary . ContainsKey ( objectKey ) )
392
+ if ( ! dictionary . TryGetValue ( objectKey , out var value ) )
397
393
{
398
394
return defaultValue ;
399
395
}
400
- var value = dictionary [ objectKey ] ;
396
+
401
397
if ( value == null )
402
398
{
403
399
return defaultValue ;
@@ -688,9 +684,9 @@ public static string ToUtcString(this DateTime dateTime) =>
688
684
public static string ToUtcString ( this DateTime dateTime , IFormatProvider provider ) =>
689
685
dateTime . ToUtcTime ( ) . ToString ( "o" , provider ) ;
690
686
691
- /// <summary>Round to hour, if it is the last tick from a hour</summary>
687
+ /// <summary>Round to hour, if it is the last tick from an hour</summary>
692
688
/// <param name="dateTime">The source date time</param>
693
- /// <returns>Date of the next hour if the input is on the last tick on a hour, else the original value</returns>
689
+ /// <returns>Date of the next hour if the input is on the last tick on an hour, else the original value</returns>
694
690
public static DateTime RoundTickToHour ( this DateTime dateTime )
695
691
{
696
692
if ( dateTime >= Date . MaxValue )
@@ -708,7 +704,7 @@ public static DateTime RoundTickToHour(this DateTime dateTime)
708
704
public static DateTime YearStart ( this DateTime yearMoment ) =>
709
705
Date . YearStart ( yearMoment . Year ) ;
710
706
711
- /// <summary>Get the year end date in UTC</summary>
707
+ /// <summary>Get the year- end date in UTC</summary>
712
708
/// <param name="yearMoment">The year moment</param>
713
709
/// <returns>Last moment of the year</returns>
714
710
public static DateTime YearEnd ( this DateTime yearMoment ) =>
@@ -896,14 +892,14 @@ public static DateTime FirstDayOfWeek(int year, int weekOfYear, CultureInfo cult
896
892
return firstWeekDay . AddDays ( weekOfYear * 7 ) ;
897
893
}
898
894
899
- /// <summary>Get week end date by ISO 8601 week number of the year</summary>
895
+ /// <summary>Get weekend date by ISO 8601 week number of the year</summary>
900
896
/// <param name="year">The year</param>
901
897
/// <param name="weekOfYear">The ISO 8601 week number of the year</param>
902
898
/// <returns>Last day of the week</returns>
903
899
public static DateTime LastDayOfWeek ( int year , int weekOfYear ) =>
904
900
LastDayOfWeek ( year , weekOfYear , CultureInfo . CurrentCulture ) ;
905
901
906
- /// <summary>Get week end date by ISO 8601 week number of the year</summary>
902
+ /// <summary>Get weekend date by ISO 8601 week number of the year</summary>
907
903
/// <param name="year">The year</param>
908
904
/// <param name="weekOfYear">The ISO 8601 week number of the year</param>
909
905
/// <param name="culture">The calendar culture</param>
@@ -982,13 +978,13 @@ public static bool IsSameHour(this DateTime date, DateTime compare) =>
982
978
date . IsSameDay ( compare ) && date . Hour == compare . Hour ;
983
979
984
980
/// <summary>Calculates the current age, counting the completed years</summary>
985
- /// <param name="birthDate">The birth date </param>
981
+ /// <param name="birthDate">The birthdate </param>
986
982
/// <returns>The current age</returns>
987
983
public static int Age ( this DateTime birthDate ) =>
988
984
Age ( birthDate , DateTime . UtcNow ) ;
989
985
990
986
/// <summary>Calculates the age at a specific moment, counting the completed years</summary>
991
- /// <param name="birthDate">The birth date </param>
987
+ /// <param name="birthDate">The birthdate </param>
992
988
/// <param name="testMoment">The test moment</param>
993
989
/// <returns>The age at the test moment</returns>
994
990
public static int Age ( this DateTime birthDate , DateTime testMoment )
@@ -1199,11 +1195,11 @@ public static class DictionaryExtensions
1199
1195
/// <returns>The dictionary value</returns>
1200
1196
public static object GetValue ( this Dictionary < string , object > dictionary , string key , object defaultValue = default )
1201
1197
{
1202
- if ( ! dictionary . ContainsKey ( key ) )
1198
+ if ( ! dictionary . TryGetValue ( key , out var value ) )
1203
1199
{
1204
1200
return defaultValue ;
1205
1201
}
1206
- var value = dictionary [ key ] ;
1202
+
1207
1203
if ( value is JsonElement jsonElement )
1208
1204
{
1209
1205
value = jsonElement . GetValue ( ) ;
@@ -1714,7 +1710,7 @@ public static TimeSpan TotalDuration(this IEnumerable<CaseValue> periodValues) =
1714
1710
/// <param name="intersectPeriod">The period to intersect</param>
1715
1711
/// <returns>List of intersecting date periods</returns>
1716
1712
public static List < CaseValue > Intersections ( this IEnumerable < CaseValue > periodValues , DatePeriod intersectPeriod ) =>
1717
- new ( periodValues . Where ( periodValue => periodValue . Period ( ) . IsOverlapping ( intersectPeriod ) ) ) ;
1713
+ [ .. periodValues . Where ( periodValue => periodValue . Period ( ) . IsOverlapping ( intersectPeriod ) ) ] ;
1718
1714
1719
1715
/// <summary>Get case period values matching a period predicate</summary>
1720
1716
/// <param name="periodValues">The time periods to test</param>
@@ -1906,7 +1902,7 @@ public static IEnumerable<TimeSpan> GetDurations(this IEnumerable<PeriodValue> v
1906
1902
1907
1903
/// <summary>Summarize the total duration from all date period durations</summary>
1908
1904
/// <param name="values">The period payroll values</param>
1909
- /// <returns>Total duration from all periods,, an empty time span on empty collection</returns>
1905
+ /// <returns>Total duration from all periods, an empty time span on empty collection</returns>
1910
1906
public static TimeSpan TotalDuration ( this IEnumerable < PeriodValue > values ) =>
1911
1907
// summarize from all durations the time span ticks
1912
1908
values != null ? new ( GetDurations ( values ) . Sum ( ts => ts . Ticks ) ) : TimeSpan . Zero ;
@@ -2061,7 +2057,7 @@ public static List<decimal> Values(this IEnumerable<WageTypeCustomResult> result
2061
2057
2062
2058
/// <summary>Get summary of wage type custom results</summary>
2063
2059
/// <param name="results">The wage type custom results</param>
2064
- /// <returns>Wage type results result values summary</returns>
2060
+ /// <returns>Wage type result values summary</returns>
2065
2061
public static decimal Sum ( this IEnumerable < WageTypeCustomResult > results ) =>
2066
2062
Values ( results ) . Sum ( ) ;
2067
2063
}
@@ -2095,7 +2091,7 @@ valueType is ValueType.Date or
2095
2091
public static bool IsNumber ( this ValueType valueType ) =>
2096
2092
IsInteger ( valueType ) || IsDecimal ( valueType ) ;
2097
2093
2098
- /// <summary>Test if value type is a integer</summary>
2094
+ /// <summary>Test if value type is an integer</summary>
2099
2095
/// <param name="valueType">The value type</param>
2100
2096
/// <returns>True for integer value types</returns>
2101
2097
public static bool IsInteger ( this ValueType valueType ) =>
@@ -2299,21 +2295,24 @@ public static CasePayrollValueDictionary TupleToCaseValuesDictionary(this Dictio
2299
2295
/// <param name="values">The tuple values</param>
2300
2296
/// <returns>The collector results</returns>
2301
2297
public static List < CollectorResult > TupleToCollectorResults ( this List < Tuple < string , Tuple < DateTime , DateTime > , decimal , List < string > , Dictionary < string , object > > > values ) =>
2302
- new ( values . Select ( x => new CollectorResult
2298
+ [
2299
+ ..values . Select ( x => new CollectorResult
2303
2300
{
2304
2301
CollectorName = x . Item1 ,
2305
2302
Start = x . Item2 . Item1 ,
2306
2303
End = x . Item2 . Item2 ,
2307
2304
Value = x . Item3 ,
2308
2305
Tags = x . Item4 ,
2309
2306
Attributes = x . Item5
2310
- } ) ) ;
2307
+ } )
2308
+ ] ;
2311
2309
2312
2310
/// <summary>Convert tuple values to a collector custom result</summary>
2313
2311
/// <param name="values">The tuple values</param>
2314
2312
/// <returns>The collector custom results</returns>
2315
2313
public static List < CollectorCustomResult > TupleToCollectorCustomResults ( this List < Tuple < string , string , Tuple < DateTime , DateTime > , decimal , List < string > , Dictionary < string , object > > > values ) =>
2316
- new ( values . Select ( x => new CollectorCustomResult
2314
+ [
2315
+ ..values . Select ( x => new CollectorCustomResult
2317
2316
{
2318
2317
CollectorName = x . Item1 ,
2319
2318
Source = x . Item2 ,
@@ -2322,13 +2321,15 @@ public static List<CollectorCustomResult> TupleToCollectorCustomResults(this Lis
2322
2321
Value = x . Item4 ,
2323
2322
Tags = x . Item5 ,
2324
2323
Attributes = x . Item6
2325
- } ) ) ;
2324
+ } )
2325
+ ] ;
2326
2326
2327
2327
/// <summary>Convert tuple values to a wage type result</summary>
2328
2328
/// <param name="values">The tuple values</param>
2329
2329
/// <returns>The wage type results</returns>
2330
2330
public static List < WageTypeResult > TupleToWageTypeResults ( this List < Tuple < decimal , string , Tuple < DateTime , DateTime > , decimal , List < string > , Dictionary < string , object > > > values ) =>
2331
- new ( values . Select ( x => new WageTypeResult
2331
+ [
2332
+ ..values . Select ( x => new WageTypeResult
2332
2333
{
2333
2334
WageTypeNumber = x . Item1 ,
2334
2335
WageTypeName = x . Item2 ,
@@ -2337,13 +2338,15 @@ public static List<WageTypeResult> TupleToWageTypeResults(this List<Tuple<decima
2337
2338
Value = x . Item4 ,
2338
2339
Tags = x . Item5 ,
2339
2340
Attributes = x . Item6
2340
- } ) ) ;
2341
+ } )
2342
+ ] ;
2341
2343
2342
2344
/// <summary>Convert tuple values to a wage type custom result</summary>
2343
2345
/// <param name="values">The tuple values</param>
2344
2346
/// <returns>The wage type custom results</returns>
2345
2347
public static List < WageTypeCustomResult > TupleToWageTypeCustomResults ( this List < Tuple < decimal , string , string , Tuple < DateTime , DateTime > , decimal , List < string > , Dictionary < string , object > > > values ) =>
2346
- new ( values . Select ( x => new WageTypeCustomResult
2348
+ [
2349
+ ..values . Select ( x => new WageTypeCustomResult
2347
2350
{
2348
2351
WageTypeNumber = x . Item1 ,
2349
2352
Name = x . Item2 ,
@@ -2353,5 +2356,6 @@ public static List<WageTypeCustomResult> TupleToWageTypeCustomResults(this List<
2353
2356
Value = x . Item5 ,
2354
2357
Tags = x . Item6 ,
2355
2358
Attributes = x . Item7
2356
- } ) ) ;
2359
+ } )
2360
+ ] ;
2357
2361
}
0 commit comments