Skip to content

Commit

Permalink
Update to shorten lookup of binding name attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
Coderrob committed Apr 11, 2021
1 parent 25e7971 commit 76dcdcf
Showing 1 changed file with 8 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -596,29 +596,19 @@ private static string GetPropertyName(MemberInfo property)
// Check for a custom property name used for configuration key binding
foreach (var attributeData in property.GetCustomAttributesData())
{
if (attributeData.AttributeType != typeof(ConfigurationKeyNameAttribute) ||
attributeData.ConstructorArguments.Count == 0)
if (attributeData.AttributeType != typeof(ConfigurationKeyNameAttribute))
{
// ConfigurationKeyName expected to have a single string constructor argument
continue;
}

var constructorArgument = attributeData.ConstructorArguments.First();
if (constructorArgument.ArgumentType != typeof(string) ||
constructorArgument.Value == null)
{
// First argument didn't contain the expected string value
break;
}

string name = constructorArgument.Value.ToString();
if (!string.IsNullOrWhiteSpace(name))
{
return name;
}
// Assumes ConfiguratKeyName constructor first arg is a string key name
string name = attributeData
.ConstructorArguments
.First()
.Value?
.ToString();

// No custom string "name" provided - we're done here.
break;
return !string.IsNullOrWhiteSpace(name) ? name : property.Name;
}

return property.Name;
Expand Down

0 comments on commit 76dcdcf

Please sign in to comment.