Class CompareHelper
Provides helper methods for comparing various types including IPAddress, Type, object, and Version.
public static class CompareHelper
- Inheritance
-
CompareHelper
- Inherited Members
Methods
Compare(IPAddress, IPAddress)
Compares two IPAddress instances by converting them to a numeric value.
public static int Compare(this IPAddress first, IPAddress second)
Parameters
Returns
- int
A signed integer that indicates the relative values of the two IP addresses. Less than zero if first is less than second, zero if equal, and greater than zero if first is greater than second.
Compare(object, object)
Compares two objects of the same type that implement IComparable.
public static int Compare(this object value1, object value2)
Parameters
Returns
- int
A signed integer that indicates the relative values of the two objects. Less than zero if
value1
is less thanvalue2
, zero if equal, and greater than zero if greater.
Exceptions
- ArgumentException
Thrown if the objects are not of the same type or if they do not implement IComparable.
Compare(Type, Type)
Compares two Type instances with inheritance ordering.
public static int Compare(this Type first, Type second)
Parameters
Returns
- int
0 if the types are identical; 1 if
second
is assignable fromfirst
; otherwise, -1.
Exceptions
- ArgumentNullException
Thrown if either
first
orsecond
is null.
Compare(Type, Type, bool)
Compares two Type instances for equality with an option to consider inheritance.
public static bool Compare(this Type first, Type second, bool useInheritance)
Parameters
first
TypeThe first Type to compare.
second
TypeThe second Type to compare.
useInheritance
boolIf set to true, uses inheritance to determine equality.
Returns
- bool
True if the types are considered equal; otherwise, false.
Exceptions
- ArgumentNullException
Thrown if either
first
orsecond
is null.
Compare(Version, Version)
Compares two Version instances.
public static int Compare(this Version first, Version second)
Parameters
Returns
- int
A signed integer that indicates the relative values of the two versions. Less than zero if
first
is less thansecond
, zero if equal, and greater than zero if greater.
IsDefault<T>(T)
Determines whether a value is equal to its default value.
public static bool IsDefault<T>(this T value)
Parameters
value
TThe value to check.
Returns
- bool
True if the value equals the default value of its type; otherwise, false.
Type Parameters
T
The type of the value.
IsRuntimeDefault<T>(T)
Determines whether a value is equal to the default value as computed at runtime.
public static bool IsRuntimeDefault<T>(this T value)
Parameters
value
TThe value to check.
Returns
- bool
True if the value equals the runtime default value; otherwise, false.
Type Parameters
T
The type of the value.