diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.Extensions/ViewComponentTagHelperDescriptorFactory.cs b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions/ViewComponentTagHelperDescriptorFactory.cs index b3e64c465a..99d6236941 100644 --- a/src/Microsoft.AspNetCore.Mvc.Razor.Extensions/ViewComponentTagHelperDescriptorFactory.cs +++ b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions/ViewComponentTagHelperDescriptorFactory.cs @@ -57,7 +57,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions var typeName = $"__Generated__{shortName}ViewComponentTagHelper"; var displayName = shortName + "ViewComponentTagHelper"; var descriptorBuilder = TagHelperDescriptorBuilder.Create(ViewComponentTagHelperConventions.Kind, typeName, assemblyName) - .TypeName(typeName) + .SetTypeName(typeName) .DisplayName(displayName); if (TryFindInvokeMethod(type, out var method, out var diagnostic)) @@ -186,7 +186,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions { attributeBuilder .Name(lowerKebabName) - .PropertyName(parameter.Name) + .SetPropertyName(parameter.Name) .TypeName(typeName) .DisplayName($"{simpleName} {containingDisplayName}.{parameter.Name}"); diff --git a/src/Microsoft.AspNetCore.Razor.Language/BoundAttributeDescriptorBuilder.cs b/src/Microsoft.AspNetCore.Razor.Language/BoundAttributeDescriptorBuilder.cs index 188d0a8ac5..cfa42236a7 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/BoundAttributeDescriptorBuilder.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/BoundAttributeDescriptorBuilder.cs @@ -1,13 +1,15 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.Collections.Generic; + namespace Microsoft.AspNetCore.Razor.Language { public abstract class BoundAttributeDescriptorBuilder { - public abstract BoundAttributeDescriptorBuilder Name(string name); + public abstract IDictionary Metadata { get; } - public abstract BoundAttributeDescriptorBuilder PropertyName(string propertyName); + public abstract BoundAttributeDescriptorBuilder Name(string name); public abstract BoundAttributeDescriptorBuilder TypeName(string typeName); diff --git a/src/Microsoft.AspNetCore.Razor.Language/BoundAttributeDescriptorBuilderExtensions.cs b/src/Microsoft.AspNetCore.Razor.Language/BoundAttributeDescriptorBuilderExtensions.cs new file mode 100644 index 0000000000..dbccc91b7a --- /dev/null +++ b/src/Microsoft.AspNetCore.Razor.Language/BoundAttributeDescriptorBuilderExtensions.cs @@ -0,0 +1,42 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.AspNetCore.Razor.Language +{ + public static class BoundAttributeDescriptorBuilderExtensions + { + public static BoundAttributeDescriptorBuilder SetPropertyName(this BoundAttributeDescriptorBuilder builder, string propertyName) + { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } + + if (propertyName == null) + { + throw new ArgumentNullException(nameof(propertyName)); + } + + builder.AddMetadata(TagHelperMetadata.Common.PropertyName, propertyName); + + return builder; + } + + public static string GetPropertyName(this BoundAttributeDescriptorBuilder builder) + { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } + + if (builder.Metadata.ContainsKey(TagHelperMetadata.Common.PropertyName)) + { + return builder.Metadata[TagHelperMetadata.Common.PropertyName]; + } + + return null; + } + } +} diff --git a/src/Microsoft.AspNetCore.Razor.Language/DefaultBoundAttributeDescriptorBuilder.cs b/src/Microsoft.AspNetCore.Razor.Language/DefaultBoundAttributeDescriptorBuilder.cs index da021c52d6..16556e99bd 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/DefaultBoundAttributeDescriptorBuilder.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/DefaultBoundAttributeDescriptorBuilder.cs @@ -50,6 +50,8 @@ namespace Microsoft.AspNetCore.Razor.Language _metadata = new Dictionary(); } + public override IDictionary Metadata => _metadata; + public override BoundAttributeDescriptorBuilder Name(string name) { _name = name; @@ -57,13 +59,6 @@ namespace Microsoft.AspNetCore.Razor.Language return this; } - public override BoundAttributeDescriptorBuilder PropertyName(string propertyName) - { - _metadata[TagHelperMetadata.Common.PropertyName] = propertyName; - - return this; - } - public override BoundAttributeDescriptorBuilder TypeName(string typeName) { _typeName = typeName; @@ -153,9 +148,12 @@ namespace Microsoft.AspNetCore.Razor.Language return _displayName; } + var parentTypeName = _parent.GetTypeName(); + var propertyName = this.GetPropertyName(); + if (_typeName != null && - _metadata.ContainsKey(TagHelperMetadata.Common.PropertyName) && - _parent.Metadata.ContainsKey(TagHelperMetadata.Common.TypeName)) + propertyName != null && + parentTypeName != null) { // This looks like a normal c# property, so lets compute a display name based on that. if (!PrimitiveDisplayTypeNameLookups.TryGetValue(_typeName, out var simpleTypeName)) @@ -163,7 +161,7 @@ namespace Microsoft.AspNetCore.Razor.Language simpleTypeName = _typeName; } - return $"{simpleTypeName} {_parent.Metadata[TagHelperMetadata.Common.TypeName]}.{_metadata[TagHelperMetadata.Common.PropertyName]}"; + return $"{simpleTypeName} {parentTypeName}.{propertyName}"; } return _name; diff --git a/src/Microsoft.AspNetCore.Razor.Language/DefaultTagHelperDescriptorBuilder.cs b/src/Microsoft.AspNetCore.Razor.Language/DefaultTagHelperDescriptorBuilder.cs index 4ae93c528d..b6ff3aa015 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/DefaultTagHelperDescriptorBuilder.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/DefaultTagHelperDescriptorBuilder.cs @@ -32,7 +32,7 @@ namespace Microsoft.AspNetCore.Razor.Language _metadata = new Dictionary(StringComparer.Ordinal); } - public IDictionary Metadata => _metadata; + public override IDictionary Metadata => _metadata; public override TagHelperDescriptorBuilder BindAttribute(Action configure) { @@ -114,17 +114,6 @@ namespace Microsoft.AspNetCore.Razor.Language return this; } - public override TagHelperDescriptorBuilder TypeName(string typeName) - { - if (typeName == null) - { - throw new ArgumentNullException(nameof(typeName)); - } - - _metadata[TagHelperMetadata.Common.TypeName] = typeName; - return this; - } - public override TagHelperDescriptor Build() { var validationDiagnostics = Validate(); @@ -192,7 +181,7 @@ namespace Microsoft.AspNetCore.Razor.Language return _displayName; } - return _metadata.ContainsKey(TagHelperMetadata.Common.TypeName) ? _metadata[TagHelperMetadata.Common.TypeName] : _name; + return this.GetTypeName() ?? _name; } private IEnumerable Validate() diff --git a/src/Microsoft.AspNetCore.Razor.Language/TagHelperDescriptorBuilder.cs b/src/Microsoft.AspNetCore.Razor.Language/TagHelperDescriptorBuilder.cs index 3f301037c8..c1ffa0f0e7 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/TagHelperDescriptorBuilder.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/TagHelperDescriptorBuilder.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Collections.Generic; namespace Microsoft.AspNetCore.Razor.Language { @@ -41,6 +42,8 @@ namespace Microsoft.AspNetCore.Razor.Language return new DefaultTagHelperDescriptorBuilder(kind, name, assemblyName); } + public abstract IDictionary Metadata { get; } + public abstract TagHelperDescriptorBuilder BindAttribute(Action configure); public abstract TagHelperDescriptorBuilder TagMatchingRule(Action configure); @@ -57,8 +60,6 @@ namespace Microsoft.AspNetCore.Razor.Language public abstract TagHelperDescriptorBuilder DisplayName(string displayName); - public abstract TagHelperDescriptorBuilder TypeName(string typeName); - public abstract TagHelperDescriptor Build(); public abstract void Reset(); diff --git a/src/Microsoft.AspNetCore.Razor.Language/TagHelperDescriptorBuilderExtensions.cs b/src/Microsoft.AspNetCore.Razor.Language/TagHelperDescriptorBuilderExtensions.cs new file mode 100644 index 0000000000..3e7edf25e6 --- /dev/null +++ b/src/Microsoft.AspNetCore.Razor.Language/TagHelperDescriptorBuilderExtensions.cs @@ -0,0 +1,42 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.AspNetCore.Razor.Language +{ + public static class TagHelperDescriptorBuilderExtensions + { + public static TagHelperDescriptorBuilder SetTypeName(this TagHelperDescriptorBuilder builder, string typeName) + { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } + + if (typeName == null) + { + throw new ArgumentNullException(nameof(typeName)); + } + + builder.AddMetadata(TagHelperMetadata.Common.TypeName, typeName); + + return builder; + } + + public static string GetTypeName(this TagHelperDescriptorBuilder builder) + { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } + + if (builder.Metadata.ContainsKey(TagHelperMetadata.Common.TypeName)) + { + return builder.Metadata[TagHelperMetadata.Common.TypeName]; + } + + return null; + } + } +} diff --git a/src/Microsoft.CodeAnalysis.Razor/DefaultTagHelperDescriptorFactory.cs b/src/Microsoft.CodeAnalysis.Razor/DefaultTagHelperDescriptorFactory.cs index f2cf712ceb..df48066986 100644 --- a/src/Microsoft.CodeAnalysis.Razor/DefaultTagHelperDescriptorFactory.cs +++ b/src/Microsoft.CodeAnalysis.Razor/DefaultTagHelperDescriptorFactory.cs @@ -58,7 +58,7 @@ namespace Microsoft.CodeAnalysis.Razor var typeName = GetFullName(type); var assemblyName = type.ContainingAssembly.Identity.Name; var descriptorBuilder = TagHelperDescriptorBuilder.Create(typeName, assemblyName); - descriptorBuilder.TypeName(typeName); + descriptorBuilder.SetTypeName(typeName); AddBoundAttributes(type, descriptorBuilder); AddTagMatchingRules(type, descriptorBuilder); @@ -210,7 +210,7 @@ namespace Microsoft.CodeAnalysis.Razor var typeName = GetFullName(property.Type); builder .TypeName(typeName) - .PropertyName(property.Name); + .SetPropertyName(property.Name); if (hasPublicSetter) { diff --git a/test/Microsoft.AspNetCore.Razor.Test.Common/Langauge/IntegrationTests/IntegrationTestBase.cs b/test/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/IntegrationTestBase.cs similarity index 100% rename from test/Microsoft.AspNetCore.Razor.Test.Common/Langauge/IntegrationTests/IntegrationTestBase.cs rename to test/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/IntegrationTestBase.cs diff --git a/test/Microsoft.AspNetCore.Razor.Test.Common/Langauge/IntegrationTests/IntermediateNodeSerializer.cs b/test/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/IntermediateNodeSerializer.cs similarity index 100% rename from test/Microsoft.AspNetCore.Razor.Test.Common/Langauge/IntegrationTests/IntermediateNodeSerializer.cs rename to test/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/IntermediateNodeSerializer.cs diff --git a/test/Microsoft.AspNetCore.Razor.Test.Common/Langauge/IntegrationTests/IntermediateNodeVerifier.cs b/test/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/IntermediateNodeVerifier.cs similarity index 100% rename from test/Microsoft.AspNetCore.Razor.Test.Common/Langauge/IntegrationTests/IntermediateNodeVerifier.cs rename to test/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/IntermediateNodeVerifier.cs diff --git a/test/Microsoft.AspNetCore.Razor.Test.Common/Langauge/IntegrationTests/IntermediateNodeWriter.cs b/test/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/IntermediateNodeWriter.cs similarity index 100% rename from test/Microsoft.AspNetCore.Razor.Test.Common/Langauge/IntegrationTests/IntermediateNodeWriter.cs rename to test/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/IntermediateNodeWriter.cs diff --git a/test/Microsoft.AspNetCore.Razor.Test.Common/Langauge/IntegrationTests/IntializeTestFileAttribute.cs b/test/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/IntializeTestFileAttribute.cs similarity index 100% rename from test/Microsoft.AspNetCore.Razor.Test.Common/Langauge/IntegrationTests/IntializeTestFileAttribute.cs rename to test/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/IntializeTestFileAttribute.cs diff --git a/test/Microsoft.AspNetCore.Razor.Test.Common/Langauge/IntegrationTests/LineMappingsSerializer.cs b/test/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/LineMappingsSerializer.cs similarity index 100% rename from test/Microsoft.AspNetCore.Razor.Test.Common/Langauge/IntegrationTests/LineMappingsSerializer.cs rename to test/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/LineMappingsSerializer.cs diff --git a/test/Microsoft.AspNetCore.Razor.Test.Common/Langauge/IntegrationTests/RazorDiagnosticSerializer.cs b/test/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/RazorDiagnosticSerializer.cs similarity index 100% rename from test/Microsoft.AspNetCore.Razor.Test.Common/Langauge/IntegrationTests/RazorDiagnosticSerializer.cs rename to test/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/RazorDiagnosticSerializer.cs diff --git a/test/Microsoft.AspNetCore.Razor.Test.Common/Langauge/Intermediate/IntermediateNodeAssert.cs b/test/Microsoft.AspNetCore.Razor.Test.Common/Language/Intermediate/IntermediateNodeAssert.cs similarity index 100% rename from test/Microsoft.AspNetCore.Razor.Test.Common/Langauge/Intermediate/IntermediateNodeAssert.cs rename to test/Microsoft.AspNetCore.Razor.Test.Common/Language/Intermediate/IntermediateNodeAssert.cs diff --git a/test/Microsoft.AspNetCore.Razor.Test.Common/Langauge/RazorEngineBuilderExtensions.cs b/test/Microsoft.AspNetCore.Razor.Test.Common/Language/RazorEngineBuilderExtensions.cs similarity index 100% rename from test/Microsoft.AspNetCore.Razor.Test.Common/Langauge/RazorEngineBuilderExtensions.cs rename to test/Microsoft.AspNetCore.Razor.Test.Common/Language/RazorEngineBuilderExtensions.cs diff --git a/test/Microsoft.AspNetCore.Razor.Test.Common/Language/TestBoundAttributeDescriptorExtensions.cs b/test/Microsoft.AspNetCore.Razor.Test.Common/Language/TestBoundAttributeDescriptorExtensions.cs new file mode 100644 index 0000000000..900c1162f8 --- /dev/null +++ b/test/Microsoft.AspNetCore.Razor.Test.Common/Language/TestBoundAttributeDescriptorExtensions.cs @@ -0,0 +1,20 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.AspNetCore.Razor.Language +{ + public static class TestBoundAttributeDescriptorBuilderExtensions + { + public static BoundAttributeDescriptorBuilder PropertyName(this BoundAttributeDescriptorBuilder builder, string propertyName) + { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } + + return builder.SetPropertyName(propertyName); + } + } +} diff --git a/test/Microsoft.AspNetCore.Razor.Test.Common/Langauge/TestFile.cs b/test/Microsoft.AspNetCore.Razor.Test.Common/Language/TestFile.cs similarity index 100% rename from test/Microsoft.AspNetCore.Razor.Test.Common/Langauge/TestFile.cs rename to test/Microsoft.AspNetCore.Razor.Test.Common/Language/TestFile.cs diff --git a/test/Microsoft.AspNetCore.Razor.Test.Common/Langauge/TestProject.cs b/test/Microsoft.AspNetCore.Razor.Test.Common/Language/TestProject.cs similarity index 100% rename from test/Microsoft.AspNetCore.Razor.Test.Common/Langauge/TestProject.cs rename to test/Microsoft.AspNetCore.Razor.Test.Common/Language/TestProject.cs diff --git a/test/Microsoft.AspNetCore.Razor.Test.Common/Langauge/TestRazorCodeDocument.cs b/test/Microsoft.AspNetCore.Razor.Test.Common/Language/TestRazorCodeDocument.cs similarity index 100% rename from test/Microsoft.AspNetCore.Razor.Test.Common/Langauge/TestRazorCodeDocument.cs rename to test/Microsoft.AspNetCore.Razor.Test.Common/Language/TestRazorCodeDocument.cs diff --git a/test/Microsoft.AspNetCore.Razor.Test.Common/Langauge/TestRazorProject.cs b/test/Microsoft.AspNetCore.Razor.Test.Common/Language/TestRazorProject.cs similarity index 100% rename from test/Microsoft.AspNetCore.Razor.Test.Common/Langauge/TestRazorProject.cs rename to test/Microsoft.AspNetCore.Razor.Test.Common/Language/TestRazorProject.cs diff --git a/test/Microsoft.AspNetCore.Razor.Test.Common/Langauge/TestRazorProjectItem.cs b/test/Microsoft.AspNetCore.Razor.Test.Common/Language/TestRazorProjectItem.cs similarity index 100% rename from test/Microsoft.AspNetCore.Razor.Test.Common/Langauge/TestRazorProjectItem.cs rename to test/Microsoft.AspNetCore.Razor.Test.Common/Language/TestRazorProjectItem.cs diff --git a/test/Microsoft.AspNetCore.Razor.Test.Common/Langauge/TestRazorSourceDocument.cs b/test/Microsoft.AspNetCore.Razor.Test.Common/Language/TestRazorSourceDocument.cs similarity index 100% rename from test/Microsoft.AspNetCore.Razor.Test.Common/Langauge/TestRazorSourceDocument.cs rename to test/Microsoft.AspNetCore.Razor.Test.Common/Language/TestRazorSourceDocument.cs diff --git a/test/Microsoft.AspNetCore.Razor.Test.Common/Language/TestTagHelperDescriptorBuilderExtensions.cs b/test/Microsoft.AspNetCore.Razor.Test.Common/Language/TestTagHelperDescriptorBuilderExtensions.cs new file mode 100644 index 0000000000..baa32694bf --- /dev/null +++ b/test/Microsoft.AspNetCore.Razor.Test.Common/Language/TestTagHelperDescriptorBuilderExtensions.cs @@ -0,0 +1,20 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.AspNetCore.Razor.Language +{ + public static class TestTagHelperDescriptorBuilderExtensions + { + public static TagHelperDescriptorBuilder TypeName(this TagHelperDescriptorBuilder builder, string typeName) + { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } + + return builder.SetTypeName(typeName); + } + } +} diff --git a/test/Microsoft.AspNetCore.Razor.Test.Common/Langauge/TestTagHelperFeature.cs b/test/Microsoft.AspNetCore.Razor.Test.Common/Language/TestTagHelperFeature.cs similarity index 100% rename from test/Microsoft.AspNetCore.Razor.Test.Common/Langauge/TestTagHelperFeature.cs rename to test/Microsoft.AspNetCore.Razor.Test.Common/Language/TestTagHelperFeature.cs diff --git a/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Microsoft.VisualStudio.LanguageServices.Razor.Test.csproj b/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Microsoft.VisualStudio.LanguageServices.Razor.Test.csproj index cb7dcb24ca..2e9ae773ac 100644 --- a/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Microsoft.VisualStudio.LanguageServices.Razor.Test.csproj +++ b/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Microsoft.VisualStudio.LanguageServices.Razor.Test.csproj @@ -24,6 +24,7 @@ +