ComparisonHelper
Namespace: SnowBank.Runtime.Converters · class
Helper class used to compare object of "compatible" types
Methods
AreSimilar
static bool AreSimilar(object x, object y)
Tries to compare any two object for "equality", where string "123" is considered equal to integer 123
x— Left object to comparey— Right object to compare
Returns: True if both objects are "similar" (ie: the represent the same logical value)
AreSimilar("123", 123) => true AreSimilar('A', "A") => true AreSimilar(false, 0) => true AreSimilar(true, 1) => true
static bool AreSimilar<T1, T2>(T1 x, T2 y)
AreSimilarRelaxed
static bool AreSimilarRelaxed(object x, object y)
Tries to compare any two object for "equality", where both the string "123" and double 123d are considered equal to integer 123
x— Left object to comparey— Right object to compare
Returns: True if both objects are "similar" (ie: the represent the same logical value)
AreSimilarRelaxed(123, 123.0) => true // integers and decimals are compared
AreSimilarRelaxed("123", 123) => true // strings are compared to numbers
AreSimilarRelaxed('A', "A") => true
AreSimilarRelaxed(false, 0) => true // booleans are compared to numbers
AreSimilarRelaxed(true, 1) => true
static bool AreSimilarRelaxed<T1, T2>(T1 x, T2 y)
AreSimilarStrict
static bool AreSimilarStrict(object x, object y)
Tries to compare any two object for "equality", where the double 123d is considered equal to the integer 123, but the string "123" is not.
x— Left object to comparey— Right object to compare
Returns: True if both objects are "similar" (ie: the represent the same logical value)
AreSimilarStrict(123, 123.0) => true // integers and decimals are compared
AreSimilarStrict("123", 123) => false // strings are NOT compared to numbers
AreSimilarStrict('A', "A") => true
AreSimilarStrict(false, 0) => false // booleans are NOT compared to numbers
AreSimilarStrict(true, 1) => false
static bool AreSimilarStrict<T1, T2>(T1 x, T2 y)
CompareSimilarRelaxed
static int CompareSimilarRelaxed(object x, object y)
CompareSimilarStrict
static int CompareSimilarStrict(object x, object y)
GetTypeComparatorRelaxed
static Func<object, object, int> GetTypeComparatorRelaxed(Type t1, Type t2)
GetTypeComparatorStrict
static Func<object, object, int> GetTypeComparatorStrict(Type t1, Type t2)
GetTypeEqualityComparator
static Func<object, object, bool> GetTypeEqualityComparator(Type t1, Type t2)
GetTypeEqualityComparatorRelaxed
static Func<object, object, bool> GetTypeEqualityComparatorRelaxed(Type t1, Type t2)
GetTypeEqualityComparatorStrict
static Func<object, object, bool> GetTypeEqualityComparatorStrict(Type t1, Type t2)
GetTypeEqualityComparer
static IEqualityComparer<object> GetTypeEqualityComparer(Type t1, Type t2)
IsStringType
static bool IsStringType(Type t)
Return true if the type is considered to be a "string" (string, char)
Returns: True for string and char.
TryAdaptToDecimal
static bool TryAdaptToDecimal(object value, Type type, out double result)
Tries to convert an object into an equivalent double representation (for equality comparison)
value— Object to adapttype— Type of the object to adaptresult— Double equivalent of the object
Returns: True if value is compatible with a decimal. False if the type is not compatible
TryAdaptToInteger
static bool TryAdaptToInteger(object value, Type type, out long result)
Tries to convert an object into an equivalent Int64 representation (for equality comparison)
value— Object to adapttype— Type of the object to adaptresult— Int64 equivalent of the object
Returns: True if value is compatible with a decimal. False if the type is not compatible
TryAdaptToString
static string TryAdaptToString(object value)
Tries to convert an object into an equivalent string representation (for equality comparison)
value— Object to adapt
Returns: String equivalent of the object