diff --git a/src/Components/Blazor/Build/test/BindRazorIntegrationTest.cs b/src/Components/Blazor/Build/test/BindRazorIntegrationTest.cs index 5c8eb3dca6..bc63a4b0df 100644 --- a/src/Components/Blazor/Build/test/BindRazorIntegrationTest.cs +++ b/src/Components/Blazor/Build/test/BindRazorIntegrationTest.cs @@ -68,7 +68,7 @@ namespace Test { public class MyComponent : ComponentBase, IComponent { - Task IComponent.SetParametersAsync(ParameterCollection parameters) + Task IComponent.SetParametersAsync(ParameterView parameters) { return Task.CompletedTask; } @@ -142,7 +142,7 @@ namespace Test { public class MyComponent : ComponentBase, IComponent { - Task IComponent.SetParametersAsync(ParameterCollection parameters) + Task IComponent.SetParametersAsync(ParameterView parameters) { return Task.CompletedTask; } diff --git a/src/Components/Blazor/Build/test/ComponentRenderingRazorIntegrationTest.cs b/src/Components/Blazor/Build/test/ComponentRenderingRazorIntegrationTest.cs index c746626559..abfdd07793 100644 --- a/src/Components/Blazor/Build/test/ComponentRenderingRazorIntegrationTest.cs +++ b/src/Components/Blazor/Build/test/ComponentRenderingRazorIntegrationTest.cs @@ -165,7 +165,7 @@ namespace Test { public class MyComponent : ComponentBase, IComponent { - Task IComponent.SetParametersAsync(ParameterCollection parameters) + Task IComponent.SetParametersAsync(ParameterView parameters) { return Task.CompletedTask; } diff --git a/src/Components/Blazor/Build/test/DirectiveRazorIntegrationTest.cs b/src/Components/Blazor/Build/test/DirectiveRazorIntegrationTest.cs index de2cc72807..ef46dd1d19 100644 --- a/src/Components/Blazor/Build/test/DirectiveRazorIntegrationTest.cs +++ b/src/Components/Blazor/Build/test/DirectiveRazorIntegrationTest.cs @@ -153,7 +153,7 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test { } - public Task SetParametersAsync(ParameterCollection parameters) + public Task SetParametersAsync(ParameterView parameters) { return Task.CompletedTask; } diff --git a/src/Components/Blazor/Build/test/RazorIntegrationTestBase.cs b/src/Components/Blazor/Build/test/RazorIntegrationTestBase.cs index be14dcbdee..943a658a36 100644 --- a/src/Components/Blazor/Build/test/RazorIntegrationTestBase.cs +++ b/src/Components/Blazor/Build/test/RazorIntegrationTestBase.cs @@ -385,7 +385,7 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test protected private RenderTreeFrame[] GetRenderTree(TestRenderer renderer, IComponent component) { renderer.AttachComponent(component); - var task = renderer.Dispatcher.InvokeAsync(() => component.SetParametersAsync(ParameterCollection.Empty)); + var task = renderer.Dispatcher.InvokeAsync(() => component.SetParametersAsync(ParameterView.Empty)); // we will have to change this method if we add a test that does actual async work. Assert.True(task.Status.HasFlag(TaskStatus.RanToCompletion) || task.Status.HasFlag(TaskStatus.Faulted)); if (task.IsFaulted) diff --git a/src/Components/Components/ref/Microsoft.AspNetCore.Components.netstandard2.0.cs b/src/Components/Components/ref/Microsoft.AspNetCore.Components.netstandard2.0.cs index 65b583091a..a4d8a9c9be 100644 --- a/src/Components/Components/ref/Microsoft.AspNetCore.Components.netstandard2.0.cs +++ b/src/Components/Components/ref/Microsoft.AspNetCore.Components.netstandard2.0.cs @@ -117,7 +117,7 @@ namespace Microsoft.AspNetCore.Components [Microsoft.AspNetCore.Components.ParameterAttribute] public T Value { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } public void Attach(Microsoft.AspNetCore.Components.RenderHandle renderHandle) { } - public System.Threading.Tasks.Task SetParametersAsync(Microsoft.AspNetCore.Components.ParameterCollection parameters) { throw null; } + public System.Threading.Tasks.Task SetParametersAsync(Microsoft.AspNetCore.Components.ParameterView parameters) { throw null; } } public abstract partial class ComponentBase : Microsoft.AspNetCore.Components.IComponent, Microsoft.AspNetCore.Components.IHandleAfterRender, Microsoft.AspNetCore.Components.IHandleEvent { @@ -134,7 +134,7 @@ namespace Microsoft.AspNetCore.Components protected virtual System.Threading.Tasks.Task OnInitializedAsync() { throw null; } protected virtual void OnParametersSet() { } protected virtual System.Threading.Tasks.Task OnParametersSetAsync() { throw null; } - public virtual System.Threading.Tasks.Task SetParametersAsync(Microsoft.AspNetCore.Components.ParameterCollection parameters) { throw null; } + public virtual System.Threading.Tasks.Task SetParametersAsync(Microsoft.AspNetCore.Components.ParameterView parameters) { throw null; } protected virtual bool ShouldRender() { throw null; } protected void StateHasChanged() { } } @@ -238,7 +238,7 @@ namespace Microsoft.AspNetCore.Components public partial interface IComponent { void Attach(Microsoft.AspNetCore.Components.RenderHandle renderHandle); - System.Threading.Tasks.Task SetParametersAsync(Microsoft.AspNetCore.Components.ParameterCollection parameters); + System.Threading.Tasks.Task SetParametersAsync(Microsoft.AspNetCore.Components.ParameterView parameters); } public partial interface IComponentContext { @@ -309,16 +309,7 @@ namespace Microsoft.AspNetCore.Components [Microsoft.AspNetCore.Components.ParameterAttribute] public System.Collections.Generic.IDictionary PageParameters { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } public void Attach(Microsoft.AspNetCore.Components.RenderHandle renderHandle) { } - public System.Threading.Tasks.Task SetParametersAsync(Microsoft.AspNetCore.Components.ParameterCollection parameters) { throw null; } - } - [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] - public readonly partial struct Parameter - { - private readonly object _dummy; - private readonly int _dummyPrimitive; - public bool Cascading { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } } - public string Name { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } } - public object Value { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } } + public System.Threading.Tasks.Task SetParametersAsync(Microsoft.AspNetCore.Components.ParameterView parameters) { throw null; } } [System.AttributeUsageAttribute(System.AttributeTargets.Property, AllowMultiple=false, Inherited=true)] public sealed partial class ParameterAttribute : System.Attribute @@ -327,29 +318,35 @@ namespace Microsoft.AspNetCore.Components public bool CaptureUnmatchedValues { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] - public readonly partial struct ParameterCollection + public readonly partial struct ParameterValue { private readonly object _dummy; private readonly int _dummyPrimitive; - public static Microsoft.AspNetCore.Components.ParameterCollection Empty { get { throw null; } } - public static Microsoft.AspNetCore.Components.ParameterCollection FromDictionary(System.Collections.Generic.IDictionary parameters) { throw null; } - public Microsoft.AspNetCore.Components.ParameterEnumerator GetEnumerator() { throw null; } - public T GetValueOrDefault(string parameterName) { throw null; } - public T GetValueOrDefault(string parameterName, T defaultValue) { throw null; } - public System.Collections.Generic.IReadOnlyDictionary ToDictionary() { throw null; } - public bool TryGetValue(string parameterName, out T result) { throw null; } - } - public static partial class ParameterCollectionExtensions - { - public static void SetParameterProperties(this in Microsoft.AspNetCore.Components.ParameterCollection parameterCollection, object target) { } + public bool Cascading { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } } + public string Name { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } } + public object Value { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } } } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] - public partial struct ParameterEnumerator + public readonly partial struct ParameterView { - private object _dummy; - private int _dummyPrimitive; - public Microsoft.AspNetCore.Components.Parameter Current { get { throw null; } } - public bool MoveNext() { throw null; } + private readonly object _dummy; + private readonly int _dummyPrimitive; + public static Microsoft.AspNetCore.Components.ParameterView Empty { get { throw null; } } + public static Microsoft.AspNetCore.Components.ParameterView FromDictionary(System.Collections.Generic.IDictionary parameters) { throw null; } + public Microsoft.AspNetCore.Components.ParameterView.Enumerator GetEnumerator() { throw null; } + public T GetValueOrDefault(string parameterName) { throw null; } + public T GetValueOrDefault(string parameterName, T defaultValue) { throw null; } + public void SetParameterProperties(object target) { } + public System.Collections.Generic.IReadOnlyDictionary ToDictionary() { throw null; } + public bool TryGetValue(string parameterName, out T result) { throw null; } + [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] + public partial struct Enumerator + { + private object _dummy; + private int _dummyPrimitive; + public Microsoft.AspNetCore.Components.ParameterValue Current { get { throw null; } } + public bool MoveNext() { throw null; } + } } public delegate void RenderFragment(Microsoft.AspNetCore.Components.RenderTree.RenderTreeBuilder builder); public delegate Microsoft.AspNetCore.Components.RenderFragment RenderFragment(T value); @@ -502,8 +499,8 @@ namespace Microsoft.AspNetCore.Components.Rendering public override Microsoft.AspNetCore.Components.Dispatcher Dispatcher { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } } protected override void HandleException(System.Exception exception) { } [System.Diagnostics.DebuggerStepThroughAttribute] - public System.Threading.Tasks.Task RenderComponentAsync(System.Type componentType, Microsoft.AspNetCore.Components.ParameterCollection initialParameters) { throw null; } - public System.Threading.Tasks.Task RenderComponentAsync(Microsoft.AspNetCore.Components.ParameterCollection initialParameters) where TComponent : Microsoft.AspNetCore.Components.IComponent { throw null; } + public System.Threading.Tasks.Task RenderComponentAsync(System.Type componentType, Microsoft.AspNetCore.Components.ParameterView initialParameters) { throw null; } + public System.Threading.Tasks.Task RenderComponentAsync(Microsoft.AspNetCore.Components.ParameterView initialParameters) where TComponent : Microsoft.AspNetCore.Components.IComponent { throw null; } protected override System.Threading.Tasks.Task UpdateDisplayAsync(in Microsoft.AspNetCore.Components.Rendering.RenderBatch renderBatch) { throw null; } } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] @@ -529,7 +526,7 @@ namespace Microsoft.AspNetCore.Components.Rendering protected Microsoft.AspNetCore.Components.IComponent InstantiateComponent(System.Type componentType) { throw null; } protected System.Threading.Tasks.Task RenderRootComponentAsync(int componentId) { throw null; } [System.Diagnostics.DebuggerStepThroughAttribute] - protected System.Threading.Tasks.Task RenderRootComponentAsync(int componentId, Microsoft.AspNetCore.Components.ParameterCollection initialParameters) { throw null; } + protected System.Threading.Tasks.Task RenderRootComponentAsync(int componentId, Microsoft.AspNetCore.Components.ParameterView initialParameters) { throw null; } protected abstract System.Threading.Tasks.Task UpdateDisplayAsync(in Microsoft.AspNetCore.Components.Rendering.RenderBatch renderBatch); } } @@ -663,6 +660,6 @@ namespace Microsoft.AspNetCore.Components.Routing public void Dispose() { } System.Threading.Tasks.Task Microsoft.AspNetCore.Components.IHandleAfterRender.OnAfterRenderAsync() { throw null; } protected virtual void Render(Microsoft.AspNetCore.Components.RenderTree.RenderTreeBuilder builder, System.Type handler, System.Collections.Generic.IDictionary parameters) { } - public System.Threading.Tasks.Task SetParametersAsync(Microsoft.AspNetCore.Components.ParameterCollection parameters) { throw null; } + public System.Threading.Tasks.Task SetParametersAsync(Microsoft.AspNetCore.Components.ParameterView parameters) { throw null; } } } diff --git a/src/Components/Components/src/CascadingParameterState.cs b/src/Components/Components/src/CascadingParameterState.cs index 453fb9692d..8c3e445a86 100644 --- a/src/Components/Components/src/CascadingParameterState.cs +++ b/src/Components/Components/src/CascadingParameterState.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 Microsoft.AspNetCore.Components.Reflection; using Microsoft.AspNetCore.Components.Rendering; using System; using System.Collections.Concurrent; @@ -89,7 +90,7 @@ namespace Microsoft.AspNetCore.Components private static ReflectedCascadingParameterInfo[] CreateReflectedCascadingParameterInfos(Type componentType) { List result = null; - var candidateProps = ParameterCollectionExtensions.GetCandidateBindableProperties(componentType); + var candidateProps = ComponentProperties.GetCandidateBindableProperties(componentType); foreach (var prop in candidateProps) { var attribute = prop.GetCustomAttribute(); diff --git a/src/Components/Components/src/CascadingValue.cs b/src/Components/Components/src/CascadingValue.cs index 02082856f0..1a03c2557e 100644 --- a/src/Components/Components/src/CascadingValue.cs +++ b/src/Components/Components/src/CascadingValue.cs @@ -56,7 +56,7 @@ namespace Microsoft.AspNetCore.Components } /// - public Task SetParametersAsync(ParameterCollection parameters) + public Task SetParametersAsync(ParameterView parameters) { // Implementing the parameter binding manually, instead of just calling // parameters.SetParameterProperties(this), is just a very slight perf optimization @@ -110,7 +110,7 @@ namespace Microsoft.AspNetCore.Components // because it serves no useful purpose to have a otherwise. if (!hasSuppliedValue) { - throw new ArgumentException($"Missing required parameter '{nameof(Value)}' for component '{nameof(Parameter)}'."); + throw new ArgumentException($"Missing required parameter '{nameof(Value)}' for component '{GetType().Name}'."); } // Rendering is most efficient when things are queued from rootmost to leafmost. diff --git a/src/Components/Components/src/ComponentBase.cs b/src/Components/Components/src/ComponentBase.cs index 23dd8734e7..baa91fd458 100644 --- a/src/Components/Components/src/ComponentBase.cs +++ b/src/Components/Components/src/ComponentBase.cs @@ -175,7 +175,7 @@ namespace Microsoft.AspNetCore.Components /// Method invoked to apply initial or updated parameters to the component. /// /// The parameters to apply. - public virtual Task SetParametersAsync(ParameterCollection parameters) + public virtual Task SetParametersAsync(ParameterView parameters) { parameters.SetParameterProperties(this); if (!_initialized) diff --git a/src/Components/Components/src/IComponent.cs b/src/Components/Components/src/IComponent.cs index c06dbb193e..ec1059b1e6 100644 --- a/src/Components/Components/src/IComponent.cs +++ b/src/Components/Components/src/IComponent.cs @@ -21,6 +21,6 @@ namespace Microsoft.AspNetCore.Components /// /// The parameters. /// A that completes when the component has finished updating and rendering itself. - Task SetParametersAsync(ParameterCollection parameters); + Task SetParametersAsync(ParameterView parameters); } } diff --git a/src/Components/Components/src/PageDisplay.cs b/src/Components/Components/src/PageDisplay.cs index 1a1703117c..61abc70697 100644 --- a/src/Components/Components/src/PageDisplay.cs +++ b/src/Components/Components/src/PageDisplay.cs @@ -51,7 +51,7 @@ namespace Microsoft.AspNetCore.Components } /// - public Task SetParametersAsync(ParameterCollection parameters) + public Task SetParametersAsync(ParameterView parameters) { parameters.SetParameterProperties(this); Render(); diff --git a/src/Components/Components/src/ParameterEnumerator.cs b/src/Components/Components/src/ParameterEnumerator.cs deleted file mode 100644 index 6abc92e8a1..0000000000 --- a/src/Components/Components/src/ParameterEnumerator.cs +++ /dev/null @@ -1,137 +0,0 @@ -// 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 Microsoft.AspNetCore.Components.RenderTree; -using System; -using System.Collections.Generic; - -namespace Microsoft.AspNetCore.Components -{ - /// - /// An enumerator that iterates through a . - /// - public struct ParameterEnumerator - { - private RenderTreeFrameParameterEnumerator _directParamsEnumerator; - private CascadingParameterEnumerator _cascadingParameterEnumerator; - private bool _isEnumeratingDirectParams; - - internal ParameterEnumerator(RenderTreeFrame[] frames, int ownerIndex, IReadOnlyList cascadingParameters) - { - _directParamsEnumerator = new RenderTreeFrameParameterEnumerator(frames, ownerIndex); - _cascadingParameterEnumerator = new CascadingParameterEnumerator(cascadingParameters); - _isEnumeratingDirectParams = true; - } - - /// - /// Gets the current value of the enumerator. - /// - public Parameter Current => _isEnumeratingDirectParams - ? _directParamsEnumerator.Current - : _cascadingParameterEnumerator.Current; - - /// - /// Instructs the enumerator to move to the next value in the sequence. - /// - /// A flag to indicate whether or not there is a next value. - public bool MoveNext() - { - if (_isEnumeratingDirectParams) - { - if (_directParamsEnumerator.MoveNext()) - { - return true; - } - else - { - _isEnumeratingDirectParams = false; - } - } - - return _cascadingParameterEnumerator.MoveNext(); - } - - struct RenderTreeFrameParameterEnumerator - { - private readonly RenderTreeFrame[] _frames; - private readonly int _ownerIndex; - private readonly int _ownerDescendantsEndIndexExcl; - private int _currentIndex; - private Parameter _current; - - internal RenderTreeFrameParameterEnumerator(RenderTreeFrame[] frames, int ownerIndex) - { - _frames = frames; - _ownerIndex = ownerIndex; - _ownerDescendantsEndIndexExcl = ownerIndex + _frames[ownerIndex].ElementSubtreeLength; - _currentIndex = ownerIndex; - _current = default; - } - - public Parameter Current => _current; - - public bool MoveNext() - { - // Stop iteration if you get to the end of the owner's descendants... - var nextIndex = _currentIndex + 1; - if (nextIndex == _ownerDescendantsEndIndexExcl) - { - return false; - } - - // ... or if you get to its first non-attribute descendant (because attributes - // are always before any other type of descendant) - if (_frames[nextIndex].FrameType != RenderTreeFrameType.Attribute) - { - return false; - } - - _currentIndex = nextIndex; - - ref var frame = ref _frames[_currentIndex]; - _current = new Parameter(frame.AttributeName, frame.AttributeValue, false); - - return true; - } - } - - struct CascadingParameterEnumerator - { - private readonly IReadOnlyList _cascadingParameters; - private int _currentIndex; - private Parameter _current; - - public CascadingParameterEnumerator(IReadOnlyList cascadingParameters) - { - _cascadingParameters = cascadingParameters; - _currentIndex = -1; - _current = default; - } - - public Parameter Current => _current; - - public bool MoveNext() - { - // Bail out early if there are no cascading parameters - if (_cascadingParameters == null) - { - return false; - } - - var nextIndex = _currentIndex + 1; - if (nextIndex < _cascadingParameters.Count) - { - _currentIndex = nextIndex; - - var state = _cascadingParameters[_currentIndex]; - _current = new Parameter(state.LocalValueName, state.ValueSupplier.CurrentValue, true); - return true; - } - else - { - return false; - } - } - } - } -} diff --git a/src/Components/Components/src/Parameter.cs b/src/Components/Components/src/ParameterValue.cs similarity index 89% rename from src/Components/Components/src/Parameter.cs rename to src/Components/Components/src/ParameterValue.cs index 3ba8cdff2f..c080880de2 100644 --- a/src/Components/Components/src/Parameter.cs +++ b/src/Components/Components/src/ParameterValue.cs @@ -7,8 +7,15 @@ namespace Microsoft.AspNetCore.Components /// Represents a single parameter supplied to an /// by its parent in the render tree. /// - public readonly struct Parameter + public readonly struct ParameterValue { + internal ParameterValue(string name, object value, bool cascading) + { + Name = name; + Value = value; + Cascading = cascading; + } + /// /// Gets the name of the parameter. /// @@ -24,12 +31,5 @@ namespace Microsoft.AspNetCore.Components /// 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/Components/Components/src/ParameterCollection.cs b/src/Components/Components/src/ParameterView.cs similarity index 54% rename from src/Components/Components/src/ParameterCollection.cs rename to src/Components/Components/src/ParameterView.cs index a929c8071e..3d682cc09c 100644 --- a/src/Components/Components/src/ParameterCollection.cs +++ b/src/Components/Components/src/ParameterView.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using Microsoft.AspNetCore.Components.Reflection; using Microsoft.AspNetCore.Components.RenderTree; namespace Microsoft.AspNetCore.Components @@ -11,27 +12,26 @@ namespace Microsoft.AspNetCore.Components /// Represents a collection of parameters supplied to an /// by its parent in the render tree. /// - public readonly struct ParameterCollection + public readonly struct ParameterView { - private const string GeneratedParameterCollectionElementName = "__ARTIFICIAL_PARAMETER_COLLECTION"; - private static readonly RenderTreeFrame[] _emptyCollectionFrames = new RenderTreeFrame[] + private const string GeneratedParameterViewElementName = "__ARTIFICIAL_PARAMETER_VIEW"; + private static readonly RenderTreeFrame[] _emptyFrames = new RenderTreeFrame[] { RenderTreeFrame.Element(0, string.Empty).WithComponentSubtreeLength(1) }; - private static readonly ParameterCollection _emptyCollection - = new ParameterCollection(_emptyCollectionFrames, 0, null); + private static readonly ParameterView _empty = new ParameterView(_emptyFrames, 0, null); private readonly RenderTreeFrame[] _frames; private readonly int _ownerIndex; private readonly IReadOnlyList _cascadingParametersOrNull; - internal ParameterCollection(RenderTreeFrame[] frames, int ownerIndex) + internal ParameterView(RenderTreeFrame[] frames, int ownerIndex) : this(frames, ownerIndex, null) { } - private ParameterCollection(RenderTreeFrame[] frames, int ownerIndex, IReadOnlyList cascadingParametersOrNull) + private ParameterView(RenderTreeFrame[] frames, int ownerIndex, IReadOnlyList cascadingParametersOrNull) { _frames = frames; _ownerIndex = ownerIndex; @@ -39,16 +39,16 @@ namespace Microsoft.AspNetCore.Components } /// - /// Gets an empty . + /// Gets an empty . /// - public static ParameterCollection Empty => _emptyCollection; + public static ParameterView Empty => _empty; /// - /// Returns an enumerator that iterates through the . + /// Returns an enumerator that iterates through the . /// /// The enumerator. - public ParameterEnumerator GetEnumerator() - => new ParameterEnumerator(_frames, _ownerIndex, _cascadingParametersOrNull); + public Enumerator GetEnumerator() + => new Enumerator(_frames, _ownerIndex, _cascadingParametersOrNull); /// /// Gets the value of the parameter with the specified name. @@ -94,9 +94,9 @@ namespace Microsoft.AspNetCore.Components => TryGetValue(parameterName, out T result) ? result : defaultValue; /// - /// Returns a dictionary populated with the contents of the . + /// Returns a dictionary populated with the contents of the . /// - /// A dictionary populated with the contents of the . + /// A dictionary populated with the contents of the . public IReadOnlyDictionary ToDictionary() { var result = new Dictionary(); @@ -107,13 +107,13 @@ namespace Microsoft.AspNetCore.Components return result; } - internal ParameterCollection WithCascadingParameters(IReadOnlyList cascadingParameters) - => new ParameterCollection(_frames, _ownerIndex, cascadingParameters); + internal ParameterView WithCascadingParameters(IReadOnlyList cascadingParameters) + => new ParameterView(_frames, _ownerIndex, cascadingParameters); // It's internal because there isn't a known use case for user code comparing - // ParameterCollection instances, and even if there was, it's unlikely it should + // ParameterView instances, and even if there was, it's unlikely it should // use these equality rules which are designed for their effect on rendering. - internal bool DefinitelyEquals(ParameterCollection oldParameters) + internal bool DefinitelyEquals(ParameterView oldParameters) { // In general we can't detect mutations on arbitrary objects. We can't trust // things like .Equals or .GetHashCode because they usually only tell us about @@ -187,7 +187,7 @@ namespace Microsoft.AspNetCore.Components } // We need to prefix the captured frames with an "owner" frame that - // describes the length of the buffer so that ParameterCollection + // describes the length of the buffer so that ParameterView // knows how far to iterate through it. var owner = RenderTreeFrame.PlaceholderChildComponentWithSubtreeLength(1 + numEntries); builder.Append(owner); @@ -199,14 +199,14 @@ namespace Microsoft.AspNetCore.Components } /// - /// Creates a new from the given . + /// Creates a new from the given . /// /// The with the parameters. - /// A . - public static ParameterCollection FromDictionary(IDictionary parameters) + /// A . + public static ParameterView FromDictionary(IDictionary parameters) { var frames = new RenderTreeFrame[parameters.Count + 1]; - frames[0] = RenderTreeFrame.Element(0, GeneratedParameterCollectionElementName) + frames[0] = RenderTreeFrame.Element(0, GeneratedParameterViewElementName) .WithElementSubtreeLength(frames.Length); var i = 0; @@ -215,7 +215,153 @@ namespace Microsoft.AspNetCore.Components frames[++i] = RenderTreeFrame.Attribute(i, kvp.Key, kvp.Value); } - return new ParameterCollection(frames, 0); + return new ParameterView(frames, 0); + } + + /// + /// For each parameter property on , updates its value to + /// match the corresponding entry in the . + /// + /// An object that has a public writable property matching each parameter's name and type. + public void SetParameterProperties(object target) + { + if (target is null) + { + throw new ArgumentNullException(nameof(target)); + } + + ComponentProperties.SetProperties(this, target); + } + + /// + /// An enumerator that iterates through a . + /// + + // Note that this intentionally does not implement IEnumerator<>. This is the same pattern as Span<>.Enumerator + // it's valid to foreach over a type that doesn't implement IEnumerator<>. + public struct Enumerator + { + private RenderTreeFrameParameterEnumerator _directParamsEnumerator; + private CascadingParameterEnumerator _cascadingParameterEnumerator; + private bool _isEnumeratingDirectParams; + + internal Enumerator(RenderTreeFrame[] frames, int ownerIndex, IReadOnlyList cascadingParameters) + { + _directParamsEnumerator = new RenderTreeFrameParameterEnumerator(frames, ownerIndex); + _cascadingParameterEnumerator = new CascadingParameterEnumerator(cascadingParameters); + _isEnumeratingDirectParams = true; + } + + /// + /// Gets the current value of the enumerator. + /// + public ParameterValue Current => _isEnumeratingDirectParams + ? _directParamsEnumerator.Current + : _cascadingParameterEnumerator.Current; + + /// + /// Instructs the enumerator to move to the next value in the sequence. + /// + /// A flag to indicate whether or not there is a next value. + public bool MoveNext() + { + if (_isEnumeratingDirectParams) + { + if (_directParamsEnumerator.MoveNext()) + { + return true; + } + else + { + _isEnumeratingDirectParams = false; + } + } + + return _cascadingParameterEnumerator.MoveNext(); + } + } + + private struct RenderTreeFrameParameterEnumerator + { + private readonly RenderTreeFrame[] _frames; + private readonly int _ownerIndex; + private readonly int _ownerDescendantsEndIndexExcl; + private int _currentIndex; + private ParameterValue _current; + + internal RenderTreeFrameParameterEnumerator(RenderTreeFrame[] frames, int ownerIndex) + { + _frames = frames; + _ownerIndex = ownerIndex; + _ownerDescendantsEndIndexExcl = ownerIndex + _frames[ownerIndex].ElementSubtreeLength; + _currentIndex = ownerIndex; + _current = default; + } + + public ParameterValue Current => _current; + + public bool MoveNext() + { + // Stop iteration if you get to the end of the owner's descendants... + var nextIndex = _currentIndex + 1; + if (nextIndex == _ownerDescendantsEndIndexExcl) + { + return false; + } + + // ... or if you get to its first non-attribute descendant (because attributes + // are always before any other type of descendant) + if (_frames[nextIndex].FrameType != RenderTreeFrameType.Attribute) + { + return false; + } + + _currentIndex = nextIndex; + + ref var frame = ref _frames[_currentIndex]; + _current = new ParameterValue(frame.AttributeName, frame.AttributeValue, false); + + return true; + } + } + + private struct CascadingParameterEnumerator + { + private readonly IReadOnlyList _cascadingParameters; + private int _currentIndex; + private ParameterValue _current; + + public CascadingParameterEnumerator(IReadOnlyList cascadingParameters) + { + _cascadingParameters = cascadingParameters; + _currentIndex = -1; + _current = default; + } + + public ParameterValue Current => _current; + + public bool MoveNext() + { + // Bail out early if there are no cascading parameters + if (_cascadingParameters == null) + { + return false; + } + + var nextIndex = _currentIndex + 1; + if (nextIndex < _cascadingParameters.Count) + { + _currentIndex = nextIndex; + + var state = _cascadingParameters[_currentIndex]; + _current = new ParameterValue(state.LocalValueName, state.ValueSupplier.CurrentValue, true); + return true; + } + else + { + return false; + } + } } } } diff --git a/src/Components/Components/src/ParameterCollectionExtensions.cs b/src/Components/Components/src/Reflection/ComponentProperties.cs similarity index 92% rename from src/Components/Components/src/ParameterCollectionExtensions.cs rename to src/Components/Components/src/Reflection/ComponentProperties.cs index fb23b5de49..5caeab20b1 100644 --- a/src/Components/Components/src/ParameterCollectionExtensions.cs +++ b/src/Components/Components/src/Reflection/ComponentProperties.cs @@ -7,29 +7,17 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; -using Microsoft.AspNetCore.Components.Reflection; -namespace Microsoft.AspNetCore.Components +namespace Microsoft.AspNetCore.Components.Reflection { - /// - /// Extension methods for the type. - /// - public static class ParameterCollectionExtensions + internal static class ComponentProperties { private const BindingFlags _bindablePropertyFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.IgnoreCase; private readonly static ConcurrentDictionary _cachedWritersByType = new ConcurrentDictionary(); - /// - /// For each parameter property on , updates its value to - /// match the corresponding entry in the . - /// - /// The . - /// An object that has a public writable property matching each parameter's name and type. - public static void SetParameterProperties( - in this ParameterCollection parameterCollection, - object target) + public static void SetProperties(in ParameterView parameters, object target) { if (target == null) { @@ -47,7 +35,7 @@ namespace Microsoft.AspNetCore.Components if (writers.CaptureUnmatchedValuesWriter == null) { // Logic for components without a CaptureUnmatchedValues parameter - foreach (var parameter in parameterCollection) + foreach (var parameter in parameters) { var parameterName = parameter.Name; if (!writers.WritersByName.TryGetValue(parameterName, out var writer)) @@ -65,7 +53,7 @@ namespace Microsoft.AspNetCore.Components // Logic with components with a CaptureUnmatchedValues parameter var isCaptureUnmatchedValuesParameterSetExplicitly = false; Dictionary unmatched = null; - foreach (var parameter in parameterCollection) + foreach (var parameter in parameters) { var parameterName = parameter.Name; if (string.Equals(parameterName, writers.CaptureUnmatchedValuesPropertyName, StringComparison.OrdinalIgnoreCase)) diff --git a/src/Components/Components/src/RenderTree/RenderTreeDiffBuilder.cs b/src/Components/Components/src/RenderTree/RenderTreeDiffBuilder.cs index 632334fcc0..517b4b65ab 100644 --- a/src/Components/Components/src/RenderTree/RenderTreeDiffBuilder.cs +++ b/src/Components/Components/src/RenderTree/RenderTreeDiffBuilder.cs @@ -520,8 +520,8 @@ namespace Microsoft.AspNetCore.Components.RenderTree // comparisons it wants with the old values. Later we could choose to pass the // old parameter values if we wanted. By default, components always rerender // after any SetParameters call, which is safe but now always optimal for perf. - var oldParameters = new ParameterCollection(oldTree, oldComponentIndex); - var newParameters = new ParameterCollection(newTree, newComponentIndex); + var oldParameters = new ParameterView(oldTree, oldComponentIndex); + var newParameters = new ParameterView(newTree, newComponentIndex); if (!newParameters.DefinitelyEquals(oldParameters)) { componentState.SetDirectParameters(newParameters); @@ -894,7 +894,7 @@ namespace Microsoft.AspNetCore.Components.RenderTree var childComponentState = frame.ComponentState; // Set initial parameters - var initialParameters = new ParameterCollection(frames, frameIndex); + var initialParameters = new ParameterView(frames, frameIndex); childComponentState.SetDirectParameters(initialParameters); } diff --git a/src/Components/Components/src/Rendering/ComponentState.cs b/src/Components/Components/src/Rendering/ComponentState.cs index b9ad1605f6..a0609b9331 100644 --- a/src/Components/Components/src/Rendering/ComponentState.cs +++ b/src/Components/Components/src/Rendering/ComponentState.cs @@ -105,7 +105,7 @@ namespace Microsoft.AspNetCore.Components.Rendering return Task.CompletedTask; } - public void SetDirectParameters(ParameterCollection parameters) + public void SetDirectParameters(ParameterView parameters) { // Note: We should be careful to ensure that the framework never calls // IComponent.SetParameters directly elsewhere. We should only call it @@ -137,8 +137,8 @@ namespace Microsoft.AspNetCore.Components.Rendering public void NotifyCascadingValueChanged() { var directParams = _latestDirectParametersSnapshot != null - ? new ParameterCollection(_latestDirectParametersSnapshot.Buffer, 0) - : ParameterCollection.Empty; + ? new ParameterView(_latestDirectParametersSnapshot.Buffer, 0) + : ParameterView.Empty; var allParams = directParams.WithCascadingParameters(_cascadingParameters); var task = Component.SetParametersAsync(allParams); _renderer.AddToPendingTasks(task); diff --git a/src/Components/Components/src/Rendering/HtmlRenderer.cs b/src/Components/Components/src/Rendering/HtmlRenderer.cs index 13015c0ffe..c5c77e5169 100644 --- a/src/Components/Components/src/Rendering/HtmlRenderer.cs +++ b/src/Components/Components/src/Rendering/HtmlRenderer.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.Diagnostics; -using System.Runtime.CompilerServices; using System.Runtime.ExceptionServices; using System.Threading.Tasks; using Microsoft.AspNetCore.Components.RenderTree; @@ -49,9 +48,9 @@ namespace Microsoft.AspNetCore.Components.Rendering /// of the HTML produced by the component. /// /// The type of the . - /// A with the initial parameters to render the component. + /// A with the initial parameters to render the component. /// A that on completion returns a sequence of fragments that represent the HTML text of the component. - public async Task RenderComponentAsync(Type componentType, ParameterCollection initialParameters) + public async Task RenderComponentAsync(Type componentType, ParameterView initialParameters) { var (componentId, frames) = await CreateInitialRenderAsync(componentType, initialParameters); @@ -66,9 +65,9 @@ namespace Microsoft.AspNetCore.Components.Rendering /// of the HTML produced by the component. /// /// The type of the . - /// A with the initial parameters to render the component. + /// A with the initial parameters to render the component. /// A that on completion returns a sequence of fragments that represent the HTML text of the component. - public Task RenderComponentAsync(ParameterCollection initialParameters) where TComponent : IComponent + public Task RenderComponentAsync(ParameterView initialParameters) where TComponent : IComponent { return RenderComponentAsync(typeof(TComponent), initialParameters); } @@ -224,7 +223,7 @@ namespace Microsoft.AspNetCore.Components.Rendering return position + maxElements; } - private async Task<(int, ArrayRange)> CreateInitialRenderAsync(Type componentType, ParameterCollection initialParameters) + private async Task<(int, ArrayRange)> CreateInitialRenderAsync(Type componentType, ParameterView initialParameters) { var component = InstantiateComponent(componentType); var componentId = AssignRootComponentId(component); diff --git a/src/Components/Components/src/Rendering/Renderer.cs b/src/Components/Components/src/Rendering/Renderer.cs index 605a72a125..83505bd61e 100644 --- a/src/Components/Components/src/Rendering/Renderer.cs +++ b/src/Components/Components/src/Rendering/Renderer.cs @@ -109,7 +109,7 @@ namespace Microsoft.AspNetCore.Components.Rendering /// protected Task RenderRootComponentAsync(int componentId) { - return RenderRootComponentAsync(componentId, ParameterCollection.Empty); + return RenderRootComponentAsync(componentId, ParameterView.Empty); } /// @@ -120,12 +120,12 @@ namespace Microsoft.AspNetCore.Components.Rendering /// this more than once. /// /// The ID returned by . - /// The with the initial parameters to use for rendering. + /// The with the initial parameters to use for rendering. /// /// Rendering a root component is an asynchronous operation. Clients may choose to not await the returned task to /// start, but not wait for the entire render to complete. /// - protected async Task RenderRootComponentAsync(int componentId, ParameterCollection initialParameters) + protected async Task RenderRootComponentAsync(int componentId, ParameterView initialParameters) { if (Interlocked.CompareExchange(ref _pendingTasks, new List(), null) != null) { diff --git a/src/Components/Components/src/Routing/Router.cs b/src/Components/Components/src/Routing/Router.cs index 7c49316ada..c1459063e7 100644 --- a/src/Components/Components/src/Routing/Router.cs +++ b/src/Components/Components/src/Routing/Router.cs @@ -66,7 +66,7 @@ namespace Microsoft.AspNetCore.Components.Routing } /// - public Task SetParametersAsync(ParameterCollection parameters) + public Task SetParametersAsync(ParameterView parameters) { parameters.SetParameterProperties(this); Routes = RouteTableFactory.Create(AppAssembly); diff --git a/src/Components/Components/test/CascadingParameterStateTest.cs b/src/Components/Components/test/CascadingParameterStateTest.cs index 12ed03a445..5931d9d6fc 100644 --- a/src/Components/Components/test/CascadingParameterStateTest.cs +++ b/src/Components/Components/test/CascadingParameterStateTest.cs @@ -386,7 +386,7 @@ namespace Microsoft.AspNetCore.Components.Test supplierParams.Add("Name", name); } - renderer.Dispatcher.InvokeAsync((Action)(() => supplier.SetParametersAsync(ParameterCollection.FromDictionary(supplierParams)))); + renderer.Dispatcher.InvokeAsync((Action)(() => supplier.SetParametersAsync(ParameterView.FromDictionary(supplierParams)))); return supplier; } @@ -427,7 +427,7 @@ namespace Microsoft.AspNetCore.Components.Test public void Attach(RenderHandle renderHandle) => throw new NotImplementedException(); - public Task SetParametersAsync(ParameterCollection parameters) + public Task SetParametersAsync(ParameterView parameters) => throw new NotImplementedException(); } diff --git a/src/Components/Components/test/CascadingParameterTest.cs b/src/Components/Components/test/CascadingParameterTest.cs index d40c4d70c8..1e05b98f68 100644 --- a/src/Components/Components/test/CascadingParameterTest.cs +++ b/src/Components/Components/test/CascadingParameterTest.cs @@ -383,7 +383,7 @@ namespace Microsoft.AspNetCore.Components.Test [CascadingParameter] T CascadingParameter { get; set; } [Parameter] public string RegularParameter { get; set; } - public override async Task SetParametersAsync(ParameterCollection parameters) + public override async Task SetParametersAsync(ParameterView parameters) { NumSetParametersCalls++; await base.SetParametersAsync(parameters); diff --git a/src/Components/Components/test/ComponentFactoryTest.cs b/src/Components/Components/test/ComponentFactoryTest.cs index 0d77c0f24a..4dd4de56e0 100644 --- a/src/Components/Components/test/ComponentFactoryTest.cs +++ b/src/Components/Components/test/ComponentFactoryTest.cs @@ -103,7 +103,7 @@ namespace Microsoft.AspNetCore.Components throw new NotImplementedException(); } - public Task SetParametersAsync(ParameterCollection parameters) + public Task SetParametersAsync(ParameterView parameters) { throw new NotImplementedException(); } @@ -130,7 +130,7 @@ namespace Microsoft.AspNetCore.Components throw new NotImplementedException(); } - public Task SetParametersAsync(ParameterCollection parameters) + public Task SetParametersAsync(ParameterView parameters) { throw new NotImplementedException(); } @@ -148,7 +148,7 @@ namespace Microsoft.AspNetCore.Components throw new NotImplementedException(); } - public Task SetParametersAsync(ParameterCollection parameters) + public Task SetParametersAsync(ParameterView parameters) { throw new NotImplementedException(); } diff --git a/src/Components/Components/test/DependencyInjectionTest.cs b/src/Components/Components/test/DependencyInjectionTest.cs index fedbcba993..2a77c75325 100644 --- a/src/Components/Components/test/DependencyInjectionTest.cs +++ b/src/Components/Components/test/DependencyInjectionTest.cs @@ -197,7 +197,7 @@ namespace Microsoft.AspNetCore.Components.Test public void Attach(RenderHandle renderHandle) => throw new NotImplementedException(); - public Task SetParametersAsync(ParameterCollection parameters) + public Task SetParametersAsync(ParameterView parameters) => throw new NotImplementedException(); } } diff --git a/src/Components/Components/test/EventCallbackFactoryBinderExtensionsTest.cs b/src/Components/Components/test/EventCallbackFactoryBinderExtensionsTest.cs index 220e9285ab..0a588259cc 100644 --- a/src/Components/Components/test/EventCallbackFactoryBinderExtensionsTest.cs +++ b/src/Components/Components/test/EventCallbackFactoryBinderExtensionsTest.cs @@ -667,7 +667,7 @@ namespace Microsoft.AspNetCore.Components throw new System.NotImplementedException(); } - public Task SetParametersAsync(ParameterCollection parameters) + public Task SetParametersAsync(ParameterView parameters) { throw new System.NotImplementedException(); } diff --git a/src/Components/Components/test/EventCallbackFactoryTest.cs b/src/Components/Components/test/EventCallbackFactoryTest.cs index dc9a3bfd30..69b7bfa748 100644 --- a/src/Components/Components/test/EventCallbackFactoryTest.cs +++ b/src/Components/Components/test/EventCallbackFactoryTest.cs @@ -645,7 +645,7 @@ namespace Microsoft.AspNetCore.Components throw new NotImplementedException(); } - public Task SetParametersAsync(ParameterCollection parameters) + public Task SetParametersAsync(ParameterView parameters) { throw new NotImplementedException(); } diff --git a/src/Components/Components/test/EventCallbackTest.cs b/src/Components/Components/test/EventCallbackTest.cs index e390735fa8..6fc1e601ca 100644 --- a/src/Components/Components/test/EventCallbackTest.cs +++ b/src/Components/Components/test/EventCallbackTest.cs @@ -451,7 +451,7 @@ namespace Microsoft.AspNetCore.Components public void Attach(RenderHandle renderHandle) => throw new NotImplementedException(); - public Task SetParametersAsync(ParameterCollection parameters) => throw new NotImplementedException(); + public Task SetParametersAsync(ParameterView parameters) => throw new NotImplementedException(); } } } diff --git a/src/Components/Components/test/PageDisplayTest.cs b/src/Components/Components/test/PageDisplayTest.cs index e73e7e7083..9b28d95d23 100644 --- a/src/Components/Components/test/PageDisplayTest.cs +++ b/src/Components/Components/test/PageDisplayTest.cs @@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.Components.Test public void DisplaysComponentInsideLayout() { // Arrange/Act - _renderer.Dispatcher.InvokeAsync(() => _pageDisplayComponent.SetParametersAsync(ParameterCollection.FromDictionary(new Dictionary + _renderer.Dispatcher.InvokeAsync(() => _pageDisplayComponent.SetParametersAsync(ParameterView.FromDictionary(new Dictionary { { nameof(PageDisplay.Page), typeof(ComponentWithLayout) } }))); @@ -84,7 +84,7 @@ namespace Microsoft.AspNetCore.Components.Test public void DisplaysComponentInsideNestedLayout() { // Arrange/Act - _renderer.Dispatcher.InvokeAsync(() => _pageDisplayComponent.SetParametersAsync(ParameterCollection.FromDictionary(new Dictionary + _renderer.Dispatcher.InvokeAsync(() => _pageDisplayComponent.SetParametersAsync(ParameterView.FromDictionary(new Dictionary { { nameof(PageDisplay.Page), typeof(ComponentWithNestedLayout) } }))); @@ -111,13 +111,13 @@ namespace Microsoft.AspNetCore.Components.Test public void CanChangeDisplayedPageWithSameLayout() { // Arrange - _renderer.Dispatcher.InvokeAsync(() => _pageDisplayComponent.SetParametersAsync(ParameterCollection.FromDictionary(new Dictionary + _renderer.Dispatcher.InvokeAsync(() => _pageDisplayComponent.SetParametersAsync(ParameterView.FromDictionary(new Dictionary { { nameof(PageDisplay.Page), typeof(ComponentWithLayout) } }))); // Act - _renderer.Dispatcher.InvokeAsync(() => _pageDisplayComponent.SetParametersAsync(ParameterCollection.FromDictionary(new Dictionary + _renderer.Dispatcher.InvokeAsync(() => _pageDisplayComponent.SetParametersAsync(ParameterView.FromDictionary(new Dictionary { { nameof(PageDisplay.Page), typeof(DifferentComponentWithLayout) } }))); @@ -162,13 +162,13 @@ namespace Microsoft.AspNetCore.Components.Test public void CanChangeDisplayedPageWithDifferentLayout() { // Arrange - _renderer.Dispatcher.InvokeAsync(() => _pageDisplayComponent.SetParametersAsync(ParameterCollection.FromDictionary(new Dictionary + _renderer.Dispatcher.InvokeAsync(() => _pageDisplayComponent.SetParametersAsync(ParameterView.FromDictionary(new Dictionary { { nameof(PageDisplay.Page), typeof(ComponentWithLayout) } }))); // Act - _renderer.Dispatcher.InvokeAsync(() => _pageDisplayComponent.SetParametersAsync(ParameterCollection.FromDictionary(new Dictionary + _renderer.Dispatcher.InvokeAsync(() => _pageDisplayComponent.SetParametersAsync(ParameterView.FromDictionary(new Dictionary { { nameof(PageDisplay.Page), typeof(ComponentWithNestedLayout) } }))); diff --git a/src/Components/Components/test/ParameterCollectionAssignmentExtensionsTest.cs b/src/Components/Components/test/ParameterViewTest.Assignment.cs similarity index 84% rename from src/Components/Components/test/ParameterCollectionAssignmentExtensionsTest.cs rename to src/Components/Components/test/ParameterViewTest.Assignment.cs index 5ef39a979d..7c2056683a 100644 --- a/src/Components/Components/test/ParameterCollectionAssignmentExtensionsTest.cs +++ b/src/Components/Components/test/ParameterViewTest.Assignment.cs @@ -10,16 +10,16 @@ using Microsoft.AspNetCore.Components.RenderTree; using Microsoft.AspNetCore.Components.Test.Helpers; using Xunit; -namespace Microsoft.AspNetCore.Components.Test +namespace Microsoft.AspNetCore.Components { - public class ParameterCollectionAssignmentExtensionsTest + public partial class ParameterViewTest { [Fact] public void IncomingParameterMatchesAnnotatedPrivateProperty_SetsValue() { // Arrange var someObject = new object(); - var parameterCollection = new ParameterCollectionBuilder + var parameters = new ParameterViewBuilder { { nameof(HasInstanceProperties.IntProp), 123 }, { nameof(HasInstanceProperties.StringProp), "Hello" }, @@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Components.Test var target = new HasInstanceProperties(); // Act - parameterCollection.SetParameterProperties(target); + parameters.SetParameterProperties(target); // Assert Assert.Equal(123, target.IntProp); @@ -40,14 +40,14 @@ namespace Microsoft.AspNetCore.Components.Test public void IncomingParameterMatchesDeclaredParameterCaseInsensitively_SetsValue() { // Arrange - var parameterCollection = new ParameterCollectionBuilder + var parameters = new ParameterViewBuilder { { nameof(HasInstanceProperties.IntProp).ToLowerInvariant(), 123 } }.Build(); var target = new HasInstanceProperties(); // Act - parameterCollection.SetParameterProperties(target); + parameters.SetParameterProperties(target); // Assert Assert.Equal(123, target.IntProp); @@ -57,7 +57,7 @@ namespace Microsoft.AspNetCore.Components.Test public void IncomingParameterMatchesInheritedDeclaredParameter_SetsValue() { // Arrange - var parameterCollection = new ParameterCollectionBuilder + var parameters = new ParameterViewBuilder { { nameof(HasInheritedProperties.IntProp), 123 }, { nameof(HasInheritedProperties.DerivedClassIntProp), 456 }, @@ -65,7 +65,7 @@ namespace Microsoft.AspNetCore.Components.Test var target = new HasInheritedProperties(); // Act - parameterCollection.SetParameterProperties(target); + parameters.SetParameterProperties(target); // Assert Assert.Equal(123, target.IntProp); @@ -84,10 +84,10 @@ namespace Microsoft.AspNetCore.Components.Test ObjectPropCurrentValue = existingObjectValue }; - var parameterCollection = new ParameterCollectionBuilder().Build(); + var parameters = new ParameterViewBuilder().Build(); // Act - parameterCollection.SetParameterProperties(target); + parameters.SetParameterProperties(target); // Assert Assert.Equal(456, target.IntProp); @@ -100,14 +100,14 @@ namespace Microsoft.AspNetCore.Components.Test { // Arrange var target = new HasPropertyWithoutParameterAttribute(); - var parameterCollection = new ParameterCollectionBuilder + var parameters = new ParameterViewBuilder { { "AnyOtherKey", 123 }, }.Build(); // Act var ex = Assert.Throws( - () => parameterCollection.SetParameterProperties(target)); + () => parameters.SetParameterProperties(target)); // Assert Assert.Equal( @@ -121,14 +121,14 @@ namespace Microsoft.AspNetCore.Components.Test { // Arrange var target = new HasPropertyWithoutParameterAttribute(); - var parameterCollection = new ParameterCollectionBuilder + var parameters = new ParameterViewBuilder { { nameof(HasPropertyWithoutParameterAttribute.IntProp), 123 }, }.Build(); // Act var ex = Assert.Throws( - () => parameterCollection.SetParameterProperties(target)); + () => parameters.SetParameterProperties(target)); // Assert Assert.Equal(default, target.IntProp); @@ -144,13 +144,13 @@ namespace Microsoft.AspNetCore.Components.Test // Arrange var target = new HasCaptureUnmatchedValuesProperty(); var value = new Dictionary(); - var parameterCollection = new ParameterCollectionBuilder + var parameters = new ParameterViewBuilder { { nameof(HasCaptureUnmatchedValuesProperty.CaptureUnmatchedValues), value }, }.Build(); // Act - parameterCollection.SetParameterProperties(target); + parameters.SetParameterProperties(target); // Assert Assert.Same(value, target.CaptureUnmatchedValues); @@ -161,7 +161,7 @@ namespace Microsoft.AspNetCore.Components.Test { // Arrange var target = new HasCaptureUnmatchedValuesProperty(); - var parameterCollection = new ParameterCollectionBuilder + var parameters = new ParameterViewBuilder { { nameof(HasCaptureUnmatchedValuesProperty.StringProp), "hi" }, { "test1", 123 }, @@ -169,7 +169,7 @@ namespace Microsoft.AspNetCore.Components.Test }.Build(); // Act - parameterCollection.SetParameterProperties(target); + parameters.SetParameterProperties(target); // Assert Assert.Equal("hi", target.StringProp); @@ -192,7 +192,7 @@ namespace Microsoft.AspNetCore.Components.Test { // Arrange var target = new HasCaptureUnmatchedValuesProperty(); - var parameterCollection = new ParameterCollectionBuilder + var parameters = new ParameterViewBuilder { { nameof(HasCaptureUnmatchedValuesProperty.CaptureUnmatchedValues), new Dictionary() }, { "test1", 123 }, @@ -200,7 +200,7 @@ namespace Microsoft.AspNetCore.Components.Test }.Build(); // Act - var ex = Assert.Throws(() => parameterCollection.SetParameterProperties(target)); + var ex = Assert.Throws(() => parameters.SetParameterProperties(target)); // Assert Assert.Equal( @@ -216,7 +216,7 @@ namespace Microsoft.AspNetCore.Components.Test { // Arrange var target = new HasCaptureUnmatchedValuesProperty(); - var parameterCollection = new ParameterCollectionBuilder + var parameters = new ParameterViewBuilder { { "test2", 456 }, { "test1", 123 }, @@ -224,7 +224,7 @@ namespace Microsoft.AspNetCore.Components.Test }.Build(); // Act - var ex = Assert.Throws(() => parameterCollection.SetParameterProperties(target)); + var ex = Assert.Throws(() => parameters.SetParameterProperties(target)); // Assert Assert.Equal( @@ -240,10 +240,10 @@ namespace Microsoft.AspNetCore.Components.Test { // Arrange var target = new HasDupliateCaptureUnmatchedValuesProperty(); - var parameterCollection = new ParameterCollectionBuilder().Build(); + var parameters = new ParameterViewBuilder().Build(); // Act - var ex = Assert.Throws(() => parameterCollection.SetParameterProperties(target)); + var ex = Assert.Throws(() => parameters.SetParameterProperties(target)); // Assert Assert.Equal( @@ -261,10 +261,10 @@ namespace Microsoft.AspNetCore.Components.Test { // Arrange var target = new HasWrongTypeCaptureUnmatchedValuesProperty(); - var parameterCollection = new ParameterCollectionBuilder().Build(); + var parameters = new ParameterViewBuilder().Build(); // Act - var ex = Assert.Throws(() => parameterCollection.SetParameterProperties(target)); + var ex = Assert.Throws(() => parameters.SetParameterProperties(target)); // Assert Assert.Equal( @@ -279,7 +279,7 @@ namespace Microsoft.AspNetCore.Components.Test { // Arrange var someObject = new object(); - var parameterCollection = new ParameterCollectionBuilder + var parameters = new ParameterViewBuilder { { nameof(HasInstanceProperties.IntProp), "string value" }, }.Build(); @@ -287,7 +287,7 @@ namespace Microsoft.AspNetCore.Components.Test // Act var ex = Assert.Throws( - () => parameterCollection.SetParameterProperties(target)); + () => parameters.SetParameterProperties(target)); // Assert Assert.Equal( @@ -301,14 +301,14 @@ namespace Microsoft.AspNetCore.Components.Test { // Arrange var target = new HasPropertyWhoseSetterThrows(); - var parameterCollection = new ParameterCollectionBuilder + var parameters = new ParameterViewBuilder { { nameof(HasPropertyWhoseSetterThrows.StringProp), "anything" }, }.Build(); // Act var ex = Assert.Throws( - () => parameterCollection.SetParameterProperties(target)); + () => parameters.SetParameterProperties(target)); // Assert Assert.Equal( @@ -321,12 +321,12 @@ namespace Microsoft.AspNetCore.Components.Test public void DeclaredParametersVaryOnlyByCase_Throws() { // Arrange - var parameterCollection = new ParameterCollectionBuilder().Build(); + var parameters = new ParameterViewBuilder().Build(); var target = new HasParametersVaryingOnlyByCase(); // Act var ex = Assert.Throws(() => - parameterCollection.SetParameterProperties(target)); + parameters.SetParameterProperties(target)); // Assert Assert.Equal( @@ -344,12 +344,12 @@ namespace Microsoft.AspNetCore.Components.Test // base class can legitimately depend on it for correct functioning. // Arrange - var parameterCollection = new ParameterCollectionBuilder().Build(); + var parameters = new ParameterViewBuilder().Build(); var target = new HasParameterClashingWithInherited(); // Act var ex = Assert.Throws(() => - parameterCollection.SetParameterProperties(target)); + parameters.SetParameterProperties(target)); // Assert Assert.Equal( @@ -362,7 +362,7 @@ namespace Microsoft.AspNetCore.Components.Test public void SupplyingNullWritesDefaultForType() { // Arrange - var parameterCollection = new ParameterCollectionBuilder + var parameters = new ParameterViewBuilder { { nameof(HasInstanceProperties.IntProp), null }, { nameof(HasInstanceProperties.StringProp), null }, @@ -370,7 +370,7 @@ namespace Microsoft.AspNetCore.Components.Test var target = new HasInstanceProperties { IntProp = 123, StringProp = "Hello" }; // Act - parameterCollection.SetParameterProperties(target); + parameters.SetParameterProperties(target); // Assert Assert.Equal(0, target.IntProp); @@ -446,7 +446,7 @@ namespace Microsoft.AspNetCore.Components.Test [Parameter(CaptureUnmatchedValues = true)] public KeyValuePair[] CaptureUnmatchedValuesProp { get; set; } } - class ParameterCollectionBuilder : IEnumerable + class ParameterViewBuilder : IEnumerable { private readonly List<(string Name, object Value)> _keyValuePairs = new List<(string, object)>(); @@ -457,7 +457,7 @@ namespace Microsoft.AspNetCore.Components.Test public IEnumerator GetEnumerator() => throw new NotImplementedException(); - public ParameterCollection Build() + public ParameterView Build() { var builder = new RenderTreeBuilder(); builder.OpenComponent(0); @@ -466,17 +466,8 @@ namespace Microsoft.AspNetCore.Components.Test builder.AddAttribute(1, kvp.Name, kvp.Value); } builder.CloseComponent(); - return new ParameterCollection(builder.GetFrames().Array, ownerIndex: 0); + return new ParameterView(builder.GetFrames().Array, ownerIndex: 0); } } - - class FakeComponent : IComponent - { - public void Attach(RenderHandle renderHandle) - => throw new NotImplementedException(); - - public Task SetParametersAsync(ParameterCollection parameters) - => throw new NotImplementedException(); - } } } diff --git a/src/Components/Components/test/ParameterCollectionTest.cs b/src/Components/Components/test/ParameterViewTest.cs similarity index 79% rename from src/Components/Components/test/ParameterCollectionTest.cs rename to src/Components/Components/test/ParameterViewTest.cs index 9e9b8da975..cfb3191ca5 100644 --- a/src/Components/Components/test/ParameterCollectionTest.cs +++ b/src/Components/Components/test/ParameterViewTest.cs @@ -8,9 +8,9 @@ using Microsoft.AspNetCore.Components.Rendering; using Microsoft.AspNetCore.Components.RenderTree; using Xunit; -namespace Microsoft.AspNetCore.Components.Test +namespace Microsoft.AspNetCore.Components { - public class ParameterCollectionTest + public partial class ParameterViewTest { [Fact] public void CanInitializeUsingComponentWithNoDescendants() @@ -20,10 +20,10 @@ namespace Microsoft.AspNetCore.Components.Test { RenderTreeFrame.ChildComponent(0, typeof(FakeComponent)).WithComponentSubtreeLength(1) }; - var parameterCollection = new ParameterCollection(frames, 0); + var parameters = new ParameterView(frames, 0); // Assert - Assert.Empty(ToEnumerable(parameterCollection)); + Assert.Empty(ToEnumerable(parameters)); } [Fact] @@ -34,10 +34,10 @@ namespace Microsoft.AspNetCore.Components.Test { RenderTreeFrame.Element(0, "some element").WithElementSubtreeLength(1) }; - var parameterCollection = new ParameterCollection(frames, 0); + var parameters = new ParameterView(frames, 0); // Assert - Assert.Empty(ToEnumerable(parameterCollection)); + Assert.Empty(ToEnumerable(parameters)); } [Fact] @@ -52,14 +52,14 @@ namespace Microsoft.AspNetCore.Components.Test RenderTreeFrame.Attribute(1, "attribute 1", attribute1Value), RenderTreeFrame.Attribute(2, "attribute 2", attribute2Value), // Although RenderTreeBuilder doesn't let you add orphaned attributes like this, - // still want to verify that ParameterCollection doesn't attempt to read past the + // still want to verify that parameters doesn't attempt to read past the // end of the owner's descendants RenderTreeFrame.Attribute(3, "orphaned attribute", "value") }; - var parameterCollection = new ParameterCollection(frames, 0); + var parameters = new ParameterView(frames, 0); // Assert - Assert.Collection(ToEnumerable(parameterCollection), + Assert.Collection(ToEnumerable(parameters), AssertParameter("attribute 1", attribute1Value, false), AssertParameter("attribute 2", attribute2Value, false)); } @@ -78,10 +78,10 @@ namespace Microsoft.AspNetCore.Components.Test RenderTreeFrame.Element(3, "child element").WithElementSubtreeLength(2), RenderTreeFrame.Attribute(4, "child attribute", "some value") }; - var parameterCollection = new ParameterCollection(frames, 0); + var parameters = new ParameterView(frames, 0); // Assert - Assert.Collection(ToEnumerable(parameterCollection), + Assert.Collection(ToEnumerable(parameters), AssertParameter("attribute 1", attribute1Value, false), AssertParameter("attribute 2", attribute2Value, false)); } @@ -93,7 +93,7 @@ namespace Microsoft.AspNetCore.Components.Test var attribute1Value = new object(); var attribute2Value = new object(); var attribute3Value = new object(); - var parameterCollection = new ParameterCollection(new[] + var parameters = new ParameterView(new[] { RenderTreeFrame.Element(0, "some element").WithElementSubtreeLength(2), RenderTreeFrame.Attribute(1, "attribute 1", attribute1Value) @@ -104,7 +104,7 @@ namespace Microsoft.AspNetCore.Components.Test }); // Assert - Assert.Collection(ToEnumerable(parameterCollection), + Assert.Collection(ToEnumerable(parameters), AssertParameter("attribute 1", attribute1Value, false), AssertParameter("attribute 2", attribute2Value, true), AssertParameter("attribute 3", attribute3Value, true)); @@ -114,14 +114,14 @@ namespace Microsoft.AspNetCore.Components.Test public void CanTryGetNonExistingValue() { // Arrange - var parameterCollection = new ParameterCollection(new[] + var parameters = new ParameterView(new[] { RenderTreeFrame.Element(0, "some element").WithElementSubtreeLength(2), RenderTreeFrame.Attribute(1, "some other entry", new object()) }, 0); // Act - var didFind = parameterCollection.TryGetValue("nonexisting entry", out var value); + var didFind = parameters.TryGetValue("nonexisting entry", out var value); // Assert Assert.False(didFind); @@ -132,14 +132,14 @@ namespace Microsoft.AspNetCore.Components.Test public void CanTryGetExistingValueWithCorrectType() { // Arrange - var parameterCollection = new ParameterCollection(new[] + var parameters = new ParameterView(new[] { RenderTreeFrame.Element(0, "some element").WithElementSubtreeLength(2), RenderTreeFrame.Attribute(1, "my entry", "hello") }, 0); // Act - var didFind = parameterCollection.TryGetValue("my entry", out var value); + var didFind = parameters.TryGetValue("my entry", out var value); // Assert Assert.True(didFind); @@ -151,7 +151,7 @@ namespace Microsoft.AspNetCore.Components.Test { // Arrange var myEntryValue = new object(); - var parameterCollection = new ParameterCollection(new[] + var parameters = new ParameterView(new[] { RenderTreeFrame.Element(0, "some element").WithElementSubtreeLength(2), RenderTreeFrame.Attribute(1, "my entry", myEntryValue), @@ -159,7 +159,7 @@ namespace Microsoft.AspNetCore.Components.Test }, 0); // Act - var result = parameterCollection.GetValueOrDefault("my entry"); + var result = parameters.GetValueOrDefault("my entry"); // Assert Assert.Same(myEntryValue, result); @@ -170,7 +170,7 @@ namespace Microsoft.AspNetCore.Components.Test { // Arrange var myEntryValue = new object(); - var parameterCollection = new ParameterCollection(new[] + var parameters = new ParameterView(new[] { RenderTreeFrame.Element(0, "some element").WithElementSubtreeLength(3), RenderTreeFrame.Attribute(1, "my entry", myEntryValue), @@ -178,7 +178,7 @@ namespace Microsoft.AspNetCore.Components.Test }, 0); // Act - var result = parameterCollection.GetValueOrDefault("my entry"); + var result = parameters.GetValueOrDefault("my entry"); // Assert: Picks first match Assert.Same(myEntryValue, result); @@ -188,7 +188,7 @@ namespace Microsoft.AspNetCore.Components.Test public void CanGetValueOrDefault_WithNonExistingValue() { // Arrange - var parameterCollection = new ParameterCollection(new[] + var parameters = new ParameterView(new[] { RenderTreeFrame.Element(0, "some element").WithElementSubtreeLength(2), RenderTreeFrame.Attribute(1, "some other entry", new object()) @@ -198,7 +198,7 @@ namespace Microsoft.AspNetCore.Components.Test }); // Act - var result = parameterCollection.GetValueOrDefault("nonexisting entry"); + var result = parameters.GetValueOrDefault("nonexisting entry"); // Assert Assert.Equal(default, result); @@ -209,14 +209,14 @@ namespace Microsoft.AspNetCore.Components.Test { // Arrange var explicitDefaultValue = new DateTime(2018, 3, 20); - var parameterCollection = new ParameterCollection(new[] + var parameters = new ParameterView(new[] { RenderTreeFrame.Element(0, "some element").WithElementSubtreeLength(2), RenderTreeFrame.Attribute(1, "some other entry", new object()) }, 0); // Act - var result = parameterCollection.GetValueOrDefault("nonexisting entry", explicitDefaultValue); + var result = parameters.GetValueOrDefault("nonexisting entry", explicitDefaultValue); // Assert Assert.Equal(explicitDefaultValue, result); @@ -226,7 +226,7 @@ namespace Microsoft.AspNetCore.Components.Test public void ThrowsIfTryGetExistingValueWithIncorrectType() { // Arrange - var parameterCollection = new ParameterCollection(new[] + var parameters = new ParameterView(new[] { RenderTreeFrame.Element(0, "some element").WithElementSubtreeLength(2), RenderTreeFrame.Attribute(1, "my entry", "hello") @@ -235,7 +235,7 @@ namespace Microsoft.AspNetCore.Components.Test // Act/Assert Assert.Throws(() => { - parameterCollection.TryGetValue("my entry", out var value); + parameters.TryGetValue("my entry", out var value); }); } @@ -246,7 +246,7 @@ namespace Microsoft.AspNetCore.Components.Test var dictionary = new Dictionary(); // Act - var collection = ParameterCollection.FromDictionary(dictionary); + var collection = ParameterView.FromDictionary(dictionary); // Assert Assert.Empty(collection.ToDictionary()); @@ -263,7 +263,7 @@ namespace Microsoft.AspNetCore.Components.Test }; // Act - var collection = ParameterCollection.FromDictionary(dictionary); + var collection = ParameterView.FromDictionary(dictionary); // Assert Assert.Equal(dictionary, collection.ToDictionary()); @@ -275,7 +275,7 @@ namespace Microsoft.AspNetCore.Components.Test { // Arrange var entry2Value = new object(); - var parameterCollection = new ParameterCollection(new[] + var parameters = new ParameterView(new[] { RenderTreeFrame.Element(0, "some element").WithElementSubtreeLength(3), RenderTreeFrame.Attribute(0, "entry 1", "value 1"), @@ -283,7 +283,7 @@ namespace Microsoft.AspNetCore.Components.Test }, 0); // Act - IReadOnlyDictionary dict = parameterCollection.ToDictionary(); + IReadOnlyDictionary dict = parameters.ToDictionary(); // Assert Assert.Collection(dict, @@ -304,7 +304,7 @@ namespace Microsoft.AspNetCore.Components.Test { // Arrange var myEntryValue = new object(); - var parameterCollection = new ParameterCollection(new[] + var parameters = new ParameterView(new[] { RenderTreeFrame.Element(0, "some element").WithElementSubtreeLength(2), RenderTreeFrame.Attribute(1, "unrelated value", new object()) @@ -316,13 +316,13 @@ namespace Microsoft.AspNetCore.Components.Test }); // Act - var result = parameterCollection.GetValueOrDefault("my entry"); + var result = parameters.GetValueOrDefault("my entry"); // Assert Assert.Same(myEntryValue, result); } - private Action AssertParameter(string expectedName, object expectedValue, bool expectedIsCascading) + private Action AssertParameter(string expectedName, object expectedValue, bool expectedIsCascading) { return parameter => { @@ -332,9 +332,9 @@ namespace Microsoft.AspNetCore.Components.Test }; } - public IEnumerable ToEnumerable(ParameterCollection parameterCollection) + public IEnumerable ToEnumerable(ParameterView parameters) { - foreach (var item in parameterCollection) + foreach (var item in parameters) { yield return item; } @@ -345,7 +345,7 @@ namespace Microsoft.AspNetCore.Components.Test public void Attach(RenderHandle renderHandle) => throw new NotImplementedException(); - public Task SetParametersAsync(ParameterCollection parameters) + public Task SetParametersAsync(ParameterView parameters) => throw new NotImplementedException(); } diff --git a/src/Components/Components/test/RenderTreeBuilderTest.cs b/src/Components/Components/test/RenderTreeBuilderTest.cs index 4bce2e3165..c90259f057 100644 --- a/src/Components/Components/test/RenderTreeBuilderTest.cs +++ b/src/Components/Components/test/RenderTreeBuilderTest.cs @@ -1803,7 +1803,7 @@ namespace Microsoft.AspNetCore.Components.Test { public void Attach(RenderHandle renderHandle) { } - public Task SetParametersAsync(ParameterCollection parameters) + public Task SetParametersAsync(ParameterView parameters) => throw new NotImplementedException(); } diff --git a/src/Components/Components/test/RenderTreeDiffBuilderTest.cs b/src/Components/Components/test/RenderTreeDiffBuilderTest.cs index c098d56d97..3c0edffd62 100644 --- a/src/Components/Components/test/RenderTreeDiffBuilderTest.cs +++ b/src/Components/Components/test/RenderTreeDiffBuilderTest.cs @@ -2222,7 +2222,7 @@ namespace Microsoft.AspNetCore.Components.Test public string NonParameterProperty { get; set; } public void Attach(RenderHandle renderHandle) { } - public Task SetParametersAsync(ParameterCollection parameters) + public Task SetParametersAsync(ParameterView parameters) { parameters.SetParameterProperties(this); return Task.CompletedTask; @@ -2235,7 +2235,7 @@ namespace Microsoft.AspNetCore.Components.Test { } - public Task SetParametersAsync(ParameterCollection parameters) => Task.CompletedTask; + public Task SetParametersAsync(ParameterView parameters) => Task.CompletedTask; } private class CaptureSetParametersComponent : IComponent @@ -2246,7 +2246,7 @@ namespace Microsoft.AspNetCore.Components.Test { } - public Task SetParametersAsync(ParameterCollection parameters) + public Task SetParametersAsync(ParameterView parameters) { SetParametersCallCount++; return Task.CompletedTask; @@ -2260,14 +2260,14 @@ namespace Microsoft.AspNetCore.Components.Test public void Attach(RenderHandle renderHandle) { } - public Task SetParametersAsync(ParameterCollection parameters) => Task.CompletedTask; + public Task SetParametersAsync(ParameterView parameters) => Task.CompletedTask; } private class NonDisposableComponent : IComponent { public void Attach(RenderHandle renderHandle) { } - public Task SetParametersAsync(ParameterCollection parameters) => Task.CompletedTask; + public Task SetParametersAsync(ParameterView parameters) => Task.CompletedTask; } private static void AssertEdit( diff --git a/src/Components/Components/test/RendererTest.cs b/src/Components/Components/test/RendererTest.cs index 44118704d4..c404e5360f 100644 --- a/src/Components/Components/test/RendererTest.cs +++ b/src/Components/Components/test/RendererTest.cs @@ -239,7 +239,7 @@ namespace Microsoft.AspNetCore.Components.Test // Act/Assert var componentId = renderer.AssignRootComponentId(component); var log = new ConcurrentQueue<(int id, NestedAsyncComponent.EventType @event)>(); - await renderer.Dispatcher.InvokeAsync(() => renderer.RenderRootComponentAsync(componentId, ParameterCollection.FromDictionary(new Dictionary + await renderer.Dispatcher.InvokeAsync(() => renderer.RenderRootComponentAsync(componentId, ParameterView.FromDictionary(new Dictionary { [EventActionsName] = new Dictionary> { @@ -283,7 +283,7 @@ namespace Microsoft.AspNetCore.Components.Test // Act/Assert var componentId = renderer.AssignRootComponentId(component); var log = new ConcurrentQueue<(int id, NestedAsyncComponent.EventType @event)>(); - await renderer.Dispatcher.InvokeAsync(() => renderer.RenderRootComponentAsync(componentId, ParameterCollection.FromDictionary(new Dictionary + await renderer.Dispatcher.InvokeAsync(() => renderer.RenderRootComponentAsync(componentId, ParameterView.FromDictionary(new Dictionary { [EventActionsName] = new Dictionary> { @@ -327,7 +327,7 @@ namespace Microsoft.AspNetCore.Components.Test // Act/Assert var componentId = renderer.AssignRootComponentId(component); var log = new ConcurrentQueue<(int id, NestedAsyncComponent.EventType @event)>(); - await renderer.Dispatcher.InvokeAsync(() => renderer.RenderRootComponentAsync(componentId, ParameterCollection.FromDictionary(new Dictionary + await renderer.Dispatcher.InvokeAsync(() => renderer.RenderRootComponentAsync(componentId, ParameterView.FromDictionary(new Dictionary { [EventActionsName] = new Dictionary> { @@ -371,7 +371,7 @@ namespace Microsoft.AspNetCore.Components.Test // Act/Assert var componentId = renderer.AssignRootComponentId(component); var log = new ConcurrentQueue<(int id, NestedAsyncComponent.EventType @event)>(); - await renderer.Dispatcher.InvokeAsync(() => renderer.RenderRootComponentAsync(componentId, ParameterCollection.FromDictionary(new Dictionary + await renderer.Dispatcher.InvokeAsync(() => renderer.RenderRootComponentAsync(componentId, ParameterView.FromDictionary(new Dictionary { [EventActionsName] = new Dictionary> { @@ -2776,7 +2776,7 @@ namespace Microsoft.AspNetCore.Components.Test // Act/Assert var componentId = renderer.AssignRootComponentId(component); - var task = renderer.RenderRootComponentAsync(componentId, ParameterCollection.FromDictionary(new Dictionary + var task = renderer.RenderRootComponentAsync(componentId, ParameterView.FromDictionary(new Dictionary { [nameof(NestedAsyncComponent.EventActions)] = new Dictionary> { @@ -2809,7 +2809,7 @@ namespace Microsoft.AspNetCore.Components.Test // Act/Assert var componentId = renderer.AssignRootComponentId(component); - var renderTask = renderer.RenderRootComponentAsync(componentId, ParameterCollection.FromDictionary(new Dictionary + var renderTask = renderer.RenderRootComponentAsync(componentId, ParameterView.FromDictionary(new Dictionary { [nameof(NestedAsyncComponent.EventActions)] = new Dictionary> { @@ -2842,7 +2842,7 @@ namespace Microsoft.AspNetCore.Components.Test // Act/Assert var componentId = renderer.AssignRootComponentId(component); - var renderTask = renderer.RenderRootComponentAsync(componentId, ParameterCollection.FromDictionary(new Dictionary + var renderTask = renderer.RenderRootComponentAsync(componentId, ParameterView.FromDictionary(new Dictionary { [nameof(NestedAsyncComponent.EventActions)] = new Dictionary> { @@ -2876,7 +2876,7 @@ namespace Microsoft.AspNetCore.Components.Test // Act/Assert var componentId = renderer.AssignRootComponentId(component); - var renderTask = renderer.RenderRootComponentAsync(componentId, ParameterCollection.FromDictionary(new Dictionary + var renderTask = renderer.RenderRootComponentAsync(componentId, ParameterView.FromDictionary(new Dictionary { [nameof(NestedAsyncComponent.EventActions)] = new Dictionary> { @@ -2957,7 +2957,7 @@ namespace Microsoft.AspNetCore.Components.Test // Act/Assert var componentId = renderer.AssignRootComponentId(component); - var renderTask = renderer.RenderRootComponentAsync(componentId, ParameterCollection.FromDictionary(new Dictionary + var renderTask = renderer.RenderRootComponentAsync(componentId, ParameterView.FromDictionary(new Dictionary { [nameof(NestedAsyncComponent.EventActions)] = new Dictionary> { @@ -3015,7 +3015,7 @@ namespace Microsoft.AspNetCore.Components.Test // Act/Assert var componentId = renderer.AssignRootComponentId(component); - var renderTask = renderer.RenderRootComponentAsync(componentId, ParameterCollection.FromDictionary(new Dictionary + var renderTask = renderer.RenderRootComponentAsync(componentId, ParameterView.FromDictionary(new Dictionary { [nameof(NestedAsyncComponent.EventActions)] = new Dictionary> { @@ -3070,7 +3070,7 @@ namespace Microsoft.AspNetCore.Components.Test // Act/Assert var componentId = renderer.AssignRootComponentId(component); - var renderTask = renderer.RenderRootComponentAsync(componentId, ParameterCollection.FromDictionary(new Dictionary + var renderTask = renderer.RenderRootComponentAsync(componentId, ParameterView.FromDictionary(new Dictionary { [nameof(NestedAsyncComponent.EventActions)] = new Dictionary> { @@ -3124,7 +3124,7 @@ namespace Microsoft.AspNetCore.Components.Test // Act/Assert var componentId = renderer.AssignRootComponentId(component); - var renderTask = renderer.RenderRootComponentAsync(componentId, ParameterCollection.FromDictionary(new Dictionary + var renderTask = renderer.RenderRootComponentAsync(componentId, ParameterView.FromDictionary(new Dictionary { [nameof(NestedAsyncComponent.EventActions)] = new Dictionary> { @@ -3158,7 +3158,7 @@ namespace Microsoft.AspNetCore.Components.Test // Act/Assert var componentId = renderer.AssignRootComponentId(component); - var renderTask = renderer.RenderRootComponentAsync(componentId, ParameterCollection.FromDictionary(new Dictionary + var renderTask = renderer.RenderRootComponentAsync(componentId, ParameterView.FromDictionary(new Dictionary { [nameof(NestedAsyncComponent.EventActions)] = new Dictionary> { @@ -3195,7 +3195,7 @@ namespace Microsoft.AspNetCore.Components.Test // Act/Assert var componentId = renderer.AssignRootComponentId(component); - await renderer.RenderRootComponentAsync(componentId, ParameterCollection.FromDictionary(new Dictionary + await renderer.RenderRootComponentAsync(componentId, ParameterView.FromDictionary(new Dictionary { [nameof(NestedAsyncComponent.EventActions)] = new Dictionary> { @@ -3428,7 +3428,7 @@ namespace Microsoft.AspNetCore.Components.Test _renderHandle = renderHandle; } - public Task SetParametersAsync(ParameterCollection parameters) + public Task SetParametersAsync(ParameterView parameters) { TriggerRender(); return Task.CompletedTask; @@ -3497,7 +3497,7 @@ namespace Microsoft.AspNetCore.Components.Test public void Attach(RenderHandle renderHandle) => RenderHandle = renderHandle; - public Task SetParametersAsync(ParameterCollection parameters) + public Task SetParametersAsync(ParameterView parameters) { parameters.SetParameterProperties(this); return Task.CompletedTask; @@ -3646,7 +3646,7 @@ namespace Microsoft.AspNetCore.Components.Test public void Attach(RenderHandle renderHandle) => _renderHandle = renderHandle; - public Task SetParametersAsync(ParameterCollection parameters) + public Task SetParametersAsync(ParameterView parameters) { parameters.SetParameterProperties(this); Render(); @@ -3677,7 +3677,7 @@ namespace Microsoft.AspNetCore.Components.Test public void Attach(RenderHandle renderHandle) => _renderHandles.Add(renderHandle); - public Task SetParametersAsync(ParameterCollection parameters) + public Task SetParametersAsync(ParameterView parameters) { return Task.CompletedTask; } @@ -3734,7 +3734,7 @@ namespace Microsoft.AspNetCore.Components.Test return Task.CompletedTask; } - Task IComponent.SetParametersAsync(ParameterCollection parameters) + Task IComponent.SetParametersAsync(ParameterView parameters) { TriggerRender(); return Task.CompletedTask; @@ -3793,7 +3793,7 @@ namespace Microsoft.AspNetCore.Components.Test _renderHandler = renderHandle; } - public async Task SetParametersAsync(ParameterCollection parameters) + public async Task SetParametersAsync(ParameterView parameters) { int n; while (Number > 0) @@ -3842,7 +3842,7 @@ namespace Microsoft.AspNetCore.Components.Test return task; } - public Task SetParametersAsync(ParameterCollection parameters) + public Task SetParametersAsync(ParameterView parameters) { return TriggerRenderAsync(); } diff --git a/src/Components/Components/test/Rendering/HtmlRendererTestBase.cs b/src/Components/Components/test/Rendering/HtmlRendererTestBase.cs index 1650158ee7..894c8d4703 100644 --- a/src/Components/Components/test/Rendering/HtmlRendererTestBase.cs +++ b/src/Components/Components/test/Rendering/HtmlRendererTestBase.cs @@ -32,7 +32,7 @@ namespace Microsoft.AspNetCore.Components.Rendering var htmlRenderer = GetHtmlRenderer(serviceProvider); // Act - var result = GetResult(htmlRenderer.Dispatcher.InvokeAsync(() => htmlRenderer.RenderComponentAsync(ParameterCollection.Empty))); + var result = GetResult(htmlRenderer.Dispatcher.InvokeAsync(() => htmlRenderer.RenderComponentAsync(ParameterView.Empty))); // Assert Assert.Equal(expectedHtml, result); @@ -52,7 +52,7 @@ namespace Microsoft.AspNetCore.Components.Rendering var htmlRenderer = GetHtmlRenderer(serviceProvider); // Act - var result = GetResult(htmlRenderer.Dispatcher.InvokeAsync(() => htmlRenderer.RenderComponentAsync(ParameterCollection.Empty))); + var result = GetResult(htmlRenderer.Dispatcher.InvokeAsync(() => htmlRenderer.RenderComponentAsync(ParameterView.Empty))); // Assert Assert.Equal(expectedHtml, result); @@ -72,7 +72,7 @@ namespace Microsoft.AspNetCore.Components.Rendering var htmlRenderer = GetHtmlRenderer(serviceProvider); // Act - var result = GetResult(htmlRenderer.Dispatcher.InvokeAsync(() => htmlRenderer.RenderComponentAsync(ParameterCollection.Empty))); + var result = GetResult(htmlRenderer.Dispatcher.InvokeAsync(() => htmlRenderer.RenderComponentAsync(ParameterView.Empty))); // Assert Assert.Equal(expectedHtml, result); @@ -93,7 +93,7 @@ namespace Microsoft.AspNetCore.Components.Rendering var htmlRenderer = GetHtmlRenderer(serviceProvider); // Act - var result = GetResult(htmlRenderer.Dispatcher.InvokeAsync(() => htmlRenderer.RenderComponentAsync(ParameterCollection.Empty))); + var result = GetResult(htmlRenderer.Dispatcher.InvokeAsync(() => htmlRenderer.RenderComponentAsync(ParameterView.Empty))); // Assert Assert.Equal(expectedHtml, result); @@ -116,7 +116,7 @@ namespace Microsoft.AspNetCore.Components.Rendering var htmlRenderer = GetHtmlRenderer(serviceProvider); // Act - var result = GetResult(htmlRenderer.Dispatcher.InvokeAsync(() => htmlRenderer.RenderComponentAsync(ParameterCollection.Empty))); + var result = GetResult(htmlRenderer.Dispatcher.InvokeAsync(() => htmlRenderer.RenderComponentAsync(ParameterView.Empty))); // Assert Assert.Equal(expectedHtml, result); @@ -150,7 +150,7 @@ namespace Microsoft.AspNetCore.Components.Rendering var htmlRenderer = GetHtmlRenderer(serviceProvider); // Act - var result = GetResult(htmlRenderer.Dispatcher.InvokeAsync(() => htmlRenderer.RenderComponentAsync(ParameterCollection.Empty))); + var result = GetResult(htmlRenderer.Dispatcher.InvokeAsync(() => htmlRenderer.RenderComponentAsync(ParameterView.Empty))); // Assert Assert.Equal(expectedHtml, result); @@ -172,7 +172,7 @@ namespace Microsoft.AspNetCore.Components.Rendering var htmlRenderer = GetHtmlRenderer(serviceProvider); // Act - var result = GetResult(htmlRenderer.Dispatcher.InvokeAsync(() => htmlRenderer.RenderComponentAsync(ParameterCollection.Empty))); + var result = GetResult(htmlRenderer.Dispatcher.InvokeAsync(() => htmlRenderer.RenderComponentAsync(ParameterView.Empty))); // Assert Assert.Equal(expectedHtml, result); @@ -193,7 +193,7 @@ namespace Microsoft.AspNetCore.Components.Rendering var htmlRenderer = GetHtmlRenderer(serviceProvider); // Act - var result = GetResult(htmlRenderer.Dispatcher.InvokeAsync(() => htmlRenderer.RenderComponentAsync(ParameterCollection.Empty))); + var result = GetResult(htmlRenderer.Dispatcher.InvokeAsync(() => htmlRenderer.RenderComponentAsync(ParameterView.Empty))); // Assert Assert.Equal(expectedHtml, result); @@ -214,7 +214,7 @@ namespace Microsoft.AspNetCore.Components.Rendering var htmlRenderer = GetHtmlRenderer(serviceProvider); // Act - var result = GetResult(htmlRenderer.Dispatcher.InvokeAsync(() => htmlRenderer.RenderComponentAsync(ParameterCollection.Empty))); + var result = GetResult(htmlRenderer.Dispatcher.InvokeAsync(() => htmlRenderer.RenderComponentAsync(ParameterView.Empty))); // Assert Assert.Equal(expectedHtml, result); @@ -237,7 +237,7 @@ namespace Microsoft.AspNetCore.Components.Rendering var htmlRenderer = GetHtmlRenderer(serviceProvider); // Act - var result = GetResult(htmlRenderer.Dispatcher.InvokeAsync(() => htmlRenderer.RenderComponentAsync(ParameterCollection.Empty))); + var result = GetResult(htmlRenderer.Dispatcher.InvokeAsync(() => htmlRenderer.RenderComponentAsync(ParameterView.Empty))); // Assert Assert.Equal(expectedHtml, result); @@ -267,7 +267,7 @@ namespace Microsoft.AspNetCore.Components.Rendering var htmlRenderer = GetHtmlRenderer(serviceProvider); // Act - var result = GetResult(htmlRenderer.Dispatcher.InvokeAsync(() => htmlRenderer.RenderComponentAsync(ParameterCollection.Empty))); + var result = GetResult(htmlRenderer.Dispatcher.InvokeAsync(() => htmlRenderer.RenderComponentAsync(ParameterView.Empty))); // Assert Assert.Equal(expectedHtml, result); @@ -296,7 +296,7 @@ namespace Microsoft.AspNetCore.Components.Rendering var htmlRenderer = GetHtmlRenderer(serviceProvider); // Act - var result = GetResult(htmlRenderer.Dispatcher.InvokeAsync(() => htmlRenderer.RenderComponentAsync(ParameterCollection.Empty))); + var result = GetResult(htmlRenderer.Dispatcher.InvokeAsync(() => htmlRenderer.RenderComponentAsync(ParameterView.Empty))); // Assert Assert.Equal(expectedHtml, result); @@ -326,7 +326,7 @@ namespace Microsoft.AspNetCore.Components.Rendering var htmlRenderer = GetHtmlRenderer(serviceProvider); // Act - var result = GetResult(htmlRenderer.Dispatcher.InvokeAsync(() => htmlRenderer.RenderComponentAsync(ParameterCollection.Empty))); + var result = GetResult(htmlRenderer.Dispatcher.InvokeAsync(() => htmlRenderer.RenderComponentAsync(ParameterView.Empty))); // Assert Assert.Equal(expectedHtml, result); @@ -339,7 +339,7 @@ namespace Microsoft.AspNetCore.Components.Rendering var expectedHtml = new[] { "<", "p", ">", "<", "input", " ", "value", "=", "\"", "5", "\"", " />", "" }; - RenderFragment Content(ParameterCollection pc) => new RenderFragment((RenderTreeBuilder rtb) => + RenderFragment Content(ParameterView pc) => new RenderFragment((RenderTreeBuilder rtb) => { rtb.OpenElement(0, "p"); rtb.OpenElement(1, "input"); @@ -350,7 +350,7 @@ namespace Microsoft.AspNetCore.Components.Rendering }); var serviceProvider = new ServiceCollection() - .AddSingleton(new Func(Content)) + .AddSingleton(new Func(Content)) .BuildServiceProvider(); var htmlRenderer = GetHtmlRenderer(serviceProvider); @@ -358,7 +358,7 @@ namespace Microsoft.AspNetCore.Components.Rendering // Act var result = GetResult(htmlRenderer.Dispatcher.InvokeAsync(() => htmlRenderer.RenderComponentAsync( - new ParameterCollection(new[] { + new ParameterView(new[] { RenderTreeFrame.Element(0,string.Empty), RenderTreeFrame.Attribute(1,"update",change), RenderTreeFrame.Attribute(2,"value",5) @@ -388,7 +388,7 @@ namespace Microsoft.AspNetCore.Components.Rendering var htmlRenderer = GetHtmlRenderer(serviceProvider); // Act - var result = GetResult(htmlRenderer.Dispatcher.InvokeAsync(() => htmlRenderer.RenderComponentAsync(ParameterCollection.Empty))); + var result = GetResult(htmlRenderer.Dispatcher.InvokeAsync(() => htmlRenderer.RenderComponentAsync(ParameterView.Empty))); // Assert Assert.Equal(expectedHtml, result); @@ -415,7 +415,7 @@ namespace Microsoft.AspNetCore.Components.Rendering var htmlRenderer = GetHtmlRenderer(serviceProvider); // Act - var result = GetResult(htmlRenderer.Dispatcher.InvokeAsync(() => htmlRenderer.RenderComponentAsync(ParameterCollection.Empty))); + var result = GetResult(htmlRenderer.Dispatcher.InvokeAsync(() => htmlRenderer.RenderComponentAsync(ParameterView.Empty))); // Assert Assert.Equal(expectedHtml, result); @@ -445,9 +445,9 @@ namespace Microsoft.AspNetCore.Components.Rendering } [Inject] - Func CreateRenderFragment { get; set; } + Func CreateRenderFragment { get; set; } - public Task SetParametersAsync(ParameterCollection parameters) + public Task SetParametersAsync(ParameterView parameters) { RenderHandle.Render(CreateRenderFragment(parameters)); return Task.CompletedTask; @@ -465,7 +465,7 @@ namespace Microsoft.AspNetCore.Components.Rendering var htmlRenderer = GetHtmlRenderer(serviceProvider); // Act - var result = await htmlRenderer.Dispatcher.InvokeAsync(() => htmlRenderer.RenderComponentAsync(ParameterCollection.FromDictionary(new Dictionary + var result = await htmlRenderer.Dispatcher.InvokeAsync(() => htmlRenderer.RenderComponentAsync(ParameterView.FromDictionary(new Dictionary { ["Value"] = 10 }))); @@ -489,7 +489,7 @@ namespace Microsoft.AspNetCore.Components.Rendering var htmlRenderer = GetHtmlRenderer(serviceProvider); // Act - var result = await htmlRenderer.Dispatcher.InvokeAsync(() => htmlRenderer.RenderComponentAsync(ParameterCollection.FromDictionary(new Dictionary + var result = await htmlRenderer.Dispatcher.InvokeAsync(() => htmlRenderer.RenderComponentAsync(ParameterView.FromDictionary(new Dictionary { ["Nested"] = false, ["Value"] = 10 @@ -558,13 +558,13 @@ namespace Microsoft.AspNetCore.Components.Rendering _renderHandle = renderHandle; } - public Task SetParametersAsync(ParameterCollection parameters) + public Task SetParametersAsync(ParameterView parameters) { _renderHandle.Render(CreateRenderFragment(parameters)); return Task.CompletedTask; } - private RenderFragment CreateRenderFragment(ParameterCollection parameters) + private RenderFragment CreateRenderFragment(ParameterView parameters) { return RenderFragment; @@ -589,7 +589,7 @@ namespace Microsoft.AspNetCore.Components.Rendering _renderHandle = renderHandle; } - public Task SetParametersAsync(ParameterCollection parameters) + public Task SetParametersAsync(ParameterView parameters) { _renderHandle.Render(Fragment); return Task.CompletedTask; diff --git a/src/Components/Server/ref/Microsoft.AspNetCore.Components.Server.netcoreapp3.0.cs b/src/Components/Server/ref/Microsoft.AspNetCore.Components.Server.netcoreapp3.0.cs index ba045c2919..6f6cba733d 100644 --- a/src/Components/Server/ref/Microsoft.AspNetCore.Components.Server.netcoreapp3.0.cs +++ b/src/Components/Server/ref/Microsoft.AspNetCore.Components.Server.netcoreapp3.0.cs @@ -41,7 +41,7 @@ namespace Microsoft.AspNetCore.Components.Server public ComponentPrerenderingContext() { } public System.Type ComponentType { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } public Microsoft.AspNetCore.Http.HttpContext Context { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } - public Microsoft.AspNetCore.Components.ParameterCollection Parameters { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } + public Microsoft.AspNetCore.Components.ParameterView Parameters { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } } public sealed partial class ComponentPrerenderResult { diff --git a/src/Components/Server/src/Circuits/CircuitHost.cs b/src/Components/Server/src/Circuits/CircuitHost.cs index d82344e67c..4f71c47775 100644 --- a/src/Components/Server/src/Circuits/CircuitHost.cs +++ b/src/Components/Server/src/Circuits/CircuitHost.cs @@ -96,7 +96,7 @@ namespace Microsoft.AspNetCore.Components.Server.Circuits public IServiceProvider Services { get; } - public Task PrerenderComponentAsync(Type componentType, ParameterCollection parameters) + public Task PrerenderComponentAsync(Type componentType, ParameterView parameters) { return Renderer.Dispatcher.InvokeAsync(async () => { diff --git a/src/Components/Server/src/Prerendering/ComponentPrerenderingContext.cs b/src/Components/Server/src/Prerendering/ComponentPrerenderingContext.cs index 436c27b31a..f423bf9ce6 100644 --- a/src/Components/Server/src/Prerendering/ComponentPrerenderingContext.cs +++ b/src/Components/Server/src/Prerendering/ComponentPrerenderingContext.cs @@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.Components.Server /// /// Gets or sets the parameters for the component. /// - public ParameterCollection Parameters { get; set; } + public ParameterView Parameters { get; set; } /// /// Gets or sets the in which the prerendering has been initiated. diff --git a/src/Components/Server/test/Circuits/CircuitHostTest.cs b/src/Components/Server/test/Circuits/CircuitHostTest.cs index 8004c5cd08..58803a56b2 100644 --- a/src/Components/Server/test/Circuits/CircuitHostTest.cs +++ b/src/Components/Server/test/Circuits/CircuitHostTest.cs @@ -275,7 +275,7 @@ namespace Microsoft.AspNetCore.Components.Server.Circuits public bool DidCallDispose { get; private set; } public void Attach(RenderHandle renderHandle) { } - public Task SetParametersAsync(ParameterCollection parameters) + public Task SetParametersAsync(ParameterView parameters) => Task.CompletedTask; public void Dispose() diff --git a/src/Components/Server/test/Circuits/CircuitPrerendererTest.cs b/src/Components/Server/test/Circuits/CircuitPrerendererTest.cs index 812442facd..8d54c3e257 100644 --- a/src/Components/Server/test/Circuits/CircuitPrerendererTest.cs +++ b/src/Components/Server/test/Circuits/CircuitPrerendererTest.cs @@ -55,7 +55,7 @@ namespace Microsoft.AspNetCore.Components.Server.Tests.Circuits var prerenderingContext = new ComponentPrerenderingContext { ComponentType = typeof(UriDisplayComponent), - Parameters = ParameterCollection.Empty, + Parameters = ParameterView.Empty, Context = httpContext }; @@ -109,7 +109,7 @@ namespace Microsoft.AspNetCore.Components.Server.Tests.Circuits var prerenderingContext = new ComponentPrerenderingContext { ComponentType = typeof(UriDisplayComponent), - Parameters = ParameterCollection.Empty, + Parameters = ParameterView.Empty, Context = httpContext }; @@ -145,7 +145,7 @@ namespace Microsoft.AspNetCore.Components.Server.Tests.Circuits var prerenderingContext = new ComponentPrerenderingContext { ComponentType = typeof(UriDisplayComponent), - Parameters = ParameterCollection.Empty, + Parameters = ParameterView.Empty, Context = httpContext }; @@ -170,7 +170,7 @@ namespace Microsoft.AspNetCore.Components.Server.Tests.Circuits var prerenderingContext = new ComponentPrerenderingContext { ComponentType = typeof(ThrowExceptionComponent), - Parameters = ParameterCollection.Empty, + Parameters = ParameterView.Empty, Context = httpContext }; @@ -227,7 +227,7 @@ namespace Microsoft.AspNetCore.Components.Server.Tests.Circuits _renderHandle = renderHandle; } - public Task SetParametersAsync(ParameterCollection parameters) + public Task SetParametersAsync(ParameterView parameters) { _renderHandle.Render(builder => { @@ -246,7 +246,7 @@ namespace Microsoft.AspNetCore.Components.Server.Tests.Circuits public void Attach(RenderHandle renderHandle) => throw new InvalidTimeZoneException(); - public Task SetParametersAsync(ParameterCollection parameters) + public Task SetParametersAsync(ParameterView parameters) => Task.CompletedTask; } } diff --git a/src/Components/Server/test/Circuits/RemoteRendererTest.cs b/src/Components/Server/test/Circuits/RemoteRendererTest.cs index aa584d9308..ffb913544a 100644 --- a/src/Components/Server/test/Circuits/RemoteRendererTest.cs +++ b/src/Components/Server/test/Circuits/RemoteRendererTest.cs @@ -139,7 +139,7 @@ namespace Microsoft.AspNetCore.Components.Web.Rendering // This produces the initial batch (id = 2) var result = await renderer.RenderComponentAsync( - ParameterCollection.FromDictionary(new Dictionary + ParameterView.FromDictionary(new Dictionary { [nameof(AutoParameterTestComponent.Content)] = initialContent, [nameof(AutoParameterTestComponent.Trigger)] = trigger @@ -202,7 +202,7 @@ namespace Microsoft.AspNetCore.Components.Web.Rendering // This produces the initial batch (id = 2) var result = await renderer.RenderComponentAsync( - ParameterCollection.FromDictionary(new Dictionary + ParameterView.FromDictionary(new Dictionary { [nameof(AutoParameterTestComponent.Content)] = initialContent, [nameof(AutoParameterTestComponent.Trigger)] = trigger @@ -265,7 +265,7 @@ namespace Microsoft.AspNetCore.Components.Web.Rendering // This produces the initial batch (id = 2) var result = await renderer.RenderComponentAsync( - ParameterCollection.FromDictionary(new Dictionary + ParameterView.FromDictionary(new Dictionary { [nameof(AutoParameterTestComponent.Content)] = initialContent, [nameof(AutoParameterTestComponent.Trigger)] = trigger @@ -322,7 +322,7 @@ namespace Microsoft.AspNetCore.Components.Web.Rendering // This produces the initial batch (id = 2) var result = await renderer.RenderComponentAsync( - ParameterCollection.FromDictionary(new Dictionary + ParameterView.FromDictionary(new Dictionary { [nameof(AutoParameterTestComponent.Content)] = initialContent, [nameof(AutoParameterTestComponent.Trigger)] = trigger @@ -366,8 +366,8 @@ namespace Microsoft.AspNetCore.Components.Web.Rendering new CircuitClientProxy()); // Act - var first = await renderer.RenderComponentAsync(ParameterCollection.Empty); - var second = await renderer.RenderComponentAsync(ParameterCollection.Empty); + var first = await renderer.RenderComponentAsync(ParameterView.Empty); + var second = await renderer.RenderComponentAsync(ParameterView.Empty); // Assert Assert.Equal(0, first.ComponentId); @@ -427,7 +427,7 @@ namespace Microsoft.AspNetCore.Components.Web.Rendering return Task.CompletedTask; } - public Task SetParametersAsync(ParameterCollection parameters) + public Task SetParametersAsync(ParameterView parameters) { TriggerRender(); return Task.CompletedTask; @@ -453,7 +453,7 @@ namespace Microsoft.AspNetCore.Components.Web.Rendering _renderHandle = renderHandle; } - public Task SetParametersAsync(ParameterCollection parameters) + public Task SetParametersAsync(ParameterView parameters) { Content = parameters.GetValueOrDefault(nameof(Content)); Trigger ??= parameters.GetValueOrDefault(nameof(Trigger)); diff --git a/src/Components/Server/test/Circuits/RenderBatchWriterTest.cs b/src/Components/Server/test/Circuits/RenderBatchWriterTest.cs index febb5e381d..b52862bb2d 100644 --- a/src/Components/Server/test/Circuits/RenderBatchWriterTest.cs +++ b/src/Components/Server/test/Circuits/RenderBatchWriterTest.cs @@ -374,7 +374,7 @@ namespace Microsoft.AspNetCore.Components.Server public void Attach(RenderHandle renderHandle) => throw new NotImplementedException(); - public Task SetParametersAsync(ParameterCollection parameters) + public Task SetParametersAsync(ParameterView parameters) => throw new NotImplementedException(); } diff --git a/src/Components/Shared/test/AutoRenderComponent.cs b/src/Components/Shared/test/AutoRenderComponent.cs index 8ebe6034bb..c446034950 100644 --- a/src/Components/Shared/test/AutoRenderComponent.cs +++ b/src/Components/Shared/test/AutoRenderComponent.cs @@ -18,7 +18,7 @@ namespace Microsoft.AspNetCore.Components.Test.Helpers _renderHandle = renderHandle; } - public virtual Task SetParametersAsync(ParameterCollection parameters) + public virtual Task SetParametersAsync(ParameterView parameters) { parameters.SetParameterProperties(this); TriggerRender(); diff --git a/src/Components/Shared/test/IComponentExtensions.cs b/src/Components/Shared/test/IComponentExtensions.cs index 58a673c895..93d48ee9a4 100644 --- a/src/Components/Shared/test/IComponentExtensions.cs +++ b/src/Components/Shared/test/IComponentExtensions.cs @@ -13,27 +13,7 @@ namespace Microsoft.AspNetCore.Components.Test.Helpers this IComponent component, Dictionary parameters) { - component.SetParametersAsync(DictionaryToParameterCollection(parameters)); - } - - private static ParameterCollection DictionaryToParameterCollection( - IDictionary parameters) - { - var builder = new RenderTreeBuilder(); - builder.OpenComponent(0); - foreach (var pair in parameters) - { - builder.AddAttribute(0, pair.Key, pair.Value); - } - builder.CloseElement(); - - return new ParameterCollection(builder.GetFrames().Array, 0); - } - - private abstract class AbstractComponent : IComponent - { - public abstract void Attach(RenderHandle renderHandle); - public abstract Task SetParametersAsync(ParameterCollection parameters); + component.SetParametersAsync(ParameterView.FromDictionary(parameters)); } } } diff --git a/src/Components/Shared/test/TestRenderer.cs b/src/Components/Shared/test/TestRenderer.cs index 944be7ec87..6b5f751818 100644 --- a/src/Components/Shared/test/TestRenderer.cs +++ b/src/Components/Shared/test/TestRenderer.cs @@ -48,16 +48,16 @@ namespace Microsoft.AspNetCore.Components.Test.Helpers public new int AssignRootComponentId(IComponent component) => base.AssignRootComponentId(component); - public void RenderRootComponent(int componentId, ParameterCollection? parameters = default) + public void RenderRootComponent(int componentId, ParameterView? parameters = default) { - var task = Dispatcher.InvokeAsync(() => base.RenderRootComponentAsync(componentId, parameters ?? ParameterCollection.Empty)); + var task = Dispatcher.InvokeAsync(() => base.RenderRootComponentAsync(componentId, parameters ?? ParameterView.Empty)); UnwrapTask(task); } public new Task RenderRootComponentAsync(int componentId) => Dispatcher.InvokeAsync(() => base.RenderRootComponentAsync(componentId)); - public new Task RenderRootComponentAsync(int componentId, ParameterCollection parameters) + public new Task RenderRootComponentAsync(int componentId, ParameterView parameters) => Dispatcher.InvokeAsync(() => base.RenderRootComponentAsync(componentId, parameters)); public Task DispatchEventAsync(ulong eventHandlerId, UIEventArgs args) diff --git a/src/Components/Web/ref/Microsoft.AspNetCore.Components.Web.netstandard2.0.cs b/src/Components/Web/ref/Microsoft.AspNetCore.Components.Web.netstandard2.0.cs index 46b4c3d7bb..f577a47088 100644 --- a/src/Components/Web/ref/Microsoft.AspNetCore.Components.Web.netstandard2.0.cs +++ b/src/Components/Web/ref/Microsoft.AspNetCore.Components.Web.netstandard2.0.cs @@ -317,7 +317,7 @@ namespace Microsoft.AspNetCore.Components.Forms [Microsoft.AspNetCore.Components.ParameterAttribute] public System.Linq.Expressions.Expression> ValueExpression { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } protected virtual string FormatValueAsString(T value) { throw null; } - public override System.Threading.Tasks.Task SetParametersAsync(Microsoft.AspNetCore.Components.ParameterCollection parameters) { throw null; } + public override System.Threading.Tasks.Task SetParametersAsync(Microsoft.AspNetCore.Components.ParameterView parameters) { throw null; } protected abstract bool TryParseValueFromString(string value, out T result, out string validationErrorMessage); } public partial class InputCheckbox : Microsoft.AspNetCore.Components.Forms.InputBase diff --git a/src/Components/Web/src/Forms/InputBase.cs b/src/Components/Web/src/Forms/InputBase.cs index fe6c345bf2..b103ad0d8b 100644 --- a/src/Components/Web/src/Forms/InputBase.cs +++ b/src/Components/Web/src/Forms/InputBase.cs @@ -168,7 +168,7 @@ namespace Microsoft.AspNetCore.Components.Forms /// - public override Task SetParametersAsync(ParameterCollection parameters) + public override Task SetParametersAsync(ParameterView parameters) { parameters.SetParameterProperties(this); @@ -206,7 +206,7 @@ namespace Microsoft.AspNetCore.Components.Forms } // For derived components, retain the usual lifecycle with OnInit/OnParametersSet/etc. - return base.SetParametersAsync(ParameterCollection.Empty); + return base.SetParametersAsync(ParameterView.Empty); } } } diff --git a/src/Components/test/Ignitor.Test/RenderBatchReaderTest.cs b/src/Components/test/Ignitor.Test/RenderBatchReaderTest.cs index 6d3f996367..dbd46a0e16 100644 --- a/src/Components/test/Ignitor.Test/RenderBatchReaderTest.cs +++ b/src/Components/test/Ignitor.Test/RenderBatchReaderTest.cs @@ -331,7 +331,7 @@ namespace Ignitor public void Attach(RenderHandle renderHandle) => throw new NotImplementedException(); - public Task SetParametersAsync(ParameterCollection parameters) + public Task SetParametersAsync(ParameterView parameters) => throw new NotImplementedException(); } diff --git a/src/Components/test/testassets/Ignitor/RenderBatchReader.cs b/src/Components/test/testassets/Ignitor/RenderBatchReader.cs index 06940be7ea..324f4af88f 100644 --- a/src/Components/test/testassets/Ignitor/RenderBatchReader.cs +++ b/src/Components/test/testassets/Ignitor/RenderBatchReader.cs @@ -310,7 +310,7 @@ namespace Ignitor public void Attach(RenderHandle renderHandle) => throw new NotImplementedException(); - public Task SetParametersAsync(ParameterCollection parameters) + public Task SetParametersAsync(ParameterView parameters) => throw new NotImplementedException(); } } diff --git a/src/Mvc/Mvc.Components.Prerendering/src/HtmlHelperComponentPrerenderingExtensions.cs b/src/Mvc/Mvc.Components.Prerendering/src/HtmlHelperComponentPrerenderingExtensions.cs index e6e03f175c..8989149268 100644 --- a/src/Mvc/Mvc.Components.Prerendering/src/HtmlHelperComponentPrerenderingExtensions.cs +++ b/src/Mvc/Mvc.Components.Prerendering/src/HtmlHelperComponentPrerenderingExtensions.cs @@ -58,8 +58,8 @@ namespace Microsoft.AspNetCore.Mvc.Rendering } var parametersCollection = parameters == null ? - ParameterCollection.Empty : - ParameterCollection.FromDictionary(HtmlHelper.ObjectToDictionary(parameters)); + ParameterView.Empty : + ParameterView.FromDictionary(HtmlHelper.ObjectToDictionary(parameters)); var result = await prerenderer.PrerenderComponentAsync( new ComponentPrerenderingContext diff --git a/src/Mvc/Mvc.Components.Prerendering/test/HtmlHelperComponentPrerenderingExtensionsTests.cs b/src/Mvc/Mvc.Components.Prerendering/test/HtmlHelperComponentPrerenderingExtensionsTests.cs index 4e6c2a6c0d..76a54c5dec 100644 --- a/src/Mvc/Mvc.Components.Prerendering/test/HtmlHelperComponentPrerenderingExtensionsTests.cs +++ b/src/Mvc/Mvc.Components.Prerendering/test/HtmlHelperComponentPrerenderingExtensionsTests.cs @@ -277,7 +277,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures _renderHandle = renderHandle; } - public Task SetParametersAsync(ParameterCollection parameters) + public Task SetParametersAsync(ParameterView parameters) { _renderHandle.Render(builder => { diff --git a/src/Mvc/Mvc.ViewFeatures/src/HtmlHelperRazorComponentExtensions.cs b/src/Mvc/Mvc.ViewFeatures/src/HtmlHelperRazorComponentExtensions.cs index baf194f4fe..ae06a6219d 100644 --- a/src/Mvc/Mvc.ViewFeatures/src/HtmlHelperRazorComponentExtensions.cs +++ b/src/Mvc/Mvc.ViewFeatures/src/HtmlHelperRazorComponentExtensions.cs @@ -52,8 +52,8 @@ namespace Microsoft.AspNetCore.Mvc.Rendering var prerenderer = serviceProvider.GetRequiredService(); var parametersCollection = parameters == null ? - ParameterCollection.Empty : - ParameterCollection.FromDictionary(HtmlHelper.ObjectToDictionary(parameters)); + ParameterView.Empty : + ParameterView.FromDictionary(HtmlHelper.ObjectToDictionary(parameters)); var result = await prerenderer.PrerenderComponentAsync( parametersCollection, diff --git a/src/Mvc/Mvc.ViewFeatures/src/RazorComponents/StaticComponentRenderer.cs b/src/Mvc/Mvc.ViewFeatures/src/RazorComponents/StaticComponentRenderer.cs index cfe1e7caf5..daae4ddbb1 100644 --- a/src/Mvc/Mvc.ViewFeatures/src/RazorComponents/StaticComponentRenderer.cs +++ b/src/Mvc/Mvc.ViewFeatures/src/RazorComponents/StaticComponentRenderer.cs @@ -26,7 +26,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.RazorComponents } public async Task> PrerenderComponentAsync( - ParameterCollection parameters, + ParameterView parameters, HttpContext httpContext, Type componentType) { diff --git a/src/Mvc/Mvc.ViewFeatures/test/HtmlHelperComponentExtensionsTests.cs b/src/Mvc/Mvc.ViewFeatures/test/HtmlHelperComponentExtensionsTests.cs index 4467e432a4..db1f591feb 100644 --- a/src/Mvc/Mvc.ViewFeatures/test/HtmlHelperComponentExtensionsTests.cs +++ b/src/Mvc/Mvc.ViewFeatures/test/HtmlHelperComponentExtensionsTests.cs @@ -256,7 +256,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Test _renderHandle = renderHandle; } - public Task SetParametersAsync(ParameterCollection parameters) + public Task SetParametersAsync(ParameterView parameters) { _renderHandle.Render(builder => {