Skip to content

Commit 4b00642

Browse files
committed
Replace TryGetValue() with GetValue()
The `TopicReferenceDictionary` had a `TryGetValue()` method, since it implemented `IDictionary<>`. The `KeyedCollection<>` used by the new underlying `TrackedCollection` doesn't implement this. We could add one, but it doesn't add significantly to the capabilities of `GetValue()`, which wil check to see if a value exists, and if not return an optional default value. As such, the call to `TryGetValue()` is replaced with a call to `GetValue()`. (I refactored this a bit since another condition relies on the variable, and thus it needs to be defined in the parent scope. This is done when placing `TryGetValue()` instead a condition's _expression_, but wouldn't be done if I declared the variable within the _body_ of the condition.)
1 parent e7a5520 commit 4b00642

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

OnTopic/Mapping/TopicMappingService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ private async Task SetPropertyAsync(
281281
\-----------------------------------------------------------------------------------------------------------------------*/
282282
var configuration = new PropertyConfiguration(property, attributePrefix);
283283
var topicReferenceId = source.Attributes.GetInteger($"{configuration.AttributeKey}Id", 0);
284+
var topicReference = source.References.GetValue(configuration.AttributeKey);
284285

285286
if (topicReferenceId == 0 && configuration.AttributeKey.EndsWith("Id", StringComparison.OrdinalIgnoreCase)) {
286287
topicReferenceId = source.Attributes.GetInteger(configuration.AttributeKey, 0);
@@ -314,7 +315,7 @@ private async Task SetPropertyAsync(
314315
}
315316
}
316317
else if (
317-
source.References.TryGetValue(configuration.AttributeKey, out var topicReference) &&
318+
topicReference is not null &&
318319
relationships.HasFlag(Relationships.References)
319320
) {
320321
await SetTopicReferenceAsync(topicReference, target, configuration, cache).ConfigureAwait(false);

0 commit comments

Comments
 (0)