@@ -44,15 +44,15 @@ public static bool IsNumericType(this Type type)
4444public static class NullableExtensions
4545{
4646 /// <summary>Safe nullable boolean cast</summary>
47- public static bool Safe ( this bool ? value , bool defaultValue = default ) =>
47+ public static bool Safe ( this bool ? value , bool defaultValue = false ) =>
4848 value ?? defaultValue ;
4949
5050 /// <summary>Safe nullable int cast</summary>
51- public static int Safe ( this int ? value , int defaultValue = default ) =>
51+ public static int Safe ( this int ? value , int defaultValue = 0 ) =>
5252 value ?? defaultValue ;
5353
5454 /// <summary>Safe nullable decimal cast</summary>
55- public static decimal Safe ( this decimal ? value , decimal defaultValue = default ) =>
55+ public static decimal Safe ( this decimal ? value , decimal defaultValue = 0 ) =>
5656 value ?? defaultValue ;
5757
5858 /// <summary>Safe nullable DateTime cast</summary>
@@ -336,13 +336,13 @@ public static Tuple<string, string> ToRelatedCaseNames(this string caseRelation)
336336 {
337337 if ( string . IsNullOrWhiteSpace ( caseRelation ) )
338338 {
339- return default ;
339+ return null ;
340340 }
341341
342342 var relatedCases = caseRelation . Split ( RelatedCaseSeparator , StringSplitOptions . RemoveEmptyEntries ) ;
343343 if ( relatedCases . Length != 2 )
344344 {
345- throw new ArgumentException ( $ "invalid case relation { caseRelation } , please use 'sourceCaseName:targetCaseName')") ;
345+ throw new ArgumentException ( $ "invalid case relation { caseRelation } , please use 'sourceCaseName:targetCaseName'). ") ;
346346 }
347347 return new ( relatedCases [ 0 ] , relatedCases [ 1 ] ) ;
348348 }
@@ -355,11 +355,11 @@ public static string ToCaseRelationKey(this string sourceCaseName, string target
355355 {
356356 if ( string . IsNullOrWhiteSpace ( sourceCaseName ) )
357357 {
358- return default ;
358+ return null ;
359359 }
360360 if ( string . IsNullOrWhiteSpace ( targetCaseName ) )
361361 {
362- return default ;
362+ return null ;
363363 }
364364
365365 return $ "{ sourceCaseName } { RelatedCaseSeparator } { targetCaseName } ";
@@ -467,21 +467,21 @@ public static bool IsWithin(this decimal? value, decimal min, decimal max) =>
467467 /// <param name="stepSize">The step size used to truncate</param>
468468 /// <returns>The result of d rounded toward zero, to the nearest whole number within the step size</returns>
469469 public static decimal Truncate ( this decimal value , int stepSize ) =>
470- value == default ? default : value - ( value % stepSize ) ;
470+ value == 0 ? 0 : value - ( value % stepSize ) ;
471471
472472 /// <summary>Rounds a decimal value up</summary>
473473 /// <param name="value">The decimal value to round</param>
474474 /// <param name="stepSize">The round step size</param>
475475 /// <returns>The up-rounded value</returns>
476476 public static decimal RoundUp ( this decimal value , decimal stepSize ) =>
477- value == default || stepSize == 0 ? value : Math . Ceiling ( value / stepSize ) * stepSize ;
477+ value == 0 || stepSize == 0 ? value : Math . Ceiling ( value / stepSize ) * stepSize ;
478478
479479 /// <summary>Rounds a decimal value down</summary>
480480 /// <param name="value">The decimal value to round</param>
481481 /// <param name="stepSize">The round step size</param>
482482 /// <returns>The rounded value</returns>
483483 public static decimal RoundDown ( this decimal value , decimal stepSize ) =>
484- value == default || stepSize == 0 ? value : Math . Floor ( value / stepSize ) * stepSize ;
484+ value == 0 || stepSize == 0 ? value : Math . Floor ( value / stepSize ) * stepSize ;
485485
486486 /// <summary>Rounds a decimal value wit predefined rounding type</summary>
487487 /// <param name="value">The decimal value to round</param>
@@ -542,7 +542,7 @@ public static decimal RoundHundredth(this decimal value) =>
542542 /// <param name="divisor">The divisor factor</param>
543543 /// <returns>The rounded value to one-tenth</returns>
544544 public static decimal RoundPartOfOne ( this decimal value , int divisor ) =>
545- value == default ? default : Math . Round ( value * divisor , MidpointRounding . AwayFromZero ) / divisor ;
545+ value == 0 ? 0 : Math . Round ( value * divisor , MidpointRounding . AwayFromZero ) / divisor ;
546546}
547547
548548/// <summary><see cref="DateTime">DateTime</see> extension methods</summary>
@@ -645,7 +645,7 @@ public static DateTime ToUtc(this DateTime moment)
645645 // convert to utc
646646 return moment . ToUniversalTime ( ) ;
647647 default :
648- throw new ArgumentOutOfRangeException ( $ "Unknown date time kind { moment . Kind } ") ;
648+ throw new ArgumentOutOfRangeException ( $ "Unknown date time kind { moment . Kind } . ") ;
649649 }
650650 }
651651
@@ -667,7 +667,7 @@ public static DateTime ToUtcTime(this DateTime moment)
667667 // convert to utc
668668 return moment . ToUniversalTime ( ) ;
669669 default :
670- throw new ArgumentOutOfRangeException ( $ "Unknown date time kind { moment . Kind } ") ;
670+ throw new ArgumentOutOfRangeException ( $ "Unknown date time kind { moment . Kind } . ") ;
671671 }
672672 }
673673
@@ -991,7 +991,7 @@ public static int Age(this DateTime birthDate, DateTime testMoment)
991991 {
992992 if ( testMoment <= birthDate )
993993 {
994- throw new ArgumentOutOfRangeException ( nameof ( testMoment ) , "calculate age: birth-date must be older than test-date" ) ;
994+ throw new ArgumentOutOfRangeException ( nameof ( testMoment ) , "calculate age: birth-date must be older than test-date. " ) ;
995995 }
996996 var age = testMoment . Year - birthDate . Year ;
997997 // leap years
@@ -1033,7 +1033,7 @@ public static bool IsLastMomentOfDay(this DateTime moment) =>
10331033 public static DateTime RoundUp ( this DateTime dateTime , TimeSpan stepSize )
10341034 {
10351035 var modTicks = dateTime . Ticks % stepSize . Ticks ;
1036- var delta = modTicks != default ? stepSize . Ticks - modTicks : 0 ;
1036+ var delta = modTicks != 0 ? stepSize . Ticks - modTicks : 0 ;
10371037 return delta != 0 ? new ( dateTime . Ticks + delta , dateTime . Kind ) : dateTime ;
10381038 }
10391039
@@ -1044,7 +1044,7 @@ public static DateTime RoundUp(this DateTime dateTime, TimeSpan stepSize)
10441044 public static DateTime RoundDown ( this DateTime dateTime , TimeSpan stepSize )
10451045 {
10461046 var delta = dateTime . Ticks % stepSize . Ticks ;
1047- return delta != default ? new ( dateTime . Ticks - delta , dateTime . Kind ) : dateTime ;
1047+ return delta != 0 ? new ( dateTime . Ticks - delta , dateTime . Kind ) : dateTime ;
10481048 }
10491049
10501050 /// <summary>Rounds a date time to the nearest value</summary>
@@ -1054,7 +1054,7 @@ public static DateTime RoundDown(this DateTime dateTime, TimeSpan stepSize)
10541054 public static DateTime Round ( this DateTime dateTime , TimeSpan stepSize )
10551055 {
10561056 var delta = dateTime . Ticks % stepSize . Ticks ;
1057- if ( delta == default )
1057+ if ( delta == 0 )
10581058 {
10591059 return dateTime ;
10601060 }
@@ -1193,7 +1193,7 @@ public static class DictionaryExtensions
11931193 /// <param name="key">The value key</param>
11941194 /// <param name="defaultValue">The default value</param>
11951195 /// <returns>The dictionary value</returns>
1196- public static object GetValue ( this Dictionary < string , object > dictionary , string key , object defaultValue = default )
1196+ public static object GetValue ( this Dictionary < string , object > dictionary , string key , object defaultValue = null )
11971197 {
11981198 if ( ! dictionary . TryGetValue ( key , out var value ) )
11991199 {
@@ -1238,7 +1238,7 @@ public static class TimeSpanExtensions
12381238 public static TimeSpan RoundUp ( this TimeSpan timeSpan , TimeSpan stepSize )
12391239 {
12401240 var modTicks = timeSpan . Ticks % stepSize . Ticks ;
1241- var delta = modTicks != default ? stepSize . Ticks - modTicks : 0 ;
1241+ var delta = modTicks != 0 ? stepSize . Ticks - modTicks : 0 ;
12421242 return delta != 0 ? new ( timeSpan . Ticks + delta ) : timeSpan ;
12431243 }
12441244
@@ -1249,7 +1249,7 @@ public static TimeSpan RoundUp(this TimeSpan timeSpan, TimeSpan stepSize)
12491249 public static TimeSpan RoundDown ( this TimeSpan timeSpan , TimeSpan stepSize )
12501250 {
12511251 var delta = timeSpan . Ticks % stepSize . Ticks ;
1252- return delta != default ? new ( timeSpan . Ticks - delta ) : timeSpan ;
1252+ return delta != 0 ? new ( timeSpan . Ticks - delta ) : timeSpan ;
12531253 }
12541254
12551255 /// <summary>Rounds a time interval to the nearest value</summary>
@@ -1259,7 +1259,7 @@ public static TimeSpan RoundDown(this TimeSpan timeSpan, TimeSpan stepSize)
12591259 public static TimeSpan Round ( this TimeSpan timeSpan , TimeSpan stepSize )
12601260 {
12611261 var delta = timeSpan . Ticks % stepSize . Ticks ;
1262- if ( delta == default )
1262+ if ( delta == 0 )
12631263 {
12641264 return timeSpan ;
12651265 }
@@ -2137,7 +2137,7 @@ public static Type GetDataType(this ValueType valueType)
21372137 {
21382138 return typeof ( DBNull ) ;
21392139 }
2140- throw new ScriptException ( $ "Unknown value type { valueType } ") ;
2140+ throw new ScriptException ( $ "Unknown value type { valueType } . ") ;
21412141 }
21422142
21432143 /// <summary>Get the value type</summary>
@@ -2181,15 +2181,15 @@ public static object JsonToValue(this ValueType valueType, string json)
21812181
21822182 if ( valueType . IsInteger ( ) )
21832183 {
2184- return string . IsNullOrWhiteSpace ( json ) ? default : JsonSerializer . Deserialize < int > ( json ) ;
2184+ return string . IsNullOrWhiteSpace ( json ) ? 0 : JsonSerializer . Deserialize < int > ( json ) ;
21852185 }
21862186 if ( valueType . IsDecimal ( ) )
21872187 {
2188- return string . IsNullOrWhiteSpace ( json ) ? default : JsonSerializer . Deserialize < decimal > ( json ) ;
2188+ return string . IsNullOrWhiteSpace ( json ) ? 0 : JsonSerializer . Deserialize < decimal > ( json ) ;
21892189 }
21902190 if ( valueType . IsString ( ) )
21912191 {
2192- return string . IsNullOrWhiteSpace ( json ) ? default :
2192+ return string . IsNullOrWhiteSpace ( json ) ? null :
21932193 json . StartsWith ( '"' ) ? JsonSerializer . Deserialize < string > ( json ) : json ;
21942194 }
21952195 if ( valueType . IsDateTime ( ) )
@@ -2207,7 +2207,7 @@ public static object JsonToValue(this ValueType valueType, string json)
22072207 {
22082208 return null ;
22092209 }
2210- throw new ScriptException ( $ "unknown value type { valueType } ") ;
2210+ throw new ScriptException ( $ "unknown value type { valueType } . ") ;
22112211 }
22122212}
22132213
0 commit comments