diff --git a/src/Microsoft.AspNetCore.Blazor/Components/CascadingValue.cs b/src/Microsoft.AspNetCore.Blazor/Components/CascadingValue.cs index d04a07646e..e130d41d24 100644 --- a/src/Microsoft.AspNetCore.Blazor/Components/CascadingValue.cs +++ b/src/Microsoft.AspNetCore.Blazor/Components/CascadingValue.cs @@ -42,11 +42,11 @@ namespace Microsoft.AspNetCore.Blazor.Components /// change notifications. Set this flag only if you will not change /// during the component's lifetime. /// - [Parameter] private bool Fixed { get; set; } + [Parameter] private bool IsFixed { get; set; } object ICascadingValueComponent.CurrentValue => Value; - bool ICascadingValueComponent.CurrentValueIsFixed => Fixed; + bool ICascadingValueComponent.CurrentValueIsFixed => IsFixed; /// public void Init(RenderHandle renderHandle) @@ -63,11 +63,11 @@ namespace Microsoft.AspNetCore.Blazor.Components var hasSuppliedValue = false; var previousValue = Value; - var previousFixed = Fixed; + var previousFixed = IsFixed; Value = default; ChildContent = null; Name = null; - Fixed = false; + IsFixed = false; foreach (var parameter in parameters) { @@ -88,9 +88,9 @@ namespace Microsoft.AspNetCore.Blazor.Components throw new ArgumentException($"The parameter '{nameof(Name)}' for component '{nameof(CascadingValue)}' does not allow null or empty values."); } } - else if (parameter.Name.Equals(nameof(Fixed), StringComparison.OrdinalIgnoreCase)) + else if (parameter.Name.Equals(nameof(IsFixed), StringComparison.OrdinalIgnoreCase)) { - Fixed = (bool)parameter.Value; + IsFixed = (bool)parameter.Value; } else { @@ -98,9 +98,9 @@ namespace Microsoft.AspNetCore.Blazor.Components } } - if (_hasSetParametersPreviously && Fixed != previousFixed) + if (_hasSetParametersPreviously && IsFixed != previousFixed) { - throw new InvalidOperationException($"The value of {nameof(Fixed)} cannot be changed dynamically."); + throw new InvalidOperationException($"The value of {nameof(IsFixed)} cannot be changed dynamically."); } _hasSetParametersPreviously = true; @@ -145,11 +145,11 @@ namespace Microsoft.AspNetCore.Blazor.Components void ICascadingValueComponent.Subscribe(ComponentState subscriber) { #if DEBUG - if (Fixed) + if (IsFixed) { // Should not be possible. User code cannot trigger this. // Checking only to catch possible future framework bugs. - throw new InvalidOperationException($"Cannot subscribe to a {typeof(CascadingValue<>).Name} when {nameof(Fixed)} is true."); + throw new InvalidOperationException($"Cannot subscribe to a {typeof(CascadingValue<>).Name} when {nameof(IsFixed)} is true."); } #endif diff --git a/test/Microsoft.AspNetCore.Blazor.Test/CascadingParameterTest.cs b/test/Microsoft.AspNetCore.Blazor.Test/CascadingParameterTest.cs index bf149d7177..ab5a3deea3 100644 --- a/test/Microsoft.AspNetCore.Blazor.Test/CascadingParameterTest.cs +++ b/test/Microsoft.AspNetCore.Blazor.Test/CascadingParameterTest.cs @@ -248,7 +248,7 @@ namespace Microsoft.AspNetCore.Blazor.Test { builder.OpenComponent>(0); builder.AddAttribute(1, "Value", providedValue); - builder.AddAttribute(2, "Fixed", true); + builder.AddAttribute(2, "IsFixed", true); builder.AddAttribute(3, RenderTreeBuilder.ChildContent, new RenderFragment(childBuilder => { if (shouldIncludeChild) @@ -306,7 +306,7 @@ namespace Microsoft.AspNetCore.Blazor.Test var component = new TestComponent(builder => { builder.OpenComponent>(0); - builder.AddAttribute(1, "Fixed", isFixed); + builder.AddAttribute(1, "IsFixed", isFixed); builder.AddAttribute(2, "Value", new object()); builder.CloseComponent(); }); @@ -316,7 +316,7 @@ namespace Microsoft.AspNetCore.Blazor.Test // Act/Assert isFixed = true; var ex = Assert.Throws(() => component.TriggerRender()); - Assert.Equal("The value of Fixed cannot be changed dynamically.", ex.Message); + Assert.Equal("The value of IsFixed cannot be changed dynamically.", ex.Message); } [Fact] @@ -330,7 +330,7 @@ namespace Microsoft.AspNetCore.Blazor.Test builder.OpenComponent>(0); if (isFixed) // Showing also that "unset" is treated as "false" { - builder.AddAttribute(1, "Fixed", true); + builder.AddAttribute(1, "IsFixed", true); } builder.AddAttribute(2, "Value", new object()); builder.CloseComponent(); @@ -341,7 +341,7 @@ namespace Microsoft.AspNetCore.Blazor.Test // Act/Assert isFixed = false; var ex = Assert.Throws(() => component.TriggerRender()); - Assert.Equal("The value of Fixed cannot be changed dynamically.", ex.Message); + Assert.Equal("The value of IsFixed cannot be changed dynamically.", ex.Message); } private static T FindComponent(CapturedBatch batch, out int componentId) diff --git a/test/testapps/BasicTestApp/CascadingValueTest/CascadingValueSupplier.cshtml b/test/testapps/BasicTestApp/CascadingValueTest/CascadingValueSupplier.cshtml index c83fd982af..a772b949dd 100644 --- a/test/testapps/BasicTestApp/CascadingValueTest/CascadingValueSupplier.cshtml +++ b/test/testapps/BasicTestApp/CascadingValueTest/CascadingValueSupplier.cshtml @@ -6,7 +6,7 @@ Each of the CascadingValue components here is configured differently for the test. *@ - +