CompareHelper

Ecng.Common

Provides helper methods for comparing various types including IPAddress, Type, object, and Version.

方法

Compare
public static int Compare(IPAddress first, IPAddress second)
result = CompareHelper.Compare(first, second)

Compares two IPAddress instances by converting them to a numeric value.

first
The first IPAddress to compare.
second
The second IPAddress to compare.

返回值: 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
public static bool Compare(Type first, Type second, bool useInheritance)
result = CompareHelper.Compare(first, second, useInheritance)

Compares two Type instances for equality with an option to consider inheritance.

first
The first Type to compare.
second
The second Type to compare.
useInheritance
If set to true, uses inheritance to determine equality.

返回值: True if the types are considered equal; otherwise, false.

Compare
public static int Compare(Type first, Type second)
result = CompareHelper.Compare(first, second)

Compares two Type instances with inheritance ordering.

first
The first Type to compare.
second
The second Type to compare.

返回值: 0 if the types are identical; 1 if is assignable from ; otherwise, -1.

Compare
public static int Compare(object value1, object value2)
result = CompareHelper.Compare(value1, value2)

Compares two objects of the same type that implement IComparable.

value1
The first object to compare.
value2
The second object to compare.

返回值: A signed integer that indicates the relative values of the two objects. Less than zero if is less than , zero if equal, and greater than zero if greater.

Compare
public static int Compare(Version first, Version second)
result = CompareHelper.Compare(first, second)

Compares two Version instances.

first
The first Version to compare.
second
The second Version to compare.

返回值: A signed integer that indicates the relative values of the two versions. Less than zero if is less than , zero if equal, and greater than zero if greater.

IsDefault``1
public static bool IsDefault<T>(T value)
result = CompareHelper.IsDefault(value)

Determines whether a value is equal to its default value.

value
The value to check.

返回值: True if the value equals the default value of its type; otherwise, false.

IsRuntimeDefault``1
public static bool IsRuntimeDefault<T>(T value)
result = CompareHelper.IsRuntimeDefault(value)

Determines whether a value is equal to the default value as computed at runtime.

value
The value to check.

返回值: True if the value equals the runtime default value; otherwise, false.