Skip to content

Commit

Permalink
Update custom property to break and return default.
Browse files Browse the repository at this point in the history
  • Loading branch information
Coderrob committed Apr 5, 2021
1 parent 9cc1f2b commit 25e7971
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -593,26 +593,32 @@ private static string GetPropertyName(MemberInfo property)
throw new ArgumentNullException(nameof(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)
{
// ConfigurationKeyName expected to have a single string constructor argument
continue;
}

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

string value = constructorArgument.Value.ToString();
if (!string.IsNullOrWhiteSpace(value))
string name = constructorArgument.Value.ToString();
if (!string.IsNullOrWhiteSpace(name))
{
return value;
return name;
}

// No custom string "name" provided - we're done here.
break;
}

return property.Name;
Expand Down

0 comments on commit 25e7971

Please sign in to comment.