Skip to content

Commit a8acc60

Browse files
Move CascadingParameterAttributeBase.Name into subclasses. It shouldn't have been in the base because the meaning varies.
1 parent fe448a7 commit a8acc60

12 files changed

+15
-54
lines changed

src/Components/Components/src/CascadingParameterAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ public sealed class CascadingParameterAttribute : CascadingParameterAttributeBas
2020
/// <see cref="CascadingValue{T}"/> that supplies a value with a compatible
2121
/// type.
2222
/// </summary>
23-
public override string? Name { get; set; }
23+
public string? Name { get; set; }
2424
}

src/Components/Components/src/CascadingParameterAttributeBase.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,6 @@ namespace Microsoft.AspNetCore.Components;
88
/// </summary>
99
public abstract class CascadingParameterAttributeBase : Attribute
1010
{
11-
/// <summary>
12-
/// Gets or sets the name for the parameter, which correlates to the name
13-
/// of a cascading value.
14-
/// </summary>
15-
public abstract string? Name { get; set; }
16-
1711
/// <summary>
1812
/// Gets a flag indicating whether the cascading parameter should
1913
/// be supplied only once per component.

src/Components/Components/src/PublicAPI.Unshipped.txt

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
#nullable enable
2-
abstract Microsoft.AspNetCore.Components.CascadingParameterAttributeBase.Name.get -> string?
3-
abstract Microsoft.AspNetCore.Components.CascadingParameterAttributeBase.Name.set -> void
42
abstract Microsoft.AspNetCore.Components.RenderModeAttribute.Mode.get -> Microsoft.AspNetCore.Components.IComponentRenderMode!
53
Microsoft.AspNetCore.Components.CascadingParameterAttributeBase
64
Microsoft.AspNetCore.Components.CascadingParameterAttributeBase.CascadingParameterAttributeBase() -> void
@@ -83,20 +81,12 @@ Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder.AddComponentParamete
8381
Microsoft.AspNetCore.Components.StreamRenderingAttribute
8482
Microsoft.AspNetCore.Components.StreamRenderingAttribute.Enabled.get -> bool
8583
Microsoft.AspNetCore.Components.StreamRenderingAttribute.StreamRenderingAttribute(bool enabled) -> void
86-
*REMOVED*Microsoft.AspNetCore.Components.CascadingParameterAttribute.Name.get -> string?
87-
*REMOVED*Microsoft.AspNetCore.Components.CascadingParameterAttribute.Name.set -> void
8884
Microsoft.AspNetCore.Components.SupplyParameterFromQueryProviderServiceCollectionExtensions
8985
Microsoft.Extensions.DependencyInjection.CascadingValueServiceCollectionExtensions
90-
override Microsoft.AspNetCore.Components.CascadingParameterAttribute.Name.get -> string?
91-
override Microsoft.AspNetCore.Components.CascadingParameterAttribute.Name.set -> void
9286
override Microsoft.AspNetCore.Components.EventCallback.GetHashCode() -> int
9387
override Microsoft.AspNetCore.Components.EventCallback.Equals(object? obj) -> bool
9488
override Microsoft.AspNetCore.Components.EventCallback<TValue>.GetHashCode() -> int
9589
override Microsoft.AspNetCore.Components.EventCallback<TValue>.Equals(object? obj) -> bool
96-
*REMOVED*Microsoft.AspNetCore.Components.SupplyParameterFromQueryAttribute.Name.get -> string?
97-
*REMOVED*Microsoft.AspNetCore.Components.SupplyParameterFromQueryAttribute.Name.set -> void
98-
override Microsoft.AspNetCore.Components.SupplyParameterFromQueryAttribute.Name.get -> string?
99-
override Microsoft.AspNetCore.Components.SupplyParameterFromQueryAttribute.Name.set -> void
10090
static Microsoft.AspNetCore.Components.SupplyParameterFromQueryProviderServiceCollectionExtensions.AddSupplyValueFromQueryProvider(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
10191
static Microsoft.Extensions.DependencyInjection.CascadingValueServiceCollectionExtensions.AddCascadingValue<TValue>(this Microsoft.Extensions.DependencyInjection.IServiceCollection! serviceCollection, string! name, System.Func<System.IServiceProvider!, TValue>! valueFactory) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
10292
static Microsoft.Extensions.DependencyInjection.CascadingValueServiceCollectionExtensions.AddCascadingValue<TValue>(this Microsoft.Extensions.DependencyInjection.IServiceCollection! serviceCollection, System.Func<System.IServiceProvider!, Microsoft.AspNetCore.Components.CascadingValueSource<TValue>!>! sourceFactory) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!

src/Components/Components/src/Reflection/ComponentProperties.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,7 @@ private static void ThrowForUnknownIncomingParameterName([DynamicallyAccessedMem
184184
{
185185
throw new InvalidOperationException(
186186
$"Object of type '{targetType.FullName}' has a property matching the name '{parameterName}', " +
187-
$"but it does not have [{nameof(ParameterAttribute)}], [{nameof(CascadingParameterAttribute)}] or " +
188-
$"[SupplyParameterFromFormAttribute] applied.");
187+
$"but it does not have [Parameter], [CascadingParameter], or any other parameter-supplying attribute.");
189188
}
190189
else
191190
{

src/Components/Components/src/SupplyParameterFromQueryAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ public sealed class SupplyParameterFromQueryAttribute : CascadingParameterAttrib
1414
/// Gets or sets the name of the querystring parameter. If null, the querystring
1515
/// parameter is assumed to have the same name as the associated property.
1616
/// </summary>
17-
public override string? Name { get; set; }
17+
public string? Name { get; set; }
1818
}

src/Components/Components/src/SupplyParameterFromQueryProviderServiceCollectionExtensions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ public bool CanSupplyValue(in CascadingParameterInfo parameterInfo)
5050
UpdateQueryParameters();
5151
}
5252

53-
var queryParameterName = parameterInfo.Attribute.Name ?? parameterInfo.PropertyName;
53+
var attribute = (SupplyParameterFromQueryAttribute)parameterInfo.Attribute; // Must be a valid cast because we check in CanSupplyValue
54+
var queryParameterName = attribute.Name ?? parameterInfo.PropertyName;
5455
return _queryParameterValueSupplier.GetQueryParameterValue(parameterInfo.PropertyType, queryParameterName);
5556
}
5657

src/Components/Components/test/CascadingParameterStateTest.cs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -476,8 +476,6 @@ class ComponentWithNamedCascadingParam : TestComponentBase
476476

477477
class SupplyParameterWithSingleDeliveryAttribute : CascadingParameterAttributeBase
478478
{
479-
public override string Name { get; set; }
480-
481479
internal override bool SingleDelivery => true;
482480
}
483481

@@ -523,19 +521,3 @@ public TestNavigationManager()
523521
}
524522
}
525523
}
526-
527-
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
528-
public sealed class SupplyParameterFromFormAttribute : CascadingParameterAttributeBase
529-
{
530-
/// <summary>
531-
/// Gets or sets the name for the parameter. The name is used to match
532-
/// the form data and decide whether or not the value needs to be bound.
533-
/// </summary>
534-
public override string Name { get; set; }
535-
536-
/// <summary>
537-
/// Gets or sets the name for the handler. The name is used to match
538-
/// the form data and decide whether or not the value needs to be bound.
539-
/// </summary>
540-
public string Handler { get; set; }
541-
}

src/Components/Components/test/CascadingParameterTest.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -734,8 +734,6 @@ private class SingleDeliveryValue(string text)
734734

735735
private class SingleDeliveryCascadingParameterAttribute : CascadingParameterAttributeBase
736736
{
737-
public override string Name { get; set; }
738-
739737
internal override bool SingleDelivery => true;
740738
}
741739

@@ -852,13 +850,11 @@ class SecondCascadingParameterConsumerComponent<T1, T2> : CascadingParameterCons
852850
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
853851
class CustomCascadingParameter1Attribute : CascadingParameterAttributeBase
854852
{
855-
public override string Name { get; set; }
856853
}
857854

858855
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
859856
class CustomCascadingParameter2Attribute : CascadingParameterAttributeBase
860857
{
861-
public override string Name { get; set; }
862858
}
863859

864860
class CustomCascadingValueProducer<TAttribute> : AutoRenderComponent, ICascadingValueSupplier
@@ -904,7 +900,7 @@ void ICascadingValueSupplier.Unsubscribe(ComponentState subscriber, in Cascading
904900

905901
class CustomCascadingValueConsumer1 : AutoRenderComponent
906902
{
907-
[CustomCascadingParameter1(Name = nameof(Value))]
903+
[CustomCascadingParameter1]
908904
public object Value { get; set; }
909905

910906
protected override void BuildRenderTree(RenderTreeBuilder builder)
@@ -915,7 +911,7 @@ protected override void BuildRenderTree(RenderTreeBuilder builder)
915911

916912
class CustomCascadingValueConsumer2 : AutoRenderComponent
917913
{
918-
[CustomCascadingParameter2(Name = nameof(Value))]
914+
[CustomCascadingParameter2]
919915
public object Value { get; set; }
920916

921917
protected override void BuildRenderTree(RenderTreeBuilder builder)

src/Components/Components/test/ParameterViewTest.Assignment.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ public void IncomingParameterMatchesPropertyNotDeclaredAsParameter_Throws()
183183
Assert.Equal(default, target.IntProp);
184184
Assert.Equal(
185185
$"Object of type '{typeof(HasPropertyWithoutParameterAttribute).FullName}' has a property matching the name '{nameof(HasPropertyWithoutParameterAttribute.IntProp)}', " +
186-
$"but it does not have [{nameof(ParameterAttribute)}], [{nameof(CascadingParameterAttribute)}] or [{nameof(SupplyParameterFromFormAttribute)}] applied.",
186+
"but it does not have [Parameter], [CascadingParameter], or any other parameter-supplying attribute.",
187187
ex.Message);
188188
}
189189

src/Components/Web/src/Forms/Mapping/SupplyParameterFromFormValueProvider.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,9 @@ void ICascadingValueSupplier.Unsubscribe(ComponentState subscriber, in Cascading
7373
{
7474
Debug.Assert(mappingContext != null);
7575

76-
var parameterName = parameterInfo.Attribute.Name ?? parameterInfo.PropertyName;
77-
var restrictToFormName = ((SupplyParameterFromFormAttribute)parameterInfo.Attribute).Handler;
76+
var attribute = (SupplyParameterFromFormAttribute)parameterInfo.Attribute; // Must be a valid cast because we check in CanSupplyValue
77+
var parameterName = attribute.Name ?? parameterInfo.PropertyName;
78+
var restrictToFormName = attribute.Handler;
7879
Action<string, FormattableString, string?> errorHandler = string.IsNullOrEmpty(restrictToFormName) ?
7980
mappingContext.AddError :
8081
(name, message, value) => mappingContext.AddError(restrictToFormName, parameterName, message, value);

src/Components/Web/src/PublicAPI.Unshipped.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ Microsoft.AspNetCore.Components.HtmlRendering.Infrastructure.StaticHtmlRenderer.
6565
Microsoft.AspNetCore.Components.SupplyParameterFromFormAttribute
6666
Microsoft.AspNetCore.Components.SupplyParameterFromFormAttribute.Handler.get -> string?
6767
Microsoft.AspNetCore.Components.SupplyParameterFromFormAttribute.Handler.set -> void
68+
Microsoft.AspNetCore.Components.SupplyParameterFromFormAttribute.Name.get -> string?
69+
Microsoft.AspNetCore.Components.SupplyParameterFromFormAttribute.Name.set -> void
6870
Microsoft.AspNetCore.Components.SupplyParameterFromFormAttribute.SupplyParameterFromFormAttribute() -> void
6971
Microsoft.AspNetCore.Components.Web.AutoRenderMode
7072
Microsoft.AspNetCore.Components.Web.AutoRenderMode.AutoRenderMode() -> void
@@ -111,8 +113,6 @@ override Microsoft.AspNetCore.Components.Forms.Editor<T>.OnParametersSet() -> vo
111113
override Microsoft.AspNetCore.Components.HtmlRendering.Infrastructure.StaticHtmlRenderer.Dispatcher.get -> Microsoft.AspNetCore.Components.Dispatcher!
112114
override Microsoft.AspNetCore.Components.HtmlRendering.Infrastructure.StaticHtmlRenderer.HandleException(System.Exception! exception) -> void
113115
override Microsoft.AspNetCore.Components.HtmlRendering.Infrastructure.StaticHtmlRenderer.UpdateDisplayAsync(in Microsoft.AspNetCore.Components.RenderTree.RenderBatch renderBatch) -> System.Threading.Tasks.Task!
114-
override Microsoft.AspNetCore.Components.SupplyParameterFromFormAttribute.Name.get -> string?
115-
override Microsoft.AspNetCore.Components.SupplyParameterFromFormAttribute.Name.set -> void
116116
override Microsoft.AspNetCore.Components.Web.RenderModeAutoAttribute.Mode.get -> Microsoft.AspNetCore.Components.IComponentRenderMode!
117117
override Microsoft.AspNetCore.Components.Web.RenderModeServerAttribute.Mode.get -> Microsoft.AspNetCore.Components.IComponentRenderMode!
118118
override Microsoft.AspNetCore.Components.Web.RenderModeWebAssemblyAttribute.Mode.get -> Microsoft.AspNetCore.Components.IComponentRenderMode!

src/Components/Web/src/SupplyParameterFromFormAttribute.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@ namespace Microsoft.AspNetCore.Components;
1111
public sealed class SupplyParameterFromFormAttribute : CascadingParameterAttributeBase
1212
{
1313
/// <summary>
14-
/// Gets or sets the name for the parameter. The name is used to determine
15-
/// the prefix to use to match the form data and decide whether or not the
16-
/// value needs to be bound.
14+
/// Gets or sets the name for the form value. If not specified, the property name will be used.
1715
/// </summary>
18-
public override string? Name { get; set; }
16+
public string? Name { get; set; }
1917

2018
/// <summary>
2119
/// Gets or sets the name for the handler. The name is used to match

0 commit comments

Comments
 (0)