Table of Contents

Class CompareHelper

Namespace
Ecng.Common
Assembly
Ecng.Common.dll

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

first IPAddress

The first IPAddress to compare.

second IPAddress

The second IPAddress to compare.

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

value1 object

The first object to compare.

value2 object

The second object to compare.

Returns

int

A signed integer that indicates the relative values of the two objects. Less than zero if value1 is less than value2, 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

first Type

The first Type to compare.

second Type

The second Type to compare.

Returns

int

0 if the types are identical; 1 if second is assignable from first; otherwise, -1.

Exceptions

ArgumentNullException

Thrown if either first or second 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 Type

The first Type to compare.

second Type

The second Type to compare.

useInheritance bool

If 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 or second is null.

Compare(Version, Version)

Compares two Version instances.

public static int Compare(this Version first, Version second)

Parameters

first Version

The first Version to compare.

second Version

The second Version to compare.

Returns

int

A signed integer that indicates the relative values of the two versions. Less than zero if first is less than second, 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 T

The 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 T

The value to check.

Returns

bool

True if the value equals the runtime default value; otherwise, false.

Type Parameters

T

The type of the value.