private void ConfigureBoundAttribute( BoundAttributeDescriptorBuilder builder, IPropertySymbol property, INamedTypeSymbol containingType) { var attributeNameAttribute = property .GetAttributes() .Where(a => SymbolEqualityComparer.Default.Equals(a.AttributeClass, _htmlAttributeNameAttributeSymbol)) .FirstOrDefault(); bool hasExplicitName; string attributeName; if (attributeNameAttribute == null || attributeNameAttribute.ConstructorArguments.Length == 0 || string.IsNullOrEmpty((string)attributeNameAttribute.ConstructorArguments[0].Value)) { hasExplicitName = false; attributeName = HtmlConventions.ToHtmlCase(property.Name); } else { hasExplicitName = true; attributeName = (string)attributeNameAttribute.ConstructorArguments[0].Value; } var hasPublicSetter = property.SetMethod != null && property.SetMethod.DeclaredAccessibility == Accessibility.Public; var typeName = GetFullName(property.Type); builder.TypeName = typeName; builder.SetPropertyName(property.Name); if (hasPublicSetter) { builder.Name = attributeName; if (property.Type.TypeKind == TypeKind.Enum) { builder.IsEnum = true; } if (IncludeDocumentation) { var xml = property.GetDocumentationCommentXml(); if (!string.IsNullOrEmpty(xml)) { builder.Documentation = xml; } } } else if (hasExplicitName && !IsPotentialDictionaryProperty(property)) { // Specified HtmlAttributeNameAttribute.Name though property has no public setter. var diagnostic = RazorDiagnosticFactory.CreateTagHelper_InvalidAttributeNameNullOrEmpty(GetFullName(containingType), property.Name); builder.Diagnostics.Add(diagnostic); } ConfigureDictionaryBoundAttribute(builder, property, containingType, attributeNameAttribute, attributeName, hasPublicSetter); }
public static BoundAttributeDescriptorBuilder PropertyName(this BoundAttributeDescriptorBuilder builder, string propertyName) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } builder.SetPropertyName(propertyName); return(builder); }