diff --git a/src/Http/Http.Extensions/gen/Microsoft.AspNetCore.Http.ValidationsGenerator/Extensions/ISymbolExtensions.cs b/src/Http/Http.Extensions/gen/Microsoft.AspNetCore.Http.ValidationsGenerator/Extensions/ISymbolExtensions.cs index 54efe204c1ec..86eb4e50a43a 100644 --- a/src/Http/Http.Extensions/gen/Microsoft.AspNetCore.Http.ValidationsGenerator/Extensions/ISymbolExtensions.cs +++ b/src/Http/Http.Extensions/gen/Microsoft.AspNetCore.Http.ValidationsGenerator/Extensions/ISymbolExtensions.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System; using System.Linq; using Microsoft.CodeAnalysis; @@ -14,17 +15,19 @@ public static string GetDisplayName(this ISymbol property, INamedTypeSymbol disp .FirstOrDefault(attribute => attribute.AttributeClass is { } attributeClass && SymbolEqualityComparer.Default.Equals(attributeClass, displayAttribute)); + if (displayNameAttribute is not null) { - if (displayNameAttribute.ConstructorArguments.Length > 0) - { - return displayNameAttribute.ConstructorArguments[0].Value?.ToString() ?? property.Name; - } - else if (displayNameAttribute.NamedArguments.Length > 0) + if (!displayNameAttribute.NamedArguments.IsDefaultOrEmpty) { - return displayNameAttribute.NamedArguments[0].Value.Value?.ToString() ?? property.Name; + foreach (var namedArgument in displayNameAttribute.NamedArguments) + { + if (string.Equals(namedArgument.Key, "Name", StringComparison.Ordinal)) + { + return namedArgument.Value.Value?.ToString() ?? property.Name; + } + } } - return property.Name; } return property.Name; diff --git a/src/Http/Http.Extensions/test/ValidationsGenerator/ValidationsGenerator.IValidatableObject.cs b/src/Http/Http.Extensions/test/ValidationsGenerator/ValidationsGenerator.IValidatableObject.cs index 30de31e208b0..d50498d4a997 100644 --- a/src/Http/Http.Extensions/test/ValidationsGenerator/ValidationsGenerator.IValidatableObject.cs +++ b/src/Http/Http.Extensions/test/ValidationsGenerator/ValidationsGenerator.IValidatableObject.cs @@ -54,6 +54,8 @@ public IEnumerable Validate(ValidationContext validationContex public class SubType { [Required] + // This gets ignored since it has an unsupported constructor name + [Display(ShortName = "SubType")] public string RequiredProperty { get; set; } = "some-value"; [StringLength(10)]