oliverbooth / X10D

Extension methods on crack.
https://oliverbooth.github.io/X10D/
MIT License
27 stars 2 forks source link

IComparable<T> "operators" #22

Closed oliverbooth closed 3 years ago

oliverbooth commented 3 years ago

Type

System.IComparable<T>

Extension method signature

T GreaterThan<T>(T);
T GreaterThanOrEqualTo<T>(T);
T LessThan<T>(T);
T LessThanOrEqualTo<T>(T);
Parameters Parameter Type Description
other T The value to compare against.

Description Determines if the current value is greater/less than (or equal to) another value.

Benefits The IComparable<T> interface offers CompareTo(T) method, but naturally does not offer operators such as > < >= and <=. These methods would essentially implement that functionality.

Drawbacks None considered (at this current time)

(Optional) Implementation example

{
    return value.CompareTo(other) < 0;
    // or
    return value.CompareTo(other) <= 0;
    // or
    return value.CompareTo(other) > 0;
    // or
    return value.CompareTo(other) >= 0;
}
oliverbooth commented 3 years ago

Implemented with 2a05cb66707084bc47f3dcb096e3dfa234d489dd