Skip to content

Commit 76f1e6f

Browse files
committed
Only check for null within GetScalarValue()
If there's not a getter method or getter property, then `attributeValue` will be null. If there is a getter method or getter property, then `attributeValue` might be null or empty. If it's null, that's ambiguous between whether the method existed in not. But if it's empty, we know the member existed and returned a value. In that case, we should trust that value instead of executing fallback logic with `String.IsNullOrEmpty()`. A further optimization would be to confirm that it exists and only fallback if it doesn't. As these are comparatively rare scenarios, though, it doesn't make sense to add additional overhead for this check, and especially when it's already handled by the `GetMethodValue()` and `GetPropertyValue()` methods.
1 parent 9f1f677 commit 76f1e6f

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

OnTopic/Mapping/TopicMappingService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -620,14 +620,14 @@ await MapAsync(
620620
/*------------------------------------------------------------------------------------------------------------------------
621621
| Attempt to retrieve value from topic.{Property}
622622
\-----------------------------------------------------------------------------------------------------------------------*/
623-
if (String.IsNullOrEmpty(attributeValue)) {
623+
if (attributeValue is null) {
624624
attributeValue = typeAccessor.GetPropertyValue(source, configuration.AttributeKey)?.ToString();
625625
}
626626

627627
/*------------------------------------------------------------------------------------------------------------------------
628628
| Otherwise, attempt to retrieve value from topic.Attributes.GetValue({Property})
629629
\-----------------------------------------------------------------------------------------------------------------------*/
630-
if (String.IsNullOrEmpty(attributeValue)) {
630+
if (attributeValue is null) {
631631
attributeValue = source.Attributes.GetValue(
632632
configuration.AttributeKey,
633633
configuration.DefaultValue?.ToString(),

0 commit comments

Comments
 (0)