Blazor API Review: Parameters (#12547)
* Blazor API Review: Parameters Part of #11610
This commit is contained in:
parent
5631b97d12
commit
bfd4305fd8
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -165,7 +165,7 @@ namespace Test
|
|||
{
|
||||
public class MyComponent : ComponentBase, IComponent
|
||||
{
|
||||
Task IComponent.SetParametersAsync(ParameterCollection parameters)
|
||||
Task IComponent.SetParametersAsync(ParameterView parameters)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -153,7 +153,7 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test
|
|||
{
|
||||
}
|
||||
|
||||
public Task SetParametersAsync(ParameterCollection parameters)
|
||||
public Task SetParametersAsync(ParameterView parameters)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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<string, object> 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<string, object> parameters) { throw null; }
|
||||
public Microsoft.AspNetCore.Components.ParameterEnumerator GetEnumerator() { throw null; }
|
||||
public T GetValueOrDefault<T>(string parameterName) { throw null; }
|
||||
public T GetValueOrDefault<T>(string parameterName, T defaultValue) { throw null; }
|
||||
public System.Collections.Generic.IReadOnlyDictionary<string, object> ToDictionary() { throw null; }
|
||||
public bool TryGetValue<T>(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<string, object> parameters) { throw null; }
|
||||
public Microsoft.AspNetCore.Components.ParameterView.Enumerator GetEnumerator() { throw null; }
|
||||
public T GetValueOrDefault<T>(string parameterName) { throw null; }
|
||||
public T GetValueOrDefault<T>(string parameterName, T defaultValue) { throw null; }
|
||||
public void SetParameterProperties(object target) { }
|
||||
public System.Collections.Generic.IReadOnlyDictionary<string, object> ToDictionary() { throw null; }
|
||||
public bool TryGetValue<T>(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>(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<Microsoft.AspNetCore.Components.Rendering.ComponentRenderedText> RenderComponentAsync(System.Type componentType, Microsoft.AspNetCore.Components.ParameterCollection initialParameters) { throw null; }
|
||||
public System.Threading.Tasks.Task<Microsoft.AspNetCore.Components.Rendering.ComponentRenderedText> RenderComponentAsync<TComponent>(Microsoft.AspNetCore.Components.ParameterCollection initialParameters) where TComponent : Microsoft.AspNetCore.Components.IComponent { throw null; }
|
||||
public System.Threading.Tasks.Task<Microsoft.AspNetCore.Components.Rendering.ComponentRenderedText> RenderComponentAsync(System.Type componentType, Microsoft.AspNetCore.Components.ParameterView initialParameters) { throw null; }
|
||||
public System.Threading.Tasks.Task<Microsoft.AspNetCore.Components.Rendering.ComponentRenderedText> RenderComponentAsync<TComponent>(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<string, object> 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; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<ReflectedCascadingParameterInfo> result = null;
|
||||
var candidateProps = ParameterCollectionExtensions.GetCandidateBindableProperties(componentType);
|
||||
var candidateProps = ComponentProperties.GetCandidateBindableProperties(componentType);
|
||||
foreach (var prop in candidateProps)
|
||||
{
|
||||
var attribute = prop.GetCustomAttribute<CascadingParameterAttribute>();
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ namespace Microsoft.AspNetCore.Components
|
|||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
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 <CascadingValue> 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.
|
||||
|
|
|
|||
|
|
@ -175,7 +175,7 @@ namespace Microsoft.AspNetCore.Components
|
|||
/// Method invoked to apply initial or updated parameters to the component.
|
||||
/// </summary>
|
||||
/// <param name="parameters">The parameters to apply.</param>
|
||||
public virtual Task SetParametersAsync(ParameterCollection parameters)
|
||||
public virtual Task SetParametersAsync(ParameterView parameters)
|
||||
{
|
||||
parameters.SetParameterProperties(this);
|
||||
if (!_initialized)
|
||||
|
|
|
|||
|
|
@ -21,6 +21,6 @@ namespace Microsoft.AspNetCore.Components
|
|||
/// </summary>
|
||||
/// <param name="parameters">The parameters.</param>
|
||||
/// <returns>A <see cref="Task"/> that completes when the component has finished updating and rendering itself.</returns>
|
||||
Task SetParametersAsync(ParameterCollection parameters);
|
||||
Task SetParametersAsync(ParameterView parameters);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ namespace Microsoft.AspNetCore.Components
|
|||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task SetParametersAsync(ParameterCollection parameters)
|
||||
public Task SetParametersAsync(ParameterView parameters)
|
||||
{
|
||||
parameters.SetParameterProperties(this);
|
||||
Render();
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// An enumerator that iterates through a <see cref="ParameterCollection"/>.
|
||||
/// </summary>
|
||||
public struct ParameterEnumerator
|
||||
{
|
||||
private RenderTreeFrameParameterEnumerator _directParamsEnumerator;
|
||||
private CascadingParameterEnumerator _cascadingParameterEnumerator;
|
||||
private bool _isEnumeratingDirectParams;
|
||||
|
||||
internal ParameterEnumerator(RenderTreeFrame[] frames, int ownerIndex, IReadOnlyList<CascadingParameterState> cascadingParameters)
|
||||
{
|
||||
_directParamsEnumerator = new RenderTreeFrameParameterEnumerator(frames, ownerIndex);
|
||||
_cascadingParameterEnumerator = new CascadingParameterEnumerator(cascadingParameters);
|
||||
_isEnumeratingDirectParams = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current value of the enumerator.
|
||||
/// </summary>
|
||||
public Parameter Current => _isEnumeratingDirectParams
|
||||
? _directParamsEnumerator.Current
|
||||
: _cascadingParameterEnumerator.Current;
|
||||
|
||||
/// <summary>
|
||||
/// Instructs the enumerator to move to the next value in the sequence.
|
||||
/// </summary>
|
||||
/// <returns>A flag to indicate whether or not there is a next value.</returns>
|
||||
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<CascadingParameterState> _cascadingParameters;
|
||||
private int _currentIndex;
|
||||
private Parameter _current;
|
||||
|
||||
public CascadingParameterEnumerator(IReadOnlyList<CascadingParameterState> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -7,8 +7,15 @@ namespace Microsoft.AspNetCore.Components
|
|||
/// Represents a single parameter supplied to an <see cref="IComponent"/>
|
||||
/// by its parent in the render tree.
|
||||
/// </summary>
|
||||
public readonly struct Parameter
|
||||
public readonly struct ParameterValue
|
||||
{
|
||||
internal ParameterValue(string name, object value, bool cascading)
|
||||
{
|
||||
Name = name;
|
||||
Value = value;
|
||||
Cascading = cascading;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the parameter.
|
||||
/// </summary>
|
||||
|
|
@ -24,12 +31,5 @@ namespace Microsoft.AspNetCore.Components
|
|||
/// was supplied by a <see cref="CascadingValue{T}"/>.
|
||||
/// </summary>
|
||||
public bool Cascading { get; }
|
||||
|
||||
internal Parameter(string name, object value, bool cascading)
|
||||
{
|
||||
Name = name;
|
||||
Value = value;
|
||||
Cascading = cascading;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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 <see cref="IComponent"/>
|
||||
/// by its parent in the render tree.
|
||||
/// </summary>
|
||||
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<CascadingParameterState> _cascadingParametersOrNull;
|
||||
|
||||
internal ParameterCollection(RenderTreeFrame[] frames, int ownerIndex)
|
||||
internal ParameterView(RenderTreeFrame[] frames, int ownerIndex)
|
||||
: this(frames, ownerIndex, null)
|
||||
{
|
||||
}
|
||||
|
||||
private ParameterCollection(RenderTreeFrame[] frames, int ownerIndex, IReadOnlyList<CascadingParameterState> cascadingParametersOrNull)
|
||||
private ParameterView(RenderTreeFrame[] frames, int ownerIndex, IReadOnlyList<CascadingParameterState> cascadingParametersOrNull)
|
||||
{
|
||||
_frames = frames;
|
||||
_ownerIndex = ownerIndex;
|
||||
|
|
@ -39,16 +39,16 @@ namespace Microsoft.AspNetCore.Components
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets an empty <see cref="ParameterCollection"/>.
|
||||
/// Gets an empty <see cref="ParameterView"/>.
|
||||
/// </summary>
|
||||
public static ParameterCollection Empty => _emptyCollection;
|
||||
public static ParameterView Empty => _empty;
|
||||
|
||||
/// <summary>
|
||||
/// Returns an enumerator that iterates through the <see cref="ParameterCollection"/>.
|
||||
/// Returns an enumerator that iterates through the <see cref="ParameterView"/>.
|
||||
/// </summary>
|
||||
/// <returns>The enumerator.</returns>
|
||||
public ParameterEnumerator GetEnumerator()
|
||||
=> new ParameterEnumerator(_frames, _ownerIndex, _cascadingParametersOrNull);
|
||||
public Enumerator GetEnumerator()
|
||||
=> new Enumerator(_frames, _ownerIndex, _cascadingParametersOrNull);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the value of the parameter with the specified name.
|
||||
|
|
@ -94,9 +94,9 @@ namespace Microsoft.AspNetCore.Components
|
|||
=> TryGetValue<T>(parameterName, out T result) ? result : defaultValue;
|
||||
|
||||
/// <summary>
|
||||
/// Returns a dictionary populated with the contents of the <see cref="ParameterCollection"/>.
|
||||
/// Returns a dictionary populated with the contents of the <see cref="ParameterView"/>.
|
||||
/// </summary>
|
||||
/// <returns>A dictionary populated with the contents of the <see cref="ParameterCollection"/>.</returns>
|
||||
/// <returns>A dictionary populated with the contents of the <see cref="ParameterView"/>.</returns>
|
||||
public IReadOnlyDictionary<string, object> ToDictionary()
|
||||
{
|
||||
var result = new Dictionary<string, object>();
|
||||
|
|
@ -107,13 +107,13 @@ namespace Microsoft.AspNetCore.Components
|
|||
return result;
|
||||
}
|
||||
|
||||
internal ParameterCollection WithCascadingParameters(IReadOnlyList<CascadingParameterState> cascadingParameters)
|
||||
=> new ParameterCollection(_frames, _ownerIndex, cascadingParameters);
|
||||
internal ParameterView WithCascadingParameters(IReadOnlyList<CascadingParameterState> 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
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ParameterCollection"/> from the given <see cref="IDictionary{TKey, TValue}"/>.
|
||||
/// Creates a new <see cref="ParameterView"/> from the given <see cref="IDictionary{TKey, TValue}"/>.
|
||||
/// </summary>
|
||||
/// <param name="parameters">The <see cref="IDictionary{TKey, TValue}"/> with the parameters.</param>
|
||||
/// <returns>A <see cref="ParameterCollection"/>.</returns>
|
||||
public static ParameterCollection FromDictionary(IDictionary<string, object> parameters)
|
||||
/// <returns>A <see cref="ParameterView"/>.</returns>
|
||||
public static ParameterView FromDictionary(IDictionary<string, object> 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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// For each parameter property on <paramref name="target"/>, updates its value to
|
||||
/// match the corresponding entry in the <see cref="ParameterView"/>.
|
||||
/// </summary>
|
||||
/// <param name="target">An object that has a public writable property matching each parameter's name and type.</param>
|
||||
public void SetParameterProperties(object target)
|
||||
{
|
||||
if (target is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(target));
|
||||
}
|
||||
|
||||
ComponentProperties.SetProperties(this, target);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// An enumerator that iterates through a <see cref="ParameterView"/>.
|
||||
/// </summary>
|
||||
|
||||
// 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<CascadingParameterState> cascadingParameters)
|
||||
{
|
||||
_directParamsEnumerator = new RenderTreeFrameParameterEnumerator(frames, ownerIndex);
|
||||
_cascadingParameterEnumerator = new CascadingParameterEnumerator(cascadingParameters);
|
||||
_isEnumeratingDirectParams = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current value of the enumerator.
|
||||
/// </summary>
|
||||
public ParameterValue Current => _isEnumeratingDirectParams
|
||||
? _directParamsEnumerator.Current
|
||||
: _cascadingParameterEnumerator.Current;
|
||||
|
||||
/// <summary>
|
||||
/// Instructs the enumerator to move to the next value in the sequence.
|
||||
/// </summary>
|
||||
/// <returns>A flag to indicate whether or not there is a next value.</returns>
|
||||
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<CascadingParameterState> _cascadingParameters;
|
||||
private int _currentIndex;
|
||||
private ParameterValue _current;
|
||||
|
||||
public CascadingParameterEnumerator(IReadOnlyList<CascadingParameterState> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension methods for the <see cref="ParameterCollection"/> type.
|
||||
/// </summary>
|
||||
public static class ParameterCollectionExtensions
|
||||
internal static class ComponentProperties
|
||||
{
|
||||
private const BindingFlags _bindablePropertyFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.IgnoreCase;
|
||||
|
||||
private readonly static ConcurrentDictionary<Type, WritersForType> _cachedWritersByType
|
||||
= new ConcurrentDictionary<Type, WritersForType>();
|
||||
|
||||
/// <summary>
|
||||
/// For each parameter property on <paramref name="target"/>, updates its value to
|
||||
/// match the corresponding entry in the <see cref="ParameterCollection"/>.
|
||||
/// </summary>
|
||||
/// <param name="parameterCollection">The <see cref="ParameterCollection"/>.</param>
|
||||
/// <param name="target">An object that has a public writable property matching each parameter's name and type.</param>
|
||||
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<string, object> unmatched = null;
|
||||
foreach (var parameter in parameterCollection)
|
||||
foreach (var parameter in parameters)
|
||||
{
|
||||
var parameterName = parameter.Name;
|
||||
if (string.Equals(parameterName, writers.CaptureUnmatchedValuesPropertyName, StringComparison.OrdinalIgnoreCase))
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
/// </summary>
|
||||
/// <param name="componentType">The type of the <see cref="IComponent"/>.</param>
|
||||
/// <param name="initialParameters">A <see cref="ParameterCollection"/> with the initial parameters to render the component.</param>
|
||||
/// <param name="initialParameters">A <see cref="ParameterView"/> with the initial parameters to render the component.</param>
|
||||
/// <returns>A <see cref="Task"/> that on completion returns a sequence of <see cref="string"/> fragments that represent the HTML text of the component.</returns>
|
||||
public async Task<ComponentRenderedText> RenderComponentAsync(Type componentType, ParameterCollection initialParameters)
|
||||
public async Task<ComponentRenderedText> 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.
|
||||
/// </summary>
|
||||
/// <typeparam name="TComponent">The type of the <see cref="IComponent"/>.</typeparam>
|
||||
/// <param name="initialParameters">A <see cref="ParameterCollection"/> with the initial parameters to render the component.</param>
|
||||
/// <param name="initialParameters">A <see cref="ParameterView"/> with the initial parameters to render the component.</param>
|
||||
/// <returns>A <see cref="Task"/> that on completion returns a sequence of <see cref="string"/> fragments that represent the HTML text of the component.</returns>
|
||||
public Task<ComponentRenderedText> RenderComponentAsync<TComponent>(ParameterCollection initialParameters) where TComponent : IComponent
|
||||
public Task<ComponentRenderedText> RenderComponentAsync<TComponent>(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<RenderTreeFrame>)> CreateInitialRenderAsync(Type componentType, ParameterCollection initialParameters)
|
||||
private async Task<(int, ArrayRange<RenderTreeFrame>)> CreateInitialRenderAsync(Type componentType, ParameterView initialParameters)
|
||||
{
|
||||
var component = InstantiateComponent(componentType);
|
||||
var componentId = AssignRootComponentId(component);
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ namespace Microsoft.AspNetCore.Components.Rendering
|
|||
/// </remarks>
|
||||
protected Task RenderRootComponentAsync(int componentId)
|
||||
{
|
||||
return RenderRootComponentAsync(componentId, ParameterCollection.Empty);
|
||||
return RenderRootComponentAsync(componentId, ParameterView.Empty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -120,12 +120,12 @@ namespace Microsoft.AspNetCore.Components.Rendering
|
|||
/// this more than once.
|
||||
/// </summary>
|
||||
/// <param name="componentId">The ID returned by <see cref="AssignRootComponentId(IComponent)"/>.</param>
|
||||
/// <param name="initialParameters">The <see cref="ParameterCollection"/>with the initial parameters to use for rendering.</param>
|
||||
/// <param name="initialParameters">The <see cref="ParameterView"/>with the initial parameters to use for rendering.</param>
|
||||
/// <remarks>
|
||||
/// 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.
|
||||
/// </remarks>
|
||||
protected async Task RenderRootComponentAsync(int componentId, ParameterCollection initialParameters)
|
||||
protected async Task RenderRootComponentAsync(int componentId, ParameterView initialParameters)
|
||||
{
|
||||
if (Interlocked.CompareExchange(ref _pendingTasks, new List<Task>(), null) != null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ namespace Microsoft.AspNetCore.Components.Routing
|
|||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task SetParametersAsync(ParameterCollection parameters)
|
||||
public Task SetParametersAsync(ParameterView parameters)
|
||||
{
|
||||
parameters.SetParameterProperties(this);
|
||||
Routes = RouteTableFactory.Create(AppAssembly);
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -645,7 +645,7 @@ namespace Microsoft.AspNetCore.Components
|
|||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task SetParametersAsync(ParameterCollection parameters)
|
||||
public Task SetParametersAsync(ParameterView parameters)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.Components.Test
|
|||
public void DisplaysComponentInsideLayout()
|
||||
{
|
||||
// Arrange/Act
|
||||
_renderer.Dispatcher.InvokeAsync(() => _pageDisplayComponent.SetParametersAsync(ParameterCollection.FromDictionary(new Dictionary<string, object>
|
||||
_renderer.Dispatcher.InvokeAsync(() => _pageDisplayComponent.SetParametersAsync(ParameterView.FromDictionary(new Dictionary<string, object>
|
||||
{
|
||||
{ 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<string, object>
|
||||
_renderer.Dispatcher.InvokeAsync(() => _pageDisplayComponent.SetParametersAsync(ParameterView.FromDictionary(new Dictionary<string, object>
|
||||
{
|
||||
{ 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<string, object>
|
||||
_renderer.Dispatcher.InvokeAsync(() => _pageDisplayComponent.SetParametersAsync(ParameterView.FromDictionary(new Dictionary<string, object>
|
||||
{
|
||||
{ nameof(PageDisplay.Page), typeof(ComponentWithLayout) }
|
||||
})));
|
||||
|
||||
// Act
|
||||
_renderer.Dispatcher.InvokeAsync(() => _pageDisplayComponent.SetParametersAsync(ParameterCollection.FromDictionary(new Dictionary<string, object>
|
||||
_renderer.Dispatcher.InvokeAsync(() => _pageDisplayComponent.SetParametersAsync(ParameterView.FromDictionary(new Dictionary<string, object>
|
||||
{
|
||||
{ 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<string, object>
|
||||
_renderer.Dispatcher.InvokeAsync(() => _pageDisplayComponent.SetParametersAsync(ParameterView.FromDictionary(new Dictionary<string, object>
|
||||
{
|
||||
{ nameof(PageDisplay.Page), typeof(ComponentWithLayout) }
|
||||
})));
|
||||
|
||||
// Act
|
||||
_renderer.Dispatcher.InvokeAsync(() => _pageDisplayComponent.SetParametersAsync(ParameterCollection.FromDictionary(new Dictionary<string, object>
|
||||
_renderer.Dispatcher.InvokeAsync(() => _pageDisplayComponent.SetParametersAsync(ParameterView.FromDictionary(new Dictionary<string, object>
|
||||
{
|
||||
{ nameof(PageDisplay.Page), typeof(ComponentWithNestedLayout) }
|
||||
})));
|
||||
|
|
|
|||
|
|
@ -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<InvalidOperationException>(
|
||||
() => 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<InvalidOperationException>(
|
||||
() => 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<string, object>();
|
||||
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<string, object>() },
|
||||
{ "test1", 123 },
|
||||
|
|
@ -200,7 +200,7 @@ namespace Microsoft.AspNetCore.Components.Test
|
|||
}.Build();
|
||||
|
||||
// Act
|
||||
var ex = Assert.Throws<InvalidOperationException>(() => parameterCollection.SetParameterProperties(target));
|
||||
var ex = Assert.Throws<InvalidOperationException>(() => 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<InvalidOperationException>(() => parameterCollection.SetParameterProperties(target));
|
||||
var ex = Assert.Throws<InvalidOperationException>(() => 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<InvalidOperationException>(() => parameterCollection.SetParameterProperties(target));
|
||||
var ex = Assert.Throws<InvalidOperationException>(() => 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<InvalidOperationException>(() => parameterCollection.SetParameterProperties(target));
|
||||
var ex = Assert.Throws<InvalidOperationException>(() => 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<InvalidOperationException>(
|
||||
() => 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<InvalidOperationException>(
|
||||
() => 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<InvalidOperationException>(() =>
|
||||
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<InvalidOperationException>(() =>
|
||||
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<string, object>[] 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<FakeComponent>(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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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<string>("nonexisting entry", out var value);
|
||||
var didFind = parameters.TryGetValue<string>("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<string>("my entry", out var value);
|
||||
var didFind = parameters.TryGetValue<string>("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<object>("my entry");
|
||||
var result = parameters.GetValueOrDefault<object>("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<object>("my entry");
|
||||
var result = parameters.GetValueOrDefault<object>("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<DateTime>("nonexisting entry");
|
||||
var result = parameters.GetValueOrDefault<DateTime>("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<InvalidCastException>(() =>
|
||||
{
|
||||
parameterCollection.TryGetValue<bool>("my entry", out var value);
|
||||
parameters.TryGetValue<bool>("my entry", out var value);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -246,7 +246,7 @@ namespace Microsoft.AspNetCore.Components.Test
|
|||
var dictionary = new Dictionary<string, object>();
|
||||
|
||||
// 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<string, object> dict = parameterCollection.ToDictionary();
|
||||
IReadOnlyDictionary<string, object> 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<object>("my entry");
|
||||
var result = parameters.GetValueOrDefault<object>("my entry");
|
||||
|
||||
// Assert
|
||||
Assert.Same(myEntryValue, result);
|
||||
}
|
||||
|
||||
private Action<Parameter> AssertParameter(string expectedName, object expectedValue, bool expectedIsCascading)
|
||||
private Action<ParameterValue> AssertParameter(string expectedName, object expectedValue, bool expectedIsCascading)
|
||||
{
|
||||
return parameter =>
|
||||
{
|
||||
|
|
@ -332,9 +332,9 @@ namespace Microsoft.AspNetCore.Components.Test
|
|||
};
|
||||
}
|
||||
|
||||
public IEnumerable<Parameter> ToEnumerable(ParameterCollection parameterCollection)
|
||||
public IEnumerable<ParameterValue> 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();
|
||||
}
|
||||
|
||||
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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<string, object>
|
||||
await renderer.Dispatcher.InvokeAsync(() => renderer.RenderRootComponentAsync(componentId, ParameterView.FromDictionary(new Dictionary<string, object>
|
||||
{
|
||||
[EventActionsName] = new Dictionary<int, IList<NestedAsyncComponent.ExecutionAction>>
|
||||
{
|
||||
|
|
@ -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<string, object>
|
||||
await renderer.Dispatcher.InvokeAsync(() => renderer.RenderRootComponentAsync(componentId, ParameterView.FromDictionary(new Dictionary<string, object>
|
||||
{
|
||||
[EventActionsName] = new Dictionary<int, IList<NestedAsyncComponent.ExecutionAction>>
|
||||
{
|
||||
|
|
@ -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<string, object>
|
||||
await renderer.Dispatcher.InvokeAsync(() => renderer.RenderRootComponentAsync(componentId, ParameterView.FromDictionary(new Dictionary<string, object>
|
||||
{
|
||||
[EventActionsName] = new Dictionary<int, IList<NestedAsyncComponent.ExecutionAction>>
|
||||
{
|
||||
|
|
@ -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<string, object>
|
||||
await renderer.Dispatcher.InvokeAsync(() => renderer.RenderRootComponentAsync(componentId, ParameterView.FromDictionary(new Dictionary<string, object>
|
||||
{
|
||||
[EventActionsName] = new Dictionary<int, IList<NestedAsyncComponent.ExecutionAction>>
|
||||
{
|
||||
|
|
@ -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<string, object>
|
||||
var task = renderer.RenderRootComponentAsync(componentId, ParameterView.FromDictionary(new Dictionary<string, object>
|
||||
{
|
||||
[nameof(NestedAsyncComponent.EventActions)] = new Dictionary<int, IList<NestedAsyncComponent.ExecutionAction>>
|
||||
{
|
||||
|
|
@ -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<string, object>
|
||||
var renderTask = renderer.RenderRootComponentAsync(componentId, ParameterView.FromDictionary(new Dictionary<string, object>
|
||||
{
|
||||
[nameof(NestedAsyncComponent.EventActions)] = new Dictionary<int, IList<NestedAsyncComponent.ExecutionAction>>
|
||||
{
|
||||
|
|
@ -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<string, object>
|
||||
var renderTask = renderer.RenderRootComponentAsync(componentId, ParameterView.FromDictionary(new Dictionary<string, object>
|
||||
{
|
||||
[nameof(NestedAsyncComponent.EventActions)] = new Dictionary<int, IList<NestedAsyncComponent.ExecutionAction>>
|
||||
{
|
||||
|
|
@ -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<string, object>
|
||||
var renderTask = renderer.RenderRootComponentAsync(componentId, ParameterView.FromDictionary(new Dictionary<string, object>
|
||||
{
|
||||
[nameof(NestedAsyncComponent.EventActions)] = new Dictionary<int, IList<NestedAsyncComponent.ExecutionAction>>
|
||||
{
|
||||
|
|
@ -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<string, object>
|
||||
var renderTask = renderer.RenderRootComponentAsync(componentId, ParameterView.FromDictionary(new Dictionary<string, object>
|
||||
{
|
||||
[nameof(NestedAsyncComponent.EventActions)] = new Dictionary<int, IList<NestedAsyncComponent.ExecutionAction>>
|
||||
{
|
||||
|
|
@ -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<string, object>
|
||||
var renderTask = renderer.RenderRootComponentAsync(componentId, ParameterView.FromDictionary(new Dictionary<string, object>
|
||||
{
|
||||
[nameof(NestedAsyncComponent.EventActions)] = new Dictionary<int, IList<NestedAsyncComponent.ExecutionAction>>
|
||||
{
|
||||
|
|
@ -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<string, object>
|
||||
var renderTask = renderer.RenderRootComponentAsync(componentId, ParameterView.FromDictionary(new Dictionary<string, object>
|
||||
{
|
||||
[nameof(NestedAsyncComponent.EventActions)] = new Dictionary<int, IList<NestedAsyncComponent.ExecutionAction>>
|
||||
{
|
||||
|
|
@ -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<string, object>
|
||||
var renderTask = renderer.RenderRootComponentAsync(componentId, ParameterView.FromDictionary(new Dictionary<string, object>
|
||||
{
|
||||
[nameof(NestedAsyncComponent.EventActions)] = new Dictionary<int, IList<NestedAsyncComponent.ExecutionAction>>
|
||||
{
|
||||
|
|
@ -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<string, object>
|
||||
var renderTask = renderer.RenderRootComponentAsync(componentId, ParameterView.FromDictionary(new Dictionary<string, object>
|
||||
{
|
||||
[nameof(NestedAsyncComponent.EventActions)] = new Dictionary<int, IList<NestedAsyncComponent.ExecutionAction>>
|
||||
{
|
||||
|
|
@ -3195,7 +3195,7 @@ namespace Microsoft.AspNetCore.Components.Test
|
|||
|
||||
// Act/Assert
|
||||
var componentId = renderer.AssignRootComponentId(component);
|
||||
await renderer.RenderRootComponentAsync(componentId, ParameterCollection.FromDictionary(new Dictionary<string, object>
|
||||
await renderer.RenderRootComponentAsync(componentId, ParameterView.FromDictionary(new Dictionary<string, object>
|
||||
{
|
||||
[nameof(NestedAsyncComponent.EventActions)] = new Dictionary<int, IList<NestedAsyncComponent.ExecutionAction>>
|
||||
{
|
||||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ namespace Microsoft.AspNetCore.Components.Rendering
|
|||
var htmlRenderer = GetHtmlRenderer(serviceProvider);
|
||||
|
||||
// Act
|
||||
var result = GetResult(htmlRenderer.Dispatcher.InvokeAsync(() => htmlRenderer.RenderComponentAsync<TestComponent>(ParameterCollection.Empty)));
|
||||
var result = GetResult(htmlRenderer.Dispatcher.InvokeAsync(() => htmlRenderer.RenderComponentAsync<TestComponent>(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<TestComponent>(ParameterCollection.Empty)));
|
||||
var result = GetResult(htmlRenderer.Dispatcher.InvokeAsync(() => htmlRenderer.RenderComponentAsync<TestComponent>(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<TestComponent>(ParameterCollection.Empty)));
|
||||
var result = GetResult(htmlRenderer.Dispatcher.InvokeAsync(() => htmlRenderer.RenderComponentAsync<TestComponent>(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<TestComponent>(ParameterCollection.Empty)));
|
||||
var result = GetResult(htmlRenderer.Dispatcher.InvokeAsync(() => htmlRenderer.RenderComponentAsync<TestComponent>(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<TestComponent>(ParameterCollection.Empty)));
|
||||
var result = GetResult(htmlRenderer.Dispatcher.InvokeAsync(() => htmlRenderer.RenderComponentAsync<TestComponent>(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<TestComponent>(ParameterCollection.Empty)));
|
||||
var result = GetResult(htmlRenderer.Dispatcher.InvokeAsync(() => htmlRenderer.RenderComponentAsync<TestComponent>(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<TestComponent>(ParameterCollection.Empty)));
|
||||
var result = GetResult(htmlRenderer.Dispatcher.InvokeAsync(() => htmlRenderer.RenderComponentAsync<TestComponent>(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<TestComponent>(ParameterCollection.Empty)));
|
||||
var result = GetResult(htmlRenderer.Dispatcher.InvokeAsync(() => htmlRenderer.RenderComponentAsync<TestComponent>(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<TestComponent>(ParameterCollection.Empty)));
|
||||
var result = GetResult(htmlRenderer.Dispatcher.InvokeAsync(() => htmlRenderer.RenderComponentAsync<TestComponent>(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<TestComponent>(ParameterCollection.Empty)));
|
||||
var result = GetResult(htmlRenderer.Dispatcher.InvokeAsync(() => htmlRenderer.RenderComponentAsync<TestComponent>(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<TestComponent>(ParameterCollection.Empty)));
|
||||
var result = GetResult(htmlRenderer.Dispatcher.InvokeAsync(() => htmlRenderer.RenderComponentAsync<TestComponent>(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<TestComponent>(ParameterCollection.Empty)));
|
||||
var result = GetResult(htmlRenderer.Dispatcher.InvokeAsync(() => htmlRenderer.RenderComponentAsync<TestComponent>(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<TestComponent>(ParameterCollection.Empty)));
|
||||
var result = GetResult(htmlRenderer.Dispatcher.InvokeAsync(() => htmlRenderer.RenderComponentAsync<TestComponent>(ParameterView.Empty)));
|
||||
|
||||
// Assert
|
||||
Assert.Equal(expectedHtml, result);
|
||||
|
|
@ -339,7 +339,7 @@ namespace Microsoft.AspNetCore.Components.Rendering
|
|||
var expectedHtml = new[] {
|
||||
"<", "p", ">", "<", "input", " ", "value", "=", "\"", "5", "\"", " />", "</", "p", ">" };
|
||||
|
||||
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<ParameterCollection, RenderFragment>(Content))
|
||||
.AddSingleton(new Func<ParameterView, RenderFragment>(Content))
|
||||
.BuildServiceProvider();
|
||||
|
||||
var htmlRenderer = GetHtmlRenderer(serviceProvider);
|
||||
|
|
@ -358,7 +358,7 @@ namespace Microsoft.AspNetCore.Components.Rendering
|
|||
|
||||
// Act
|
||||
var result = GetResult(htmlRenderer.Dispatcher.InvokeAsync(() => htmlRenderer.RenderComponentAsync<ComponentWithParameters>(
|
||||
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<TestComponent>(ParameterCollection.Empty)));
|
||||
var result = GetResult(htmlRenderer.Dispatcher.InvokeAsync(() => htmlRenderer.RenderComponentAsync<TestComponent>(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<TestComponent>(ParameterCollection.Empty)));
|
||||
var result = GetResult(htmlRenderer.Dispatcher.InvokeAsync(() => htmlRenderer.RenderComponentAsync<TestComponent>(ParameterView.Empty)));
|
||||
|
||||
// Assert
|
||||
Assert.Equal(expectedHtml, result);
|
||||
|
|
@ -445,9 +445,9 @@ namespace Microsoft.AspNetCore.Components.Rendering
|
|||
}
|
||||
|
||||
[Inject]
|
||||
Func<ParameterCollection, RenderFragment> CreateRenderFragment { get; set; }
|
||||
Func<ParameterView, RenderFragment> 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<AsyncComponent>(ParameterCollection.FromDictionary(new Dictionary<string, object>
|
||||
var result = await htmlRenderer.Dispatcher.InvokeAsync(() => htmlRenderer.RenderComponentAsync<AsyncComponent>(ParameterView.FromDictionary(new Dictionary<string, object>
|
||||
{
|
||||
["Value"] = 10
|
||||
})));
|
||||
|
|
@ -489,7 +489,7 @@ namespace Microsoft.AspNetCore.Components.Rendering
|
|||
var htmlRenderer = GetHtmlRenderer(serviceProvider);
|
||||
|
||||
// Act
|
||||
var result = await htmlRenderer.Dispatcher.InvokeAsync(() => htmlRenderer.RenderComponentAsync<NestedAsyncComponent>(ParameterCollection.FromDictionary(new Dictionary<string, object>
|
||||
var result = await htmlRenderer.Dispatcher.InvokeAsync(() => htmlRenderer.RenderComponentAsync<NestedAsyncComponent>(ParameterView.FromDictionary(new Dictionary<string, object>
|
||||
{
|
||||
["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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ namespace Microsoft.AspNetCore.Components.Server.Circuits
|
|||
|
||||
public IServiceProvider Services { get; }
|
||||
|
||||
public Task<ComponentRenderedText> PrerenderComponentAsync(Type componentType, ParameterCollection parameters)
|
||||
public Task<ComponentRenderedText> PrerenderComponentAsync(Type componentType, ParameterView parameters)
|
||||
{
|
||||
return Renderer.Dispatcher.InvokeAsync(async () =>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.Components.Server
|
|||
/// <summary>
|
||||
/// Gets or sets the parameters for the component.
|
||||
/// </summary>
|
||||
public ParameterCollection Parameters { get; set; }
|
||||
public ParameterView Parameters { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="HttpContext"/> in which the prerendering has been initiated.
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -139,7 +139,7 @@ namespace Microsoft.AspNetCore.Components.Web.Rendering
|
|||
|
||||
// This produces the initial batch (id = 2)
|
||||
var result = await renderer.RenderComponentAsync<AutoParameterTestComponent>(
|
||||
ParameterCollection.FromDictionary(new Dictionary<string, object>
|
||||
ParameterView.FromDictionary(new Dictionary<string, object>
|
||||
{
|
||||
[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<AutoParameterTestComponent>(
|
||||
ParameterCollection.FromDictionary(new Dictionary<string, object>
|
||||
ParameterView.FromDictionary(new Dictionary<string, object>
|
||||
{
|
||||
[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<AutoParameterTestComponent>(
|
||||
ParameterCollection.FromDictionary(new Dictionary<string, object>
|
||||
ParameterView.FromDictionary(new Dictionary<string, object>
|
||||
{
|
||||
[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<AutoParameterTestComponent>(
|
||||
ParameterCollection.FromDictionary(new Dictionary<string, object>
|
||||
ParameterView.FromDictionary(new Dictionary<string, object>
|
||||
{
|
||||
[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<TestComponent>(ParameterCollection.Empty);
|
||||
var second = await renderer.RenderComponentAsync<TestComponent>(ParameterCollection.Empty);
|
||||
var first = await renderer.RenderComponentAsync<TestComponent>(ParameterView.Empty);
|
||||
var second = await renderer.RenderComponentAsync<TestComponent>(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<RenderFragment>(nameof(Content));
|
||||
Trigger ??= parameters.GetValueOrDefault<Trigger>(nameof(Trigger));
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -13,27 +13,7 @@ namespace Microsoft.AspNetCore.Components.Test.Helpers
|
|||
this IComponent component,
|
||||
Dictionary<string, object> parameters)
|
||||
{
|
||||
component.SetParametersAsync(DictionaryToParameterCollection(parameters));
|
||||
}
|
||||
|
||||
private static ParameterCollection DictionaryToParameterCollection(
|
||||
IDictionary<string, object> parameters)
|
||||
{
|
||||
var builder = new RenderTreeBuilder();
|
||||
builder.OpenComponent<AbstractComponent>(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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -317,7 +317,7 @@ namespace Microsoft.AspNetCore.Components.Forms
|
|||
[Microsoft.AspNetCore.Components.ParameterAttribute]
|
||||
public System.Linq.Expressions.Expression<System.Func<T>> 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<bool>
|
||||
|
|
|
|||
|
|
@ -168,7 +168,7 @@ namespace Microsoft.AspNetCore.Components.Forms
|
|||
|
||||
|
||||
/// <inheritdoc />
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -277,7 +277,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
|
|||
_renderHandle = renderHandle;
|
||||
}
|
||||
|
||||
public Task SetParametersAsync(ParameterCollection parameters)
|
||||
public Task SetParametersAsync(ParameterView parameters)
|
||||
{
|
||||
_renderHandle.Render(builder =>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -52,8 +52,8 @@ namespace Microsoft.AspNetCore.Mvc.Rendering
|
|||
var prerenderer = serviceProvider.GetRequiredService<StaticComponentRenderer>();
|
||||
|
||||
var parametersCollection = parameters == null ?
|
||||
ParameterCollection.Empty :
|
||||
ParameterCollection.FromDictionary(HtmlHelper.ObjectToDictionary(parameters));
|
||||
ParameterView.Empty :
|
||||
ParameterView.FromDictionary(HtmlHelper.ObjectToDictionary(parameters));
|
||||
|
||||
var result = await prerenderer.PrerenderComponentAsync(
|
||||
parametersCollection,
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.RazorComponents
|
|||
}
|
||||
|
||||
public async Task<IEnumerable<string>> PrerenderComponentAsync(
|
||||
ParameterCollection parameters,
|
||||
ParameterView parameters,
|
||||
HttpContext httpContext,
|
||||
Type componentType)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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 =>
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue