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

simplify some dictionary usage #4575

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

SimonCropp
Copy link
Contributor

No description provided.

@@ -84,7 +84,7 @@ public MethodInfo[] GetRuntimeMethods(Type type)
Dictionary<string, PropertyInfo> type = ReflectionDataProvider.TypePropertiesByName[classType];

// We as asking for TestContext here, it may not be there.
PropertyInfo? property = type.TryGetValue(propertyName, out PropertyInfo? propertyInfo) ? propertyInfo : null;
PropertyInfo? property = type.GetValueOrDefault(propertyName);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
PropertyInfo? property = type.GetValueOrDefault(propertyName);
_ = type.TryGetValue(propertyName, PropertyInfo? property);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

why not GetValueOrDefault ?

Copy link
Member

@Youssef1313 Youssef1313 Jan 9, 2025

Choose a reason for hiding this comment

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

They are the same, nothing really wrong about GetValueOrDefault.

GetValueOrDefault will end up calling TryGetValue at the end of the day, so I preferred to call TryGetValue directly unless GetValueOrDefault is saving annoying conditional syntax (like the case in GetMetadata below in the PR)

It's mostly personal opinion/style though.

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.

2 participants