2using System.Collections.Generic;
17 string genericTypeName = t.GetGenericTypeDefinition().Name;
18 genericTypeName = genericTypeName.Substring(0,
19 genericTypeName.IndexOf(
'`'));
20 string genericArgs = String.Join(
",",
22 return genericTypeName +
"<" + genericArgs +
">";
25 private static readonly HashSet<Type> IntegerTypes =
new HashSet<Type>
42 return IntegerTypes.Contains(t) ||
43 IntegerTypes.Contains(Nullable.GetUnderlyingType(t));
46 private static readonly HashSet<Type> NumericTypes =
new HashSet<Type>(IntegerTypes)
58 return NumericTypes.Contains(t) ||
59 NumericTypes.Contains(Nullable.GetUnderlyingType(t));
68 double tolerance = 1E-14)
70 return d1.Equals(d2) ||
71 Math.Abs((d1 - d2) / Math.Max(Math.Abs(d1), Math.Abs(d2))) <= tolerance;
82 public static bool AlmostEquals(
this DateTime dt1, DateTime dt2, TimeSpan? tolerance =
null)
85 tolerance = tolerance ?? TimeSpan.FromTicks(1000);
86 return (dt1.ToUniversalTime() - dt2.ToUniversalTime()).Duration() <= tolerance;
Utilities used to format types and properties in a manner suitable to output in error messages,...
static string NiceTypeName(this Type t)
Produces a human readable string representation of the provided type name, with special consideration...
static bool AlmostEquals(this double d1, double d2, double tolerance=1E-14)
Determines whether two doubles are equivalent within the specified tolerance.
static bool IsIntegerType(this Type t)
Determines whether a property is an integer type.
static bool IsNumeric(this Type t)
Determines whether a property is numeric.
static bool AlmostEquals(this DateTime dt1, DateTime dt2, TimeSpan? tolerance=null)
Determines whether two dates are equal within the supported precision.