dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
18.92k stars 4.02k forks source link

'Generate inequality operators' when type already implements IComparable<> #41790

Open jnm2 opened 4 years ago

jnm2 commented 4 years ago

The same way equality operators are generated, it would be nice to not have to write this out:

public static bool operator <(Foo left, Foo right)
{
    return left.CompareTo(right) < 0;
}

public static bool operator >(Foo left, Foo right)
{
    return left.CompareTo(right) > 0;
}

public static bool operator <=(Foo left, Foo right)
{
    return left.CompareTo(right) <= 0;
}

public static bool operator >=(Foo left, Foo right)
{
    return left.CompareTo(right) >= 0;
}

A suggestion would even be nice, or just a refactoring.

CyrusNajmabadi commented 4 years ago

We would definitely take this feature if someone wrote it. If i have time, i can try to do that myself. Or, if you're interested @jnm2 you can do it :)