Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove LINQ and reflection from EasingTypeConverter #19260

Merged
merged 6 commits into from
Jun 7, 2024

Conversation

imememani
Copy link
Contributor

Description of Change

Clean up (using switch in place of if chain) for better readability and used more up to date .NET syntax as well as removing the usage of LINQ.

Issues Fixed

N/A

Fixes #

N/A

Cleaned up the methods and added more up to date .NET syntax as well as removing the usage of LINQ.
@imememani imememani requested a review from a team as a code owner December 6, 2023 18:11
@ghost ghost added the community ✨ Community Contribution label Dec 6, 2023
@ghost
Copy link

ghost commented Dec 6, 2023

Hey there @imememani! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

As the switch makes use of nameof the usage of ToLowerInvariant is redundant.
@imememani
Copy link
Contributor Author

@dotnet-policy-service agree

src/Core/src/Converters/EasingTypeConverter.cs Outdated Show resolved Hide resolved
src/Core/src/Converters/EasingTypeConverter.cs Outdated Show resolved Hide resolved
@akhanalcs
Copy link

akhanalcs commented Dec 6, 2023

Switch expressions are much cleaner IMHO.

I recommend changing your switch statements to something like below (haven't tested the below code myself, just wrote it from my phone):

return strValue switch
{
    _ when Compare(nameof(Linear)) => Linear,
    _ when Compare(nameof(SinIn)) => SinIn,
    //  and so on...
    _ => "put default value here"
};

And add this local method for case insensitive comparison:

bool Compare(string right) => string.Equals(strValue, right, StringComparison.OrdinalIgnoreCase);

The value now returns an easing instead of a string (oops!), I have also implemented a local method to check case sensitive strings for the switch statement allowing the same functionality as previous.
@imememani
Copy link
Contributor Author

@affableashish Great suggestion, it does look much more readable and allows case to be ignored, I've pushed some changes to factor the suggestions in.

@Eilon Eilon added the area-animation Animation, Transitions, Transforms label Dec 14, 2023
@albyrock87
Copy link
Contributor

Is there a reason to not use Enum.TryParse (with case-insensitive bool parameter) and ToString instead of the two switch statements?

@samhouts samhouts added the stale Indicates a stale issue/pr and will be closed soon label Feb 6, 2024
@mattleibow
Copy link
Member

/rebase

@mattleibow mattleibow closed this Jun 6, 2024
@mattleibow mattleibow reopened this Jun 6, 2024
@mattleibow mattleibow changed the title Clean up / Linq removal Refactor and remove LINQ from EasingTypeConverter Jun 6, 2024
@mattleibow mattleibow changed the title Refactor and remove LINQ from EasingTypeConverter Remove LINQ and reflection from EasingTypeConverter Jun 6, 2024
@mattleibow
Copy link
Member

/azp run

@mattleibow mattleibow added t/housekeeping ♻︎ area-animation Animation, Transitions, Transforms and removed area-animation Animation, Transitions, Transforms labels Jun 6, 2024
@mattleibow mattleibow self-assigned this Jun 6, 2024
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@mattleibow mattleibow added this to the .NET 8 SR7 milestone Jun 6, 2024
@mattleibow mattleibow removed this from the .NET 8 SR7 milestone Jun 6, 2024
@mattleibow mattleibow enabled auto-merge (squash) June 7, 2024 05:30
@mattleibow mattleibow merged commit d8d9488 into dotnet:main Jun 7, 2024
49 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Jul 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-animation Animation, Transitions, Transforms community ✨ Community Contribution fixed-in-8.0.60 fixed-in-9.0.0-preview.6.24327.7 stale Indicates a stale issue/pr and will be closed soon t/housekeeping ♻︎
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants