diff --git a/src/Components/Components/ref/Microsoft.AspNetCore.Components.netstandard2.0.cs b/src/Components/Components/ref/Microsoft.AspNetCore.Components.netstandard2.0.cs index 68325c4ec0..e3d29e6a52 100644 --- a/src/Components/Components/ref/Microsoft.AspNetCore.Components.netstandard2.0.cs +++ b/src/Components/Components/ref/Microsoft.AspNetCore.Components.netstandard2.0.cs @@ -114,7 +114,7 @@ namespace Microsoft.AspNetCore.Components public CascadingParameterAttribute() { } public string Name { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } } - public partial class CascadingValue : Microsoft.AspNetCore.Components.IComponent + public partial class CascadingValue : Microsoft.AspNetCore.Components.IComponent { public CascadingValue() { } [Microsoft.AspNetCore.Components.ParameterAttribute] @@ -124,7 +124,7 @@ namespace Microsoft.AspNetCore.Components [Microsoft.AspNetCore.Components.ParameterAttribute] public string Name { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } [Microsoft.AspNetCore.Components.ParameterAttribute] - public T Value { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } + public TValue 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.ParameterView parameters) { throw null; } } @@ -188,17 +188,17 @@ namespace Microsoft.AspNetCore.Components public Microsoft.AspNetCore.Components.EventCallback Create(object receiver, System.Func callback) { throw null; } public Microsoft.AspNetCore.Components.EventCallback Create(object receiver, System.Func callback) { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] - public Microsoft.AspNetCore.Components.EventCallback CreateInferred(object receiver, System.Action callback, T value) { throw null; } + public Microsoft.AspNetCore.Components.EventCallback CreateInferred(object receiver, System.Action callback, TValue value) { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] - public Microsoft.AspNetCore.Components.EventCallback CreateInferred(object receiver, System.Func callback, T value) { throw null; } + public Microsoft.AspNetCore.Components.EventCallback CreateInferred(object receiver, System.Func callback, TValue value) { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] - public Microsoft.AspNetCore.Components.EventCallback Create(object receiver, Microsoft.AspNetCore.Components.EventCallback callback) { throw null; } + public Microsoft.AspNetCore.Components.EventCallback Create(object receiver, Microsoft.AspNetCore.Components.EventCallback callback) { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] - public Microsoft.AspNetCore.Components.EventCallback Create(object receiver, Microsoft.AspNetCore.Components.EventCallback callback) { throw null; } - public Microsoft.AspNetCore.Components.EventCallback Create(object receiver, System.Action callback) { throw null; } - public Microsoft.AspNetCore.Components.EventCallback Create(object receiver, System.Action callback) { throw null; } - public Microsoft.AspNetCore.Components.EventCallback Create(object receiver, System.Func callback) { throw null; } - public Microsoft.AspNetCore.Components.EventCallback Create(object receiver, System.Func callback) { throw null; } + public Microsoft.AspNetCore.Components.EventCallback Create(object receiver, Microsoft.AspNetCore.Components.EventCallback callback) { throw null; } + public Microsoft.AspNetCore.Components.EventCallback Create(object receiver, System.Action callback) { throw null; } + public Microsoft.AspNetCore.Components.EventCallback Create(object receiver, System.Action callback) { throw null; } + public Microsoft.AspNetCore.Components.EventCallback Create(object receiver, System.Func callback) { throw null; } + public Microsoft.AspNetCore.Components.EventCallback Create(object receiver, System.Func callback) { throw null; } } public static partial class EventCallbackFactoryBinderExtensions { @@ -241,13 +241,13 @@ namespace Microsoft.AspNetCore.Components public System.Threading.Tasks.Task InvokeAsync(object arg) { throw null; } } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] - public readonly partial struct EventCallback + public readonly partial struct EventCallback { private readonly object _dummy; - public static readonly Microsoft.AspNetCore.Components.EventCallback Empty; + public static readonly Microsoft.AspNetCore.Components.EventCallback Empty; public EventCallback(Microsoft.AspNetCore.Components.IHandleEvent receiver, System.MulticastDelegate @delegate) { throw null; } public bool HasDelegate { get { throw null; } } - public System.Threading.Tasks.Task InvokeAsync(T arg) { throw null; } + public System.Threading.Tasks.Task InvokeAsync(TValue arg) { throw null; } } public partial interface IComponent { @@ -365,11 +365,11 @@ namespace Microsoft.AspNetCore.Components public static Microsoft.AspNetCore.Components.ParameterView Empty { get { throw null; } } public static Microsoft.AspNetCore.Components.ParameterView FromDictionary(System.Collections.Generic.IDictionary parameters) { throw null; } public Microsoft.AspNetCore.Components.ParameterView.Enumerator GetEnumerator() { throw null; } - public T GetValueOrDefault(string parameterName) { throw null; } - public T GetValueOrDefault(string parameterName, T defaultValue) { throw null; } + public TValue GetValueOrDefault(string parameterName) { throw null; } + public TValue GetValueOrDefault(string parameterName, TValue defaultValue) { throw null; } public void SetParameterProperties(object target) { } public System.Collections.Generic.IReadOnlyDictionary ToDictionary() { throw null; } - public bool TryGetValue(string parameterName, out T result) { throw null; } + public bool TryGetValue(string parameterName, out TValue result) { throw null; } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] public partial struct Enumerator { @@ -380,7 +380,7 @@ namespace Microsoft.AspNetCore.Components } } public delegate void RenderFragment(Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder builder); - public delegate Microsoft.AspNetCore.Components.RenderFragment RenderFragment(T value); + public delegate Microsoft.AspNetCore.Components.RenderFragment RenderFragment(TValue value); [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] public readonly partial struct RenderHandle { @@ -466,7 +466,7 @@ namespace Microsoft.AspNetCore.Components.Forms public FieldIdentifier(object model, string fieldName) { throw null; } public string FieldName { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } } public object Model { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } } - public static Microsoft.AspNetCore.Components.Forms.FieldIdentifier Create(System.Linq.Expressions.Expression> accessor) { throw null; } + public static Microsoft.AspNetCore.Components.Forms.FieldIdentifier Create(System.Linq.Expressions.Expression> accessor) { throw null; } public bool Equals(Microsoft.AspNetCore.Components.Forms.FieldIdentifier otherIdentifier) { throw null; } public override bool Equals(object obj) { throw null; } public override int GetHashCode() { throw null; } @@ -556,13 +556,13 @@ namespace Microsoft.AspNetCore.Components.Rendering public void AddAttribute(int sequence, string name, System.MulticastDelegate value) { } public void AddAttribute(int sequence, string name, object value) { } public void AddAttribute(int sequence, string name, string value) { } - public void AddAttribute(int sequence, string name, Microsoft.AspNetCore.Components.EventCallback value) { } + public void AddAttribute(int sequence, string name, Microsoft.AspNetCore.Components.EventCallback value) { } public void AddComponentReferenceCapture(int sequence, System.Action componentReferenceCaptureAction) { } public void AddContent(int sequence, Microsoft.AspNetCore.Components.MarkupString markupContent) { } public void AddContent(int sequence, Microsoft.AspNetCore.Components.RenderFragment fragment) { } public void AddContent(int sequence, object textContent) { } public void AddContent(int sequence, string textContent) { } - public void AddContent(int sequence, Microsoft.AspNetCore.Components.RenderFragment fragment, T value) { } + public void AddContent(int sequence, Microsoft.AspNetCore.Components.RenderFragment fragment, TValue value) { } public void AddElementReferenceCapture(int sequence, System.Action elementReferenceCaptureAction) { } public void AddMarkupContent(int sequence, string markupContent) { } public void AddMultipleAttributes(int sequence, System.Collections.Generic.IEnumerable> attributes) { } diff --git a/src/Components/Components/src/Auth/CascadingAuthenticationState.razor b/src/Components/Components/src/Auth/CascadingAuthenticationState.razor index 4f2e2bd630..695ebd1972 100644 --- a/src/Components/Components/src/Auth/CascadingAuthenticationState.razor +++ b/src/Components/Components/src/Auth/CascadingAuthenticationState.razor @@ -2,7 +2,7 @@ @implements IDisposable @inject AuthenticationStateProvider AuthenticationStateProvider - + @code { private Task _currentAuthenticationStateTask; diff --git a/src/Components/Components/src/CascadingValue.cs b/src/Components/Components/src/CascadingValue.cs index 1a03c2557e..564ca99def 100644 --- a/src/Components/Components/src/CascadingValue.cs +++ b/src/Components/Components/src/CascadingValue.cs @@ -5,14 +5,13 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.AspNetCore.Components.Rendering; -using Microsoft.AspNetCore.Components.RenderTree; namespace Microsoft.AspNetCore.Components { /// /// A component that provides a cascading value to all descendant components. /// - public class CascadingValue : ICascadingValueComponent, IComponent + public class CascadingValue : ICascadingValueComponent, IComponent { private RenderHandle _renderHandle; private HashSet _subscribers; // Lazily instantiated @@ -26,7 +25,7 @@ namespace Microsoft.AspNetCore.Components /// /// The value to be provided. /// - [Parameter] public T Value { get; set; } + [Parameter] public TValue Value { get; set; } /// /// Optionally gives a name to the provided value. Descendant components @@ -74,7 +73,7 @@ namespace Microsoft.AspNetCore.Components { if (parameter.Name.Equals(nameof(Value), StringComparison.OrdinalIgnoreCase)) { - Value = (T)parameter.Value; + Value = (TValue)parameter.Value; hasSuppliedValue = true; } else if (parameter.Name.Equals(nameof(ChildContent), StringComparison.OrdinalIgnoreCase)) @@ -86,7 +85,7 @@ namespace Microsoft.AspNetCore.Components Name = (string)parameter.Value; if (string.IsNullOrEmpty(Name)) { - throw new ArgumentException($"The parameter '{nameof(Name)}' for component '{nameof(CascadingValue)}' does not allow null or empty values."); + throw new ArgumentException($"The parameter '{nameof(Name)}' for component '{nameof(CascadingValue)}' does not allow null or empty values."); } } else if (parameter.Name.Equals(nameof(IsFixed), StringComparison.OrdinalIgnoreCase)) @@ -95,7 +94,7 @@ namespace Microsoft.AspNetCore.Components } else { - throw new ArgumentException($"The component '{nameof(CascadingValue)}' does not accept a parameter with the name '{parameter.Name}'."); + throw new ArgumentException($"The component '{nameof(CascadingValue)}' does not accept a parameter with the name '{parameter.Name}'."); } } @@ -136,7 +135,7 @@ namespace Microsoft.AspNetCore.Components bool ICascadingValueComponent.CanSupplyValue(Type requestedType, string requestedName) { - if (!requestedType.IsAssignableFrom(typeof(T))) + if (!requestedType.IsAssignableFrom(typeof(TValue))) { return false; } diff --git a/src/Components/Components/src/EventCallback.cs b/src/Components/Components/src/EventCallback.cs index 0d37124c64..3ba05ceaba 100644 --- a/src/Components/Components/src/EventCallback.cs +++ b/src/Components/Components/src/EventCallback.cs @@ -25,7 +25,7 @@ namespace Microsoft.AspNetCore.Components internal readonly IHandleEvent Receiver; /// - /// Creates the new . + /// Creates the new . /// /// The event receiver. /// The delegate to bind. @@ -66,73 +66,4 @@ namespace Microsoft.AspNetCore.Components return RequiresExplicitReceiver ? (object)this : Delegate; } } - - /// - /// A bound event handler delegate. - /// - public readonly struct EventCallback : IEventCallback - { - /// - /// Gets an empty . - /// - public static readonly EventCallback Empty = new EventCallback(null, (Action)(() => { })); - - internal readonly MulticastDelegate Delegate; - internal readonly IHandleEvent Receiver; - - /// - /// Creates the new . - /// - /// The event receiver. - /// The delegate to bind. - public EventCallback(IHandleEvent receiver, MulticastDelegate @delegate) - { - Receiver = receiver; - Delegate = @delegate; - } - - /// - /// Gets a value that indicates whether the delegate associated with this event dispatcher is non-null. - /// - public bool HasDelegate => Delegate != null; - - // This is a hint to the runtime that Receiver is a different object than what - // Delegate.Target points to. This allows us to avoid boxing the command object - // when building the render tree. See logic where this is used. - internal bool RequiresExplicitReceiver => Receiver != null && !object.ReferenceEquals(Receiver, Delegate?.Target); - - /// - /// Invokes the delegate associated with this binding and dispatches an event notification to the - /// appropriate component. - /// - /// The argument. - /// A which completes asynchronously once event processing has completed. - public Task InvokeAsync(T arg) - { - if (Receiver == null) - { - return EventCallbackWorkItem.InvokeAsync(Delegate, arg); - } - - return Receiver.HandleEventAsync(new EventCallbackWorkItem(Delegate), arg); - } - - internal EventCallback AsUntyped() - { - return new EventCallback(Receiver ?? Delegate?.Target as IHandleEvent, Delegate); - } - - object IEventCallback.UnpackForRenderTree() - { - return RequiresExplicitReceiver ? (object)AsUntyped() : Delegate; - } - } - - // Used to understand boxed generic EventCallbacks - internal interface IEventCallback - { - bool HasDelegate { get; } - - object UnpackForRenderTree(); - } } diff --git a/src/Components/Components/src/EventCallbackFactory.cs b/src/Components/Components/src/EventCallbackFactory.cs index a920d2277d..1b53376b85 100644 --- a/src/Components/Components/src/EventCallbackFactory.cs +++ b/src/Components/Components/src/EventCallbackFactory.cs @@ -105,14 +105,14 @@ namespace Microsoft.AspNetCore.Components /// /// [EditorBrowsable(EditorBrowsableState.Never)] - public EventCallback Create(object receiver, EventCallback callback) + public EventCallback Create(object receiver, EventCallback callback) { if (receiver == null) { throw new ArgumentNullException(nameof(receiver)); } - return new EventCallback(callback.Receiver, callback.Delegate); + return new EventCallback(callback.Receiver, callback.Delegate); } /// @@ -122,7 +122,7 @@ namespace Microsoft.AspNetCore.Components /// /// [EditorBrowsable(EditorBrowsableState.Never)] - public EventCallback Create(object receiver, EventCallback callback) + public EventCallback Create(object receiver, EventCallback callback) { if (receiver == null) { @@ -139,14 +139,14 @@ namespace Microsoft.AspNetCore.Components /// The event receiver. /// The event callback. /// The . - public EventCallback Create(object receiver, Action callback) + public EventCallback Create(object receiver, Action callback) { if (receiver == null) { throw new ArgumentNullException(nameof(receiver)); } - return CreateCore(receiver, callback); + return CreateCore(receiver, callback); } /// @@ -156,14 +156,14 @@ namespace Microsoft.AspNetCore.Components /// The event receiver. /// The event callback. /// The . - public EventCallback Create(object receiver, Action callback) + public EventCallback Create(object receiver, Action callback) { if (receiver == null) { throw new ArgumentNullException(nameof(receiver)); } - return CreateCore(receiver, callback); + return CreateCore(receiver, callback); } /// @@ -173,14 +173,14 @@ namespace Microsoft.AspNetCore.Components /// The event receiver. /// The event callback. /// The . - public EventCallback Create(object receiver, Func callback) + public EventCallback Create(object receiver, Func callback) { if (receiver == null) { throw new ArgumentNullException(nameof(receiver)); } - return CreateCore(receiver, callback); + return CreateCore(receiver, callback); } /// @@ -190,14 +190,14 @@ namespace Microsoft.AspNetCore.Components /// The event receiver. /// The event callback. /// The . - public EventCallback Create(object receiver, Func callback) + public EventCallback Create(object receiver, Func callback) { if (receiver == null) { throw new ArgumentNullException(nameof(receiver)); } - return CreateCore(receiver, callback); + return CreateCore(receiver, callback); } /// @@ -209,7 +209,7 @@ namespace Microsoft.AspNetCore.Components /// /// [EditorBrowsable(EditorBrowsableState.Never)] - public EventCallback CreateInferred(object receiver, Action callback, T value) + public EventCallback CreateInferred(object receiver, Action callback, TValue value) { return Create(receiver, callback); } @@ -223,7 +223,7 @@ namespace Microsoft.AspNetCore.Components /// /// [EditorBrowsable(EditorBrowsableState.Never)] - public EventCallback CreateInferred(object receiver, Func callback, T value) + public EventCallback CreateInferred(object receiver, Func callback, TValue value) { return Create(receiver, callback); } @@ -233,9 +233,9 @@ namespace Microsoft.AspNetCore.Components return new EventCallback(callback?.Target as IHandleEvent ?? receiver as IHandleEvent, callback); } - private EventCallback CreateCore(object receiver, MulticastDelegate callback) + private EventCallback CreateCore(object receiver, MulticastDelegate callback) { - return new EventCallback(callback?.Target as IHandleEvent ?? receiver as IHandleEvent, callback); + return new EventCallback(callback?.Target as IHandleEvent ?? receiver as IHandleEvent, callback); } } } diff --git a/src/Components/Components/src/EventCallbackOfT.cs b/src/Components/Components/src/EventCallbackOfT.cs new file mode 100644 index 0000000000..918d8d62e2 --- /dev/null +++ b/src/Components/Components/src/EventCallbackOfT.cs @@ -0,0 +1,69 @@ +// 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 System; +using System.Threading.Tasks; + +namespace Microsoft.AspNetCore.Components +{ + /// + /// A bound event handler delegate. + /// + public readonly struct EventCallback : IEventCallback + { + /// + /// Gets an empty . + /// + public static readonly EventCallback Empty = new EventCallback(null, (Action)(() => { })); + + internal readonly MulticastDelegate Delegate; + internal readonly IHandleEvent Receiver; + + /// + /// Creates the new . + /// + /// The event receiver. + /// The delegate to bind. + public EventCallback(IHandleEvent receiver, MulticastDelegate @delegate) + { + Receiver = receiver; + Delegate = @delegate; + } + + /// + /// Gets a value that indicates whether the delegate associated with this event dispatcher is non-null. + /// + public bool HasDelegate => Delegate != null; + + // This is a hint to the runtime that Receiver is a different object than what + // Delegate.Target points to. This allows us to avoid boxing the command object + // when building the render tree. See logic where this is used. + internal bool RequiresExplicitReceiver => Receiver != null && !object.ReferenceEquals(Receiver, Delegate?.Target); + + /// + /// Invokes the delegate associated with this binding and dispatches an event notification to the + /// appropriate component. + /// + /// The argument. + /// A which completes asynchronously once event processing has completed. + public Task InvokeAsync(TValue arg) + { + if (Receiver == null) + { + return EventCallbackWorkItem.InvokeAsync(Delegate, arg); + } + + return Receiver.HandleEventAsync(new EventCallbackWorkItem(Delegate), arg); + } + + internal EventCallback AsUntyped() + { + return new EventCallback(Receiver ?? Delegate?.Target as IHandleEvent, Delegate); + } + + object IEventCallback.UnpackForRenderTree() + { + return RequiresExplicitReceiver ? (object)AsUntyped() : Delegate; + } + } +} diff --git a/src/Components/Components/src/Forms/FieldIdentifier.cs b/src/Components/Components/src/Forms/FieldIdentifier.cs index fa3fb72dad..1c2c923d38 100644 --- a/src/Components/Components/src/Forms/FieldIdentifier.cs +++ b/src/Components/Components/src/Forms/FieldIdentifier.cs @@ -16,7 +16,8 @@ namespace Microsoft.AspNetCore.Components.Forms /// Initializes a new instance of the structure. /// /// An expression that identifies an object member. - public static FieldIdentifier Create(Expression> accessor) + /// The field . + public static FieldIdentifier Create(Expression> accessor) { if (accessor == null) { diff --git a/src/Components/Components/src/IEventCallback.cs b/src/Components/Components/src/IEventCallback.cs new file mode 100644 index 0000000000..6c9fcac7a3 --- /dev/null +++ b/src/Components/Components/src/IEventCallback.cs @@ -0,0 +1,13 @@ +// 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. + +namespace Microsoft.AspNetCore.Components +{ + // Used to understand boxed generic EventCallbacks + internal interface IEventCallback + { + bool HasDelegate { get; } + + object UnpackForRenderTree(); + } +} diff --git a/src/Components/Components/src/ParameterView.cs b/src/Components/Components/src/ParameterView.cs index 3d682cc09c..fb7329aab2 100644 --- a/src/Components/Components/src/ParameterView.cs +++ b/src/Components/Components/src/ParameterView.cs @@ -53,17 +53,17 @@ namespace Microsoft.AspNetCore.Components /// /// Gets the value of the parameter with the specified name. /// - /// The type of the value. + /// The type of the value. /// The name of the parameter. /// Receives the result, if any. /// True if a matching parameter was found; false otherwise. - public bool TryGetValue(string parameterName, out T result) + public bool TryGetValue(string parameterName, out TValue result) { foreach (var entry in this) { if (string.Equals(entry.Name, parameterName)) { - result = (T)entry.Value; + result = (TValue)entry.Value; return true; } } @@ -76,22 +76,22 @@ namespace Microsoft.AspNetCore.Components /// Gets the value of the parameter with the specified name, or a default value /// if no such parameter exists in the collection. /// - /// The type of the value. + /// The type of the value. /// The name of the parameter. /// The parameter value if found; otherwise the default value for the specified type. - public T GetValueOrDefault(string parameterName) - => GetValueOrDefault(parameterName, default); + public TValue GetValueOrDefault(string parameterName) + => GetValueOrDefault(parameterName, default); /// /// Gets the value of the parameter with the specified name, or a specified default value /// if no such parameter exists in the collection. /// - /// The type of the value. + /// The type of the value. /// The name of the parameter. /// The default value to return if no such parameter exists in the collection. /// The parameter value if found; otherwise . - public T GetValueOrDefault(string parameterName, T defaultValue) - => TryGetValue(parameterName, out T result) ? result : defaultValue; + public TValue GetValueOrDefault(string parameterName, TValue defaultValue) + => TryGetValue(parameterName, out TValue result) ? result : defaultValue; /// /// Returns a dictionary populated with the contents of the . diff --git a/src/Components/Components/src/RenderFragment.cs b/src/Components/Components/src/RenderFragment.cs index 06b96bfca7..cf27ad2cc4 100644 --- a/src/Components/Components/src/RenderFragment.cs +++ b/src/Components/Components/src/RenderFragment.cs @@ -13,10 +13,10 @@ namespace Microsoft.AspNetCore.Components public delegate void RenderFragment(RenderTreeBuilder builder); /// - /// Represents a segment of UI content for an object of type , implemented as + /// Represents a segment of UI content for an object of type , implemented as /// a function that returns a . /// - /// The type of object. + /// The type of object. /// The value used to build the content. - public delegate RenderFragment RenderFragment(T value); + public delegate RenderFragment RenderFragment(TValue value); } diff --git a/src/Components/Components/src/Rendering/RenderTreeBuilder.cs b/src/Components/Components/src/Rendering/RenderTreeBuilder.cs index 161a274c25..6876c97f0d 100644 --- a/src/Components/Components/src/Rendering/RenderTreeBuilder.cs +++ b/src/Components/Components/src/Rendering/RenderTreeBuilder.cs @@ -116,7 +116,7 @@ namespace Microsoft.AspNetCore.Components.Rendering /// An integer that represents the position of the instruction in the source code. /// Content to append. /// The value used by . - public void AddContent(int sequence, RenderFragment fragment, T value) + public void AddContent(int sequence, RenderFragment fragment, TValue value) { if (fragment != null) { @@ -281,7 +281,7 @@ namespace Microsoft.AspNetCore.Components.Rendering /// This method is provided for infrastructure purposes, and is used to support generated code /// that uses . /// - public void AddAttribute(int sequence, string name, EventCallback value) + public void AddAttribute(int sequence, string name, EventCallback value) { AssertCanAddAttribute(); if (_lastNonAttributeFrameType == RenderTreeFrameType.Component) diff --git a/src/Components/Web/ref/Microsoft.AspNetCore.Components.Web.netstandard2.0.cs b/src/Components/Web/ref/Microsoft.AspNetCore.Components.Web.netstandard2.0.cs index 55edccfa81..f6a30257c2 100644 --- a/src/Components/Web/ref/Microsoft.AspNetCore.Components.Web.netstandard2.0.cs +++ b/src/Components/Web/ref/Microsoft.AspNetCore.Components.Web.netstandard2.0.cs @@ -308,25 +308,25 @@ namespace Microsoft.AspNetCore.Components.Forms protected override void BuildRenderTree(Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder builder) { } protected override void OnParametersSet() { } } - public abstract partial class InputBase : Microsoft.AspNetCore.Components.ComponentBase + public abstract partial class InputBase : Microsoft.AspNetCore.Components.ComponentBase { protected InputBase() { } [Microsoft.AspNetCore.Components.ParameterAttribute(CaptureUnmatchedValues=true)] public System.Collections.Generic.IReadOnlyDictionary AdditionalAttributes { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } protected string CssClass { get { throw null; } } - protected T CurrentValue { get { throw null; } set { } } + protected TValue CurrentValue { get { throw null; } set { } } protected string CurrentValueAsString { get { throw null; } set { } } protected Microsoft.AspNetCore.Components.Forms.EditContext EditContext { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } protected Microsoft.AspNetCore.Components.Forms.FieldIdentifier FieldIdentifier { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } [Microsoft.AspNetCore.Components.ParameterAttribute] - public T Value { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } + public TValue Value { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } [Microsoft.AspNetCore.Components.ParameterAttribute] - public Microsoft.AspNetCore.Components.EventCallback ValueChanged { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } + public Microsoft.AspNetCore.Components.EventCallback ValueChanged { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } [Microsoft.AspNetCore.Components.ParameterAttribute] - public System.Linq.Expressions.Expression> ValueExpression { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } - protected virtual string FormatValueAsString(T value) { throw null; } + public System.Linq.Expressions.Expression> ValueExpression { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } + protected virtual string FormatValueAsString(TValue value) { 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); + protected abstract bool TryParseValueFromString(string value, out TValue result, out string validationErrorMessage); } public partial class InputCheckbox : Microsoft.AspNetCore.Components.Forms.InputBase { @@ -334,31 +334,31 @@ namespace Microsoft.AspNetCore.Components.Forms protected override void BuildRenderTree(Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder builder) { } protected override bool TryParseValueFromString(string value, out bool result, out string validationErrorMessage) { throw null; } } - public partial class InputDate : Microsoft.AspNetCore.Components.Forms.InputBase + public partial class InputDate : Microsoft.AspNetCore.Components.Forms.InputBase { public InputDate() { } [Microsoft.AspNetCore.Components.ParameterAttribute] public string ParsingErrorMessage { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } protected override void BuildRenderTree(Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder builder) { } - protected override string FormatValueAsString(T value) { throw null; } - protected override bool TryParseValueFromString(string value, out T result, out string validationErrorMessage) { throw null; } + protected override string FormatValueAsString(TValue value) { throw null; } + protected override bool TryParseValueFromString(string value, out TValue result, out string validationErrorMessage) { throw null; } } - public partial class InputNumber : Microsoft.AspNetCore.Components.Forms.InputBase + public partial class InputNumber : Microsoft.AspNetCore.Components.Forms.InputBase { public InputNumber() { } [Microsoft.AspNetCore.Components.ParameterAttribute] public string ParsingErrorMessage { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } protected override void BuildRenderTree(Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder builder) { } - protected override string FormatValueAsString(T value) { throw null; } - protected override bool TryParseValueFromString(string value, out T result, out string validationErrorMessage) { throw null; } + protected override string FormatValueAsString(TValue value) { throw null; } + protected override bool TryParseValueFromString(string value, out TValue result, out string validationErrorMessage) { throw null; } } - public partial class InputSelect : Microsoft.AspNetCore.Components.Forms.InputBase + public partial class InputSelect : Microsoft.AspNetCore.Components.Forms.InputBase { public InputSelect() { } [Microsoft.AspNetCore.Components.ParameterAttribute] public Microsoft.AspNetCore.Components.RenderFragment ChildContent { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } protected override void BuildRenderTree(Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder builder) { } - protected override bool TryParseValueFromString(string value, out T result, out string validationErrorMessage) { throw null; } + protected override bool TryParseValueFromString(string value, out TValue result, out string validationErrorMessage) { throw null; } } public partial class InputText : Microsoft.AspNetCore.Components.Forms.InputBase { @@ -372,13 +372,13 @@ namespace Microsoft.AspNetCore.Components.Forms protected override void BuildRenderTree(Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder builder) { } protected override bool TryParseValueFromString(string value, out string result, out string validationErrorMessage) { throw null; } } - public partial class ValidationMessage : Microsoft.AspNetCore.Components.ComponentBase, System.IDisposable + public partial class ValidationMessage : Microsoft.AspNetCore.Components.ComponentBase, System.IDisposable { public ValidationMessage() { } [Microsoft.AspNetCore.Components.ParameterAttribute(CaptureUnmatchedValues=true)] public System.Collections.Generic.IReadOnlyDictionary AdditionalAttributes { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } [Microsoft.AspNetCore.Components.ParameterAttribute] - public System.Linq.Expressions.Expression> For { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } + public System.Linq.Expressions.Expression> For { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } protected override void BuildRenderTree(Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder builder) { } protected virtual void Dispose(bool disposing) { } protected override void OnParametersSet() { } diff --git a/src/Components/Web/src/Forms/InputBase.cs b/src/Components/Web/src/Forms/InputBase.cs index 4202aec396..f60c330326 100644 --- a/src/Components/Web/src/Forms/InputBase.cs +++ b/src/Components/Web/src/Forms/InputBase.cs @@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Components.Forms /// integrates with an , which must be supplied /// as a cascading parameter. /// - public abstract class InputBase : ComponentBase + public abstract class InputBase : ComponentBase { private bool _previousParsingAttemptFailed; private ValidationMessageStore _parsingValidationMessages; @@ -32,20 +32,20 @@ namespace Microsoft.AspNetCore.Components.Forms /// /// @bind-Value="model.PropertyName" /// - [Parameter] public T Value { get; set; } + [Parameter] public TValue Value { get; set; } /// /// Gets or sets a callback that updates the bound value. /// - [Parameter] public EventCallback ValueChanged { get; set; } + [Parameter] public EventCallback ValueChanged { get; set; } /// /// Gets or sets an expression that identifies the bound value. /// - [Parameter] public Expression> ValueExpression { get; set; } + [Parameter] public Expression> ValueExpression { get; set; } /// - /// Gets the associated . + /// Gets the associated . /// protected EditContext EditContext { get; set; } @@ -57,12 +57,12 @@ namespace Microsoft.AspNetCore.Components.Forms /// /// Gets or sets the current value of the input. /// - protected T CurrentValue + protected TValue CurrentValue { get => Value; set { - var hasChanged = !EqualityComparer.Default.Equals(value, Value); + var hasChanged = !EqualityComparer.Default.Equals(value, Value); if (hasChanged) { Value = value; @@ -126,18 +126,18 @@ namespace Microsoft.AspNetCore.Components.Forms /// /// The value to format. /// A string representation of the value. - protected virtual string FormatValueAsString(T value) + protected virtual string FormatValueAsString(TValue value) => value?.ToString(); /// - /// Parses a string to create an instance of . Derived classes can override this to change how + /// Parses a string to create an instance of . Derived classes can override this to change how /// interprets incoming values. /// /// The string value to be parsed. - /// An instance of . + /// An instance of . /// If the value could not be parsed, provides a validation error message. /// True if the value could be parsed; otherwise false. - protected abstract bool TryParseValueFromString(string value, out T result, out string validationErrorMessage); + protected abstract bool TryParseValueFromString(string value, out TValue result, out string validationErrorMessage); /// /// Gets a string that indicates the status of the field being edited. This will include @@ -192,7 +192,7 @@ namespace Microsoft.AspNetCore.Components.Forms EditContext = CascadedEditContext; FieldIdentifier = FieldIdentifier.Create(ValueExpression); - _nullableUnderlyingType = Nullable.GetUnderlyingType(typeof(T)); + _nullableUnderlyingType = Nullable.GetUnderlyingType(typeof(TValue)); } else if (CascadedEditContext != EditContext) { diff --git a/src/Components/Web/src/Forms/InputDate.cs b/src/Components/Web/src/Forms/InputDate.cs index 32f6800519..7192523471 100644 --- a/src/Components/Web/src/Forms/InputDate.cs +++ b/src/Components/Web/src/Forms/InputDate.cs @@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Components.Forms /// An input component for editing date values. /// Supported types are and . /// - public class InputDate : InputBase + public class InputDate : InputBase { private const string DateFormat = "yyyy-MM-dd"; // Compatible with HTML date inputs @@ -33,7 +33,7 @@ namespace Microsoft.AspNetCore.Components.Forms } /// - protected override string FormatValueAsString(T value) + protected override string FormatValueAsString(TValue value) { switch (value) { @@ -47,11 +47,11 @@ namespace Microsoft.AspNetCore.Components.Forms } /// - protected override bool TryParseValueFromString(string value, out T result, out string validationErrorMessage) + protected override bool TryParseValueFromString(string value, out TValue result, out string validationErrorMessage) { // Unwrap nullable types. We don't have to deal with receiving empty values for nullable // types here, because the underlying InputBase already covers that. - var targetType = Nullable.GetUnderlyingType(typeof(T)) ?? typeof(T); + var targetType = Nullable.GetUnderlyingType(typeof(TValue)) ?? typeof(TValue); bool success; if (targetType == typeof(DateTime)) @@ -79,12 +79,12 @@ namespace Microsoft.AspNetCore.Components.Forms } } - static bool TryParseDateTime(string value, out T result) + static bool TryParseDateTime(string value, out TValue result) { var success = BindConverter.TryConvertToDateTime(value, CultureInfo.InvariantCulture, DateFormat, out var parsedValue); if (success) { - result = (T)(object)parsedValue; + result = (TValue)(object)parsedValue; return true; } else @@ -94,12 +94,12 @@ namespace Microsoft.AspNetCore.Components.Forms } } - static bool TryParseDateTimeOffset(string value, out T result) + static bool TryParseDateTimeOffset(string value, out TValue result) { var success = BindConverter.TryConvertToDateTimeOffset(value, CultureInfo.InvariantCulture, DateFormat, out var parsedValue); if (success) { - result = (T)(object)parsedValue; + result = (TValue)(object)parsedValue; return true; } else diff --git a/src/Components/Web/src/Forms/InputNumber.cs b/src/Components/Web/src/Forms/InputNumber.cs index 780028aa25..4f0377ceed 100644 --- a/src/Components/Web/src/Forms/InputNumber.cs +++ b/src/Components/Web/src/Forms/InputNumber.cs @@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Components.Forms /// An input component for editing numeric values. /// Supported numeric types are , , , , . /// - public class InputNumber : InputBase + public class InputNumber : InputBase { private static string _stepAttributeValue; // Null by default, so only allows whole numbers as per HTML spec @@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.Components.Forms { // Unwrap Nullable, because InputBase already deals with the Nullable aspect // of it for us. We will only get asked to parse the T for nonempty inputs. - var targetType = Nullable.GetUnderlyingType(typeof(T)) ?? typeof(T); + var targetType = Nullable.GetUnderlyingType(typeof(TValue)) ?? typeof(TValue); if (targetType == typeof(int) || targetType == typeof(float) || targetType == typeof(double) || @@ -52,9 +52,9 @@ namespace Microsoft.AspNetCore.Components.Forms } /// - protected override bool TryParseValueFromString(string value, out T result, out string validationErrorMessage) + protected override bool TryParseValueFromString(string value, out TValue result, out string validationErrorMessage) { - if (BindConverter.TryConvertTo(value, CultureInfo.InvariantCulture, out result)) + if (BindConverter.TryConvertTo(value, CultureInfo.InvariantCulture, out result)) { validationErrorMessage = null; return true; @@ -71,7 +71,7 @@ namespace Microsoft.AspNetCore.Components.Forms /// /// The value to format. /// A string representation of the value. - protected override string FormatValueAsString(T value) + protected override string FormatValueAsString(TValue value) { // Avoiding a cast to IFormattable to avoid boxing. switch (value) diff --git a/src/Components/Web/src/Forms/InputSelect.cs b/src/Components/Web/src/Forms/InputSelect.cs index 91ec034f36..b8cdbeab1f 100644 --- a/src/Components/Web/src/Forms/InputSelect.cs +++ b/src/Components/Web/src/Forms/InputSelect.cs @@ -10,7 +10,7 @@ namespace Microsoft.AspNetCore.Components.Forms /// /// A dropdown selection component. /// - public class InputSelect : InputBase + public class InputSelect : InputBase { /// /// Gets or sets the child content to be rendering inside the select element. @@ -30,17 +30,17 @@ namespace Microsoft.AspNetCore.Components.Forms } /// - protected override bool TryParseValueFromString(string value, out T result, out string validationErrorMessage) + protected override bool TryParseValueFromString(string value, out TValue result, out string validationErrorMessage) { - if (typeof(T) == typeof(string)) + if (typeof(TValue) == typeof(string)) { - result = (T)(object)value; + result = (TValue)(object)value; validationErrorMessage = null; return true; } - else if (typeof(T).IsEnum) + else if (typeof(TValue).IsEnum) { - var success = BindConverter.TryConvertTo(value, CultureInfo.CurrentCulture, out var parsedValue); + var success = BindConverter.TryConvertTo(value, CultureInfo.CurrentCulture, out var parsedValue); if (success) { result = parsedValue; @@ -55,7 +55,7 @@ namespace Microsoft.AspNetCore.Components.Forms } } - throw new InvalidOperationException($"{GetType()} does not support the type '{typeof(T)}'."); + throw new InvalidOperationException($"{GetType()} does not support the type '{typeof(TValue)}'."); } } } diff --git a/src/Components/Web/src/Forms/ValidationMessage.cs b/src/Components/Web/src/Forms/ValidationMessage.cs index 53b8057ff7..d033fdba20 100644 --- a/src/Components/Web/src/Forms/ValidationMessage.cs +++ b/src/Components/Web/src/Forms/ValidationMessage.cs @@ -11,10 +11,10 @@ namespace Microsoft.AspNetCore.Components.Forms /// /// Displays a list of validation messages for a specified field within a cascaded . /// - public class ValidationMessage : ComponentBase, IDisposable + public class ValidationMessage : ComponentBase, IDisposable { private EditContext _previousEditContext; - private Expression> _previousFieldAccessor; + private Expression> _previousFieldAccessor; private readonly EventHandler _validationStateChangedHandler; private FieldIdentifier _fieldIdentifier; @@ -28,10 +28,10 @@ namespace Microsoft.AspNetCore.Components.Forms /// /// Specifies the field for which validation messages should be displayed. /// - [Parameter] public Expression> For { get; set; } + [Parameter] public Expression> For { get; set; } /// ` - /// Constructs an instance of . + /// Constructs an instance of . /// public ValidationMessage() { diff --git a/src/Components/test/E2ETest/ServerExecutionTests/InteropReliabilityTests.cs b/src/Components/test/E2ETest/ServerExecutionTests/InteropReliabilityTests.cs index 85063046fb..ee4f4a00ed 100644 --- a/src/Components/test/E2ETest/ServerExecutionTests/InteropReliabilityTests.cs +++ b/src/Components/test/E2ETest/ServerExecutionTests/InteropReliabilityTests.cs @@ -80,7 +80,7 @@ namespace Microsoft.AspNetCore.Components.E2ETest.ServerExecutionTests await ValidateClientKeepsWorking(Client, batches); } - [Fact] + [Fact(Skip = "https://github.com/aspnet/AspNetCore/issues/12940")] public async Task CannotInvokeJSInvokableMethodsWithWrongNumberOfArguments() { // Arrange @@ -259,7 +259,7 @@ namespace Microsoft.AspNetCore.Components.E2ETest.ServerExecutionTests await ValidateClientKeepsWorking(Client, batches); } - [Fact(Skip = "https://github.com/aspnet/AspNetCore/issues/12962")] + [Fact(Skip = "https://github.com/aspnet/AspNetCore/issues/12940")] public async Task LogsJSInteropCompletionsCallbacksAndContinuesWorkingInAllSituations() { // Arrange @@ -445,7 +445,7 @@ namespace Microsoft.AspNetCore.Components.E2ETest.ServerExecutionTests await ValidateClientKeepsWorking(Client, batches); } - [Fact] + [Fact(Skip = "https://github.com/aspnet/AspNetCore/issues/12940")] public async Task DispatchingEventsWithInvalidEventHandlerId() { // Arrange