Skip to content

IComparable for complex params#2304

Merged
AndreyAkinshin merged 7 commits intodotnet:masterfrom
mrahhal:icomparable-for-complex-params
May 10, 2023
Merged

IComparable for complex params#2304
AndreyAkinshin merged 7 commits intodotnet:masterfrom
mrahhal:icomparable-for-complex-params

Conversation

@mrahhal
Copy link
Contributor

@mrahhal mrahhal commented May 9, 2023

All the types in PrimitiveComparer are actually already IComparable, so I feel we can just remove this whole part altogether and have a single implementation that uses IComparable. Thoughts?

Not sure if just removing it will replicate current behavior, since it does some stuff with enums, and it also even does a string comparison (which feels weird to me since there's already a string comparison in ParameterComparer.Compare).

Closes #2301

@mrahhal mrahhal marked this pull request as draft May 9, 2023 20:13
Copy link
Member

@adamsitnik adamsitnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall it LGTM, I just left one suggestion for improvement.

@mrahhal thank you for your contribution!

@mrahhal mrahhal marked this pull request as ready for review May 10, 2023 10:31
@AndreyAkinshin
Copy link
Member

It looks great, thanks! The only suggestion I have is about the intro example. We are trying to keep them as small as possible. I would suggest removing non-essential comments (e.g., "property with public setter", "public property") and simplifying some of the methods. E.g., instead

public int CompareTo(ComplexParam other)
{
    if (other == null)
    {
        return 1;
    }

    return Value.CompareTo(other.Value);
}

we can write

public int CompareTo(ComplexParam other) => other == null ? 1 : Value.CompareTo(other.Value);

@AndreyAkinshin
Copy link
Member

@mrahhal could you please also rewrite IntroComparableComplexParam.CompareTo(object obj)? Currently, it occupies too much space in the sample (while this particular implementation is not so important).

@mrahhal
Copy link
Contributor Author

mrahhal commented May 10, 2023

Sure. Simplified it as much as I can.

Copy link
Member

@AndreyAkinshin AndreyAkinshin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@AndreyAkinshin AndreyAkinshin merged commit f32a2e7 into dotnet:master May 10, 2023
@AndreyAkinshin
Copy link
Member

@mrahhal thanks for your contribution!

@AndreyAkinshin AndreyAkinshin added this to the v0.13.6 milestone May 10, 2023
@mrahhal mrahhal deleted the icomparable-for-complex-params branch May 10, 2023 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Custom order of parameters when using complex types

3 participants