Support [Parameter] attribute on base class of overridden properties (dotnet/aspnetcore-tooling#835)
* Support [Parameter] attribute on base class of overridden properties
* Fix test
\n\nCommit migrated from c228339bb3
This commit is contained in:
parent
53841f90f9
commit
f2f0bed885
|
|
@ -386,6 +386,13 @@ namespace Microsoft.CodeAnalysis.Razor
|
|||
|
||||
if (!property.GetAttributes().Any(a => a.AttributeClass == symbols.ParameterAttribute))
|
||||
{
|
||||
if (property.IsOverride)
|
||||
{
|
||||
// This property does not contain [Parameter] attribute but it was overridden. Don't ignore it for now.
|
||||
// We can ignore it if the base class does not contains a [Parameter] as well.
|
||||
continue;
|
||||
}
|
||||
|
||||
// Does not have [Parameter]
|
||||
kind = PropertyKind.Ignored;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1436,5 +1436,72 @@ namespace Test
|
|||
|
||||
Assert.Empty(component.BoundAttributes);
|
||||
}
|
||||
|
||||
[Fact] // Testing multilevel overrides with the [Parameter] attribute on different levels.
|
||||
public void Execute_MultiLevelOverriddenProperties_CreatesDescriptorCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
|
||||
var compilation = BaseCompilation.AddSyntaxTrees(Parse(@"
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
||||
namespace Test
|
||||
{
|
||||
public abstract class MyBaseComponent : ComponentBase
|
||||
{
|
||||
[Parameter]
|
||||
public virtual string Header { get; set; }
|
||||
|
||||
public virtual string Footer { get; set; }
|
||||
}
|
||||
|
||||
public abstract class MyDerivedComponent1 : MyBaseComponent
|
||||
{
|
||||
public override string Header { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public override string Footer { get; set; }
|
||||
}
|
||||
|
||||
public class MyDerivedComponent2 : MyDerivedComponent1
|
||||
{
|
||||
public override string Header { get; set; }
|
||||
|
||||
public override string Footer { get; set; }
|
||||
}
|
||||
}
|
||||
"));
|
||||
|
||||
Assert.Empty(compilation.GetDiagnostics());
|
||||
|
||||
var context = TagHelperDescriptorProviderContext.Create();
|
||||
context.SetCompilation(compilation);
|
||||
|
||||
var provider = new ComponentTagHelperDescriptorProvider();
|
||||
|
||||
// Act
|
||||
provider.Execute(context);
|
||||
|
||||
// Assert
|
||||
var components = ExcludeBuiltInComponents(context);
|
||||
components = AssertAndExcludeFullyQualifiedNameMatchComponents(components, expectedCount: 1);
|
||||
var component = Assert.Single(components, c => c.IsComponentTagHelper());
|
||||
|
||||
Assert.Equal("TestAssembly", component.AssemblyName);
|
||||
Assert.Equal("Test.MyDerivedComponent2", component.Name);
|
||||
|
||||
Assert.Collection(
|
||||
component.BoundAttributes.OrderBy(a => a.Name),
|
||||
a =>
|
||||
{
|
||||
Assert.Equal("Footer", a.Name);
|
||||
Assert.Equal("System.String", a.TypeName);
|
||||
},
|
||||
a =>
|
||||
{
|
||||
Assert.Equal("Header", a.Name);
|
||||
Assert.Equal("System.String", a.TypeName);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue