@@ -44,15 +44,15 @@ public static bool IsNumericType(this Type type)
44
44
public static class NullableExtensions
45
45
{
46
46
/// <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 ) =>
48
48
value ?? defaultValue ;
49
49
50
50
/// <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 ) =>
52
52
value ?? defaultValue ;
53
53
54
54
/// <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 ) =>
56
56
value ?? defaultValue ;
57
57
58
58
/// <summary>Safe nullable DateTime cast</summary>
@@ -336,13 +336,13 @@ public static Tuple<string, string> ToRelatedCaseNames(this string caseRelation)
336
336
{
337
337
if ( string . IsNullOrWhiteSpace ( caseRelation ) )
338
338
{
339
- return default ;
339
+ return null ;
340
340
}
341
341
342
342
var relatedCases = caseRelation . Split ( RelatedCaseSeparator , StringSplitOptions . RemoveEmptyEntries ) ;
343
343
if ( relatedCases . Length != 2 )
344
344
{
345
- throw new ArgumentException ( $ "invalid case relation { caseRelation } , please use 'sourceCaseName:targetCaseName')") ;
345
+ throw new ArgumentException ( $ "invalid case relation { caseRelation } , please use 'sourceCaseName:targetCaseName'). ") ;
346
346
}
347
347
return new ( relatedCases [ 0 ] , relatedCases [ 1 ] ) ;
348
348
}
@@ -355,11 +355,11 @@ public static string ToCaseRelationKey(this string sourceCaseName, string target
355
355
{
356
356
if ( string . IsNullOrWhiteSpace ( sourceCaseName ) )
357
357
{
358
- return default ;
358
+ return null ;
359
359
}
360
360
if ( string . IsNullOrWhiteSpace ( targetCaseName ) )
361
361
{
362
- return default ;
362
+ return null ;
363
363
}
364
364
365
365
return $ "{ sourceCaseName } { RelatedCaseSeparator } { targetCaseName } ";
@@ -467,21 +467,21 @@ public static bool IsWithin(this decimal? value, decimal min, decimal max) =>
467
467
/// <param name="stepSize">The step size used to truncate</param>
468
468
/// <returns>The result of d rounded toward zero, to the nearest whole number within the step size</returns>
469
469
public static decimal Truncate ( this decimal value , int stepSize ) =>
470
- value == default ? default : value - ( value % stepSize ) ;
470
+ value == 0 ? 0 : value - ( value % stepSize ) ;
471
471
472
472
/// <summary>Rounds a decimal value up</summary>
473
473
/// <param name="value">The decimal value to round</param>
474
474
/// <param name="stepSize">The round step size</param>
475
475
/// <returns>The up-rounded value</returns>
476
476
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 ;
478
478
479
479
/// <summary>Rounds a decimal value down</summary>
480
480
/// <param name="value">The decimal value to round</param>
481
481
/// <param name="stepSize">The round step size</param>
482
482
/// <returns>The rounded value</returns>
483
483
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 ;
485
485
486
486
/// <summary>Rounds a decimal value wit predefined rounding type</summary>
487
487
/// <param name="value">The decimal value to round</param>
@@ -542,7 +542,7 @@ public static decimal RoundHundredth(this decimal value) =>
542
542
/// <param name="divisor">The divisor factor</param>
543
543
/// <returns>The rounded value to one-tenth</returns>
544
544
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 ;
546
546
}
547
547
548
548
/// <summary><see cref="DateTime">DateTime</see> extension methods</summary>
@@ -645,7 +645,7 @@ public static DateTime ToUtc(this DateTime moment)
645
645
// convert to utc
646
646
return moment . ToUniversalTime ( ) ;
647
647
default :
648
- throw new ArgumentOutOfRangeException ( $ "Unknown date time kind { moment . Kind } ") ;
648
+ throw new ArgumentOutOfRangeException ( $ "Unknown date time kind { moment . Kind } . ") ;
649
649
}
650
650
}
651
651
@@ -667,7 +667,7 @@ public static DateTime ToUtcTime(this DateTime moment)
667
667
// convert to utc
668
668
return moment . ToUniversalTime ( ) ;
669
669
default :
670
- throw new ArgumentOutOfRangeException ( $ "Unknown date time kind { moment . Kind } ") ;
670
+ throw new ArgumentOutOfRangeException ( $ "Unknown date time kind { moment . Kind } . ") ;
671
671
}
672
672
}
673
673
@@ -991,7 +991,7 @@ public static int Age(this DateTime birthDate, DateTime testMoment)
991
991
{
992
992
if ( testMoment <= birthDate )
993
993
{
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. " ) ;
995
995
}
996
996
var age = testMoment . Year - birthDate . Year ;
997
997
// leap years
@@ -1033,7 +1033,7 @@ public static bool IsLastMomentOfDay(this DateTime moment) =>
1033
1033
public static DateTime RoundUp ( this DateTime dateTime , TimeSpan stepSize )
1034
1034
{
1035
1035
var modTicks = dateTime . Ticks % stepSize . Ticks ;
1036
- var delta = modTicks != default ? stepSize . Ticks - modTicks : 0 ;
1036
+ var delta = modTicks != 0 ? stepSize . Ticks - modTicks : 0 ;
1037
1037
return delta != 0 ? new ( dateTime . Ticks + delta , dateTime . Kind ) : dateTime ;
1038
1038
}
1039
1039
@@ -1044,7 +1044,7 @@ public static DateTime RoundUp(this DateTime dateTime, TimeSpan stepSize)
1044
1044
public static DateTime RoundDown ( this DateTime dateTime , TimeSpan stepSize )
1045
1045
{
1046
1046
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 ;
1048
1048
}
1049
1049
1050
1050
/// <summary>Rounds a date time to the nearest value</summary>
@@ -1054,7 +1054,7 @@ public static DateTime RoundDown(this DateTime dateTime, TimeSpan stepSize)
1054
1054
public static DateTime Round ( this DateTime dateTime , TimeSpan stepSize )
1055
1055
{
1056
1056
var delta = dateTime . Ticks % stepSize . Ticks ;
1057
- if ( delta == default )
1057
+ if ( delta == 0 )
1058
1058
{
1059
1059
return dateTime ;
1060
1060
}
@@ -1193,7 +1193,7 @@ public static class DictionaryExtensions
1193
1193
/// <param name="key">The value key</param>
1194
1194
/// <param name="defaultValue">The default value</param>
1195
1195
/// <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 )
1197
1197
{
1198
1198
if ( ! dictionary . TryGetValue ( key , out var value ) )
1199
1199
{
@@ -1238,7 +1238,7 @@ public static class TimeSpanExtensions
1238
1238
public static TimeSpan RoundUp ( this TimeSpan timeSpan , TimeSpan stepSize )
1239
1239
{
1240
1240
var modTicks = timeSpan . Ticks % stepSize . Ticks ;
1241
- var delta = modTicks != default ? stepSize . Ticks - modTicks : 0 ;
1241
+ var delta = modTicks != 0 ? stepSize . Ticks - modTicks : 0 ;
1242
1242
return delta != 0 ? new ( timeSpan . Ticks + delta ) : timeSpan ;
1243
1243
}
1244
1244
@@ -1249,7 +1249,7 @@ public static TimeSpan RoundUp(this TimeSpan timeSpan, TimeSpan stepSize)
1249
1249
public static TimeSpan RoundDown ( this TimeSpan timeSpan , TimeSpan stepSize )
1250
1250
{
1251
1251
var delta = timeSpan . Ticks % stepSize . Ticks ;
1252
- return delta != default ? new ( timeSpan . Ticks - delta ) : timeSpan ;
1252
+ return delta != 0 ? new ( timeSpan . Ticks - delta ) : timeSpan ;
1253
1253
}
1254
1254
1255
1255
/// <summary>Rounds a time interval to the nearest value</summary>
@@ -1259,7 +1259,7 @@ public static TimeSpan RoundDown(this TimeSpan timeSpan, TimeSpan stepSize)
1259
1259
public static TimeSpan Round ( this TimeSpan timeSpan , TimeSpan stepSize )
1260
1260
{
1261
1261
var delta = timeSpan . Ticks % stepSize . Ticks ;
1262
- if ( delta == default )
1262
+ if ( delta == 0 )
1263
1263
{
1264
1264
return timeSpan ;
1265
1265
}
@@ -2137,7 +2137,7 @@ public static Type GetDataType(this ValueType valueType)
2137
2137
{
2138
2138
return typeof ( DBNull ) ;
2139
2139
}
2140
- throw new ScriptException ( $ "Unknown value type { valueType } ") ;
2140
+ throw new ScriptException ( $ "Unknown value type { valueType } . ") ;
2141
2141
}
2142
2142
2143
2143
/// <summary>Get the value type</summary>
@@ -2181,15 +2181,15 @@ public static object JsonToValue(this ValueType valueType, string json)
2181
2181
2182
2182
if ( valueType . IsInteger ( ) )
2183
2183
{
2184
- return string . IsNullOrWhiteSpace ( json ) ? default : JsonSerializer . Deserialize < int > ( json ) ;
2184
+ return string . IsNullOrWhiteSpace ( json ) ? 0 : JsonSerializer . Deserialize < int > ( json ) ;
2185
2185
}
2186
2186
if ( valueType . IsDecimal ( ) )
2187
2187
{
2188
- return string . IsNullOrWhiteSpace ( json ) ? default : JsonSerializer . Deserialize < decimal > ( json ) ;
2188
+ return string . IsNullOrWhiteSpace ( json ) ? 0 : JsonSerializer . Deserialize < decimal > ( json ) ;
2189
2189
}
2190
2190
if ( valueType . IsString ( ) )
2191
2191
{
2192
- return string . IsNullOrWhiteSpace ( json ) ? default :
2192
+ return string . IsNullOrWhiteSpace ( json ) ? null :
2193
2193
json . StartsWith ( '"' ) ? JsonSerializer . Deserialize < string > ( json ) : json ;
2194
2194
}
2195
2195
if ( valueType . IsDateTime ( ) )
@@ -2207,7 +2207,7 @@ public static object JsonToValue(this ValueType valueType, string json)
2207
2207
{
2208
2208
return null ;
2209
2209
}
2210
- throw new ScriptException ( $ "unknown value type { valueType } ") ;
2210
+ throw new ScriptException ( $ "unknown value type { valueType } . ") ;
2211
2211
}
2212
2212
}
2213
2213
0 commit comments