-
Notifications
You must be signed in to change notification settings - Fork 262
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
base: main
Are you sure you want to change the base?
simplify some dictionary usage #4575
Conversation
@@ -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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PropertyInfo? property = type.GetValueOrDefault(propertyName); | |
_ = type.TryGetValue(propertyName, PropertyInfo? property); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not GetValueOrDefault ?
There was a problem hiding this comment.
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.
No description provided.