@@ -94,11 +94,7 @@ public static string GetLocalization(this string culture, Dictionary<string, str
9494 return defaultValue ;
9595 }
9696 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 ) ;
10298 }
10399
104100 #endregion
@@ -393,11 +389,11 @@ public static T ObjectValueJson<T>(this string json, string objectKey, T default
393389 }
394390
395391 var dictionary = ConvertJson < Dictionary < string , object > > ( json ) ;
396- if ( ! dictionary . ContainsKey ( objectKey ) )
392+ if ( ! dictionary . TryGetValue ( objectKey , out var value ) )
397393 {
398394 return defaultValue ;
399395 }
400- var value = dictionary [ objectKey ] ;
396+
401397 if ( value == null )
402398 {
403399 return defaultValue ;
@@ -688,9 +684,9 @@ public static string ToUtcString(this DateTime dateTime) =>
688684 public static string ToUtcString ( this DateTime dateTime , IFormatProvider provider ) =>
689685 dateTime . ToUtcTime ( ) . ToString ( "o" , provider ) ;
690686
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>
692688 /// <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>
694690 public static DateTime RoundTickToHour ( this DateTime dateTime )
695691 {
696692 if ( dateTime >= Date . MaxValue )
@@ -708,7 +704,7 @@ public static DateTime RoundTickToHour(this DateTime dateTime)
708704 public static DateTime YearStart ( this DateTime yearMoment ) =>
709705 Date . YearStart ( yearMoment . Year ) ;
710706
711- /// <summary>Get the year end date in UTC</summary>
707+ /// <summary>Get the year- end date in UTC</summary>
712708 /// <param name="yearMoment">The year moment</param>
713709 /// <returns>Last moment of the year</returns>
714710 public static DateTime YearEnd ( this DateTime yearMoment ) =>
@@ -896,14 +892,14 @@ public static DateTime FirstDayOfWeek(int year, int weekOfYear, CultureInfo cult
896892 return firstWeekDay . AddDays ( weekOfYear * 7 ) ;
897893 }
898894
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>
900896 /// <param name="year">The year</param>
901897 /// <param name="weekOfYear">The ISO 8601 week number of the year</param>
902898 /// <returns>Last day of the week</returns>
903899 public static DateTime LastDayOfWeek ( int year , int weekOfYear ) =>
904900 LastDayOfWeek ( year , weekOfYear , CultureInfo . CurrentCulture ) ;
905901
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>
907903 /// <param name="year">The year</param>
908904 /// <param name="weekOfYear">The ISO 8601 week number of the year</param>
909905 /// <param name="culture">The calendar culture</param>
@@ -982,13 +978,13 @@ public static bool IsSameHour(this DateTime date, DateTime compare) =>
982978 date . IsSameDay ( compare ) && date . Hour == compare . Hour ;
983979
984980 /// <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>
986982 /// <returns>The current age</returns>
987983 public static int Age ( this DateTime birthDate ) =>
988984 Age ( birthDate , DateTime . UtcNow ) ;
989985
990986 /// <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>
992988 /// <param name="testMoment">The test moment</param>
993989 /// <returns>The age at the test moment</returns>
994990 public static int Age ( this DateTime birthDate , DateTime testMoment )
@@ -1199,11 +1195,11 @@ public static class DictionaryExtensions
11991195 /// <returns>The dictionary value</returns>
12001196 public static object GetValue ( this Dictionary < string , object > dictionary , string key , object defaultValue = default )
12011197 {
1202- if ( ! dictionary . ContainsKey ( key ) )
1198+ if ( ! dictionary . TryGetValue ( key , out var value ) )
12031199 {
12041200 return defaultValue ;
12051201 }
1206- var value = dictionary [ key ] ;
1202+
12071203 if ( value is JsonElement jsonElement )
12081204 {
12091205 value = jsonElement . GetValue ( ) ;
@@ -1714,7 +1710,7 @@ public static TimeSpan TotalDuration(this IEnumerable<CaseValue> periodValues) =
17141710 /// <param name="intersectPeriod">The period to intersect</param>
17151711 /// <returns>List of intersecting date periods</returns>
17161712 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 ) ) ] ;
17181714
17191715 /// <summary>Get case period values matching a period predicate</summary>
17201716 /// <param name="periodValues">The time periods to test</param>
@@ -1906,7 +1902,7 @@ public static IEnumerable<TimeSpan> GetDurations(this IEnumerable<PeriodValue> v
19061902
19071903 /// <summary>Summarize the total duration from all date period durations</summary>
19081904 /// <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>
19101906 public static TimeSpan TotalDuration ( this IEnumerable < PeriodValue > values ) =>
19111907 // summarize from all durations the time span ticks
19121908 values != null ? new ( GetDurations ( values ) . Sum ( ts => ts . Ticks ) ) : TimeSpan . Zero ;
@@ -2061,7 +2057,7 @@ public static List<decimal> Values(this IEnumerable<WageTypeCustomResult> result
20612057
20622058 /// <summary>Get summary of wage type custom results</summary>
20632059 /// <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>
20652061 public static decimal Sum ( this IEnumerable < WageTypeCustomResult > results ) =>
20662062 Values ( results ) . Sum ( ) ;
20672063}
@@ -2095,7 +2091,7 @@ valueType is ValueType.Date or
20952091 public static bool IsNumber ( this ValueType valueType ) =>
20962092 IsInteger ( valueType ) || IsDecimal ( valueType ) ;
20972093
2098- /// <summary>Test if value type is a integer</summary>
2094+ /// <summary>Test if value type is an integer</summary>
20992095 /// <param name="valueType">The value type</param>
21002096 /// <returns>True for integer value types</returns>
21012097 public static bool IsInteger ( this ValueType valueType ) =>
@@ -2299,21 +2295,24 @@ public static CasePayrollValueDictionary TupleToCaseValuesDictionary(this Dictio
22992295 /// <param name="values">The tuple values</param>
23002296 /// <returns>The collector results</returns>
23012297 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
23032300 {
23042301 CollectorName = x . Item1 ,
23052302 Start = x . Item2 . Item1 ,
23062303 End = x . Item2 . Item2 ,
23072304 Value = x . Item3 ,
23082305 Tags = x . Item4 ,
23092306 Attributes = x . Item5
2310- } ) ) ;
2307+ } )
2308+ ] ;
23112309
23122310 /// <summary>Convert tuple values to a collector custom result</summary>
23132311 /// <param name="values">The tuple values</param>
23142312 /// <returns>The collector custom results</returns>
23152313 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
23172316 {
23182317 CollectorName = x . Item1 ,
23192318 Source = x . Item2 ,
@@ -2322,13 +2321,15 @@ public static List<CollectorCustomResult> TupleToCollectorCustomResults(this Lis
23222321 Value = x . Item4 ,
23232322 Tags = x . Item5 ,
23242323 Attributes = x . Item6
2325- } ) ) ;
2324+ } )
2325+ ] ;
23262326
23272327 /// <summary>Convert tuple values to a wage type result</summary>
23282328 /// <param name="values">The tuple values</param>
23292329 /// <returns>The wage type results</returns>
23302330 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
23322333 {
23332334 WageTypeNumber = x . Item1 ,
23342335 WageTypeName = x . Item2 ,
@@ -2337,13 +2338,15 @@ public static List<WageTypeResult> TupleToWageTypeResults(this List<Tuple<decima
23372338 Value = x . Item4 ,
23382339 Tags = x . Item5 ,
23392340 Attributes = x . Item6
2340- } ) ) ;
2341+ } )
2342+ ] ;
23412343
23422344 /// <summary>Convert tuple values to a wage type custom result</summary>
23432345 /// <param name="values">The tuple values</param>
23442346 /// <returns>The wage type custom results</returns>
23452347 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
23472350 {
23482351 WageTypeNumber = x . Item1 ,
23492352 Name = x . Item2 ,
@@ -2353,5 +2356,6 @@ public static List<WageTypeCustomResult> TupleToWageTypeCustomResults(this List<
23532356 Value = x . Item5 ,
23542357 Tags = x . Item6 ,
23552358 Attributes = x . Item7
2356- } ) ) ;
2359+ } )
2360+ ] ;
23572361}
0 commit comments