-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Blazor] Take cascading parameter attribute type into account when su…
…pplying cascading values (#48554)
- Loading branch information
1 parent
c53f18a
commit 883f06c
Showing
39 changed files
with
1,045 additions
and
845 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
src/Components/Components/src/Binding/CascadingModelBindingProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Microsoft.AspNetCore.Components.Rendering; | ||
|
||
namespace Microsoft.AspNetCore.Components.Binding; | ||
|
||
/// <summary> | ||
/// Provides values that get supplied to cascading parameters with <see cref="CascadingModelBinder"/>. | ||
/// </summary> | ||
public abstract class CascadingModelBindingProvider | ||
{ | ||
/// <summary> | ||
/// Gets whether values supplied by this instance will not change. | ||
/// </summary> | ||
protected internal abstract bool AreValuesFixed { get; } | ||
|
||
/// <summary> | ||
/// Determines whether this instance can provide values for parameters annotated with the specified attribute type. | ||
/// </summary> | ||
/// <param name="attributeType">The attribute type.</param> | ||
/// <returns><c>true</c> if this instance can provide values for parameters annotated with the specified attribute type, otherwise <c>false</c>.</returns> | ||
protected internal abstract bool SupportsCascadingParameterAttributeType(Type attributeType); | ||
|
||
/// <summary> | ||
/// Determines whether this instance can provide values to parameters with the specified type. | ||
/// </summary> | ||
/// <param name="parameterType">The parameter type.</param> | ||
/// <returns><c>true</c> if this instance can provide values to parameters with the specified type, otherwise <c>false</c>.</returns> | ||
protected internal abstract bool SupportsParameterType(Type parameterType); | ||
|
||
/// <summary> | ||
/// Determines whether this instance can supply a value for the specified parameter. | ||
/// </summary> | ||
/// <param name="bindingContext">The current <see cref="ModelBindingContext"/>.</param> | ||
/// <param name="parameterInfo">The <see cref="CascadingParameterInfo"/> for the component parameter.</param> | ||
/// <returns><c>true</c> if a value can be supplied, otherwise <c>false</c>.</returns> | ||
protected internal abstract bool CanSupplyValue(ModelBindingContext? bindingContext, in CascadingParameterInfo parameterInfo); | ||
|
||
/// <summary> | ||
/// Gets the value for the specified parameter. | ||
/// </summary> | ||
/// <param name="bindingContext">The current <see cref="ModelBindingContext"/>.</param> | ||
/// <param name="parameterInfo">The <see cref="CascadingParameterInfo"/> for the component parameter.</param> | ||
/// <returns>The value to supply to the parameter.</returns> | ||
protected internal abstract object? GetCurrentValue(ModelBindingContext? bindingContext, in CascadingParameterInfo parameterInfo); | ||
|
||
/// <summary> | ||
/// Subscribes to changes in supplied values, if they can change. | ||
/// </summary> | ||
/// <remarks> | ||
/// This method must be implemented if <see cref="AreValuesFixed"/> is <c>false</c>. | ||
/// </remarks> | ||
/// <param name="subscriber">The <see cref="ComponentState"/> for the subscribing component.</param> | ||
protected internal virtual void Subscribe(ComponentState subscriber) | ||
=> throw new InvalidOperationException( | ||
$"'{nameof(CascadingModelBindingProvider)}' instances that have non-fixed values must provide an implementation for '{nameof(Subscribe)}'."); | ||
|
||
/// <summary> | ||
/// Unsubscribes from changes in supplied values, if they can change. | ||
/// </summary> | ||
/// <remarks> | ||
/// This method must be implemented if <see cref="AreValuesFixed"/> is <c>false</c>. | ||
/// </remarks> | ||
/// <param name="subscriber">The <see cref="ComponentState"/> for the unsubscribing component.</param> | ||
protected internal virtual void Unsubscribe(ComponentState subscriber) | ||
=> throw new InvalidOperationException( | ||
$"'{nameof(CascadingModelBindingProvider)}' instances that have non-fixed values must provide an implementation for '{nameof(Unsubscribe)}'."); | ||
} |
Oops, something went wrong.