Skip to content

Instantly share code, notes, and snippets.

@jrmoserbaltimore
Last active September 2, 2018 22:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrmoserbaltimore/53ad753a53a47d78901fd706f7b70449 to your computer and use it in GitHub Desktop.
Save jrmoserbaltimore/53ad753a53a47d78901fd706f7b70449 to your computer and use it in GitHub Desktop.
// 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