Last active
September 2, 2018 22:30
-
-
Save jrmoserbaltimore/53ad753a53a47d78901fd706f7b70449 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Not valid | |
namespace Boilerplate | |
{ | |
public boilerplate BCompareOperators<T> | |
{ | |
bool operator >(T lhs, T rhs) => lhs.CompareTo(rhs) > 0; | |
bool operator <(T lhs, T rhs) => lhs.CompareTo(rhs) < 0; | |
bool operator >=(T lhs, T rhs) => lhs.CompareTo(rhs) >= 0; | |
bool operator <=(T lhs, T rhs) => lhs.CompareTo(rhs) <= 0; | |
} | |
public boilerplate BEqualsOperator<T> | |
{ | |
bool operator ==(T lhs, T rhs) | |
{ | |
if (lhs is null && rhs is null) | |
return true; | |
else if (lhs is null) | |
return false; | |
else | |
return lhs.Equals(rhs); | |
} | |
} | |
public boilerplate BNotEqualsOperator<T> | |
{ | |
bool operator !=(T lhs, T rhs) => !(lhs == rhs); | |
} | |
public class MyType : IEquatable<MyType>, IComparable<MyType> | |
{ | |
with public static boilerplate BCompareOperators<MyType>; | |
with public static boilerplate BEqualsOperator<MyType>; | |
with public static boilerplate BNotEqualsOperator<MyType>; | |
public int CompareTo(MyType other) | |
{ | |
... | |
} | |
public virtual bool Equals(MyType other) | |
{ | |
... | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment