From 4a6f471d12fd03b3e187610ef1d29099369c6086 Mon Sep 17 00:00:00 2001 From: Steve Sanderson Date: Thu, 18 Oct 2018 09:37:46 +0100 Subject: [PATCH] Add Cascading flag to Parameter (#1564) ... so that components that pass through an arbitrary set of parameters can choose to filter out cascading ones if they want. --- .../Components/Parameter.cs | 9 ++++++++- .../Components/ParameterEnumerator.cs | 4 ++-- .../ParameterCollectionTest.cs | 17 +++++++++-------- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/Microsoft.AspNetCore.Blazor/Components/Parameter.cs b/src/Microsoft.AspNetCore.Blazor/Components/Parameter.cs index 09c806f79f..8e4b9db909 100644 --- a/src/Microsoft.AspNetCore.Blazor/Components/Parameter.cs +++ b/src/Microsoft.AspNetCore.Blazor/Components/Parameter.cs @@ -19,10 +19,17 @@ namespace Microsoft.AspNetCore.Blazor.Components /// public object Value { get; } - internal Parameter(string name, object value) + /// + /// Gets a value to indicate whether the parameter is cascading, meaning that it + /// was supplied by a . + /// + public bool Cascading { get; } + + internal Parameter(string name, object value, bool cascading) { Name = name; Value = value; + Cascading = cascading; } } } diff --git a/src/Microsoft.AspNetCore.Blazor/Components/ParameterEnumerator.cs b/src/Microsoft.AspNetCore.Blazor/Components/ParameterEnumerator.cs index 09806dfa56..9de7197b89 100644 --- a/src/Microsoft.AspNetCore.Blazor/Components/ParameterEnumerator.cs +++ b/src/Microsoft.AspNetCore.Blazor/Components/ParameterEnumerator.cs @@ -89,7 +89,7 @@ namespace Microsoft.AspNetCore.Blazor.Components _currentIndex = nextIndex; ref var frame = ref _frames[_currentIndex]; - _current = new Parameter(frame.AttributeName, frame.AttributeValue); + _current = new Parameter(frame.AttributeName, frame.AttributeValue, false); return true; } @@ -124,7 +124,7 @@ namespace Microsoft.AspNetCore.Blazor.Components _currentIndex = nextIndex; var state = _cascadingParameters[_currentIndex]; - _current = new Parameter(state.LocalValueName, state.ValueSupplier.CurrentValue); + _current = new Parameter(state.LocalValueName, state.ValueSupplier.CurrentValue, true); return true; } else diff --git a/test/Microsoft.AspNetCore.Blazor.Test/ParameterCollectionTest.cs b/test/Microsoft.AspNetCore.Blazor.Test/ParameterCollectionTest.cs index 4a7213bf4d..f2def78acc 100644 --- a/test/Microsoft.AspNetCore.Blazor.Test/ParameterCollectionTest.cs +++ b/test/Microsoft.AspNetCore.Blazor.Test/ParameterCollectionTest.cs @@ -60,8 +60,8 @@ namespace Microsoft.AspNetCore.Blazor.Test // Assert Assert.Collection(ToEnumerable(parameterCollection), - AssertParameter("attribute 1", attribute1Value), - AssertParameter("attribute 2", attribute2Value)); + AssertParameter("attribute 1", attribute1Value, false), + AssertParameter("attribute 2", attribute2Value, false)); } [Fact] @@ -82,8 +82,8 @@ namespace Microsoft.AspNetCore.Blazor.Test // Assert Assert.Collection(ToEnumerable(parameterCollection), - AssertParameter("attribute 1", attribute1Value), - AssertParameter("attribute 2", attribute2Value)); + AssertParameter("attribute 1", attribute1Value, false), + AssertParameter("attribute 2", attribute2Value, false)); } [Fact] @@ -105,9 +105,9 @@ namespace Microsoft.AspNetCore.Blazor.Test // Assert Assert.Collection(ToEnumerable(parameterCollection), - AssertParameter("attribute 1", attribute1Value), - AssertParameter("attribute 2", attribute2Value), - AssertParameter("attribute 3", attribute3Value)); + AssertParameter("attribute 1", attribute1Value, false), + AssertParameter("attribute 2", attribute2Value, true), + AssertParameter("attribute 3", attribute3Value, true)); } [Fact] @@ -291,12 +291,13 @@ namespace Microsoft.AspNetCore.Blazor.Test Assert.Same(myEntryValue, result); } - private Action AssertParameter(string expectedName, object expectedValue) + private Action AssertParameter(string expectedName, object expectedValue, bool expectedIsCascading) { return parameter => { Assert.Equal(expectedName, parameter.Name); Assert.Same(expectedValue, parameter.Value); + Assert.Equal(expectedIsCascading, parameter.Cascading); }; }