diff --git a/src/Components/Blazor/Build/test/RenderingRazorIntegrationTest.cs b/src/Components/Blazor/Build/test/RenderingRazorIntegrationTest.cs
index af4bffa2022c..034e2b0c7657 100644
--- a/src/Components/Blazor/Build/test/RenderingRazorIntegrationTest.cs
+++ b/src/Components/Blazor/Build/test/RenderingRazorIntegrationTest.cs
@@ -290,37 +290,6 @@ public void SupportsDataDashAttributes()
frame => AssertFrame.Attribute(frame, "data-def", "Expression value", 2));
}
- [Fact]
- public void SupportsAttributesWithEventHandlerValues()
- {
- // Arrange/Act
- var component = CompileToComponent(
- @"
- @code {
- public bool HandlerWasCalled { get; set; } = false;
-
- void MyHandleEvent(Microsoft.AspNetCore.Components.UIEventArgs eventArgs)
- {
- HandlerWasCalled = true;
- }
- }");
- var handlerWasCalledProperty = component.GetType().GetProperty("HandlerWasCalled");
-
- // Assert
- Assert.False((bool)handlerWasCalledProperty.GetValue(component));
- Assert.Collection(GetRenderTree(component),
- frame => AssertFrame.Element(frame, "elem", 2, 0),
- frame =>
- {
- Assert.Equal(RenderTreeFrameType.Attribute, frame.FrameType);
- Assert.Equal(1, frame.Sequence);
- Assert.NotNull(frame.AttributeValue);
-
- ((Action)frame.AttributeValue)(null);
- Assert.True((bool)handlerWasCalledProperty.GetValue(component));
- });
- }
-
[Fact]
public void SupportsUsingStatements()
{
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 495d7b8b6fbf..b965d0ce73a2 100644
--- a/src/Components/Components/ref/Microsoft.AspNetCore.Components.netstandard2.0.cs
+++ b/src/Components/Components/ref/Microsoft.AspNetCore.Components.netstandard2.0.cs
@@ -45,13 +45,6 @@ public BindInputElementAttribute(string type, string suffix, string valueAttribu
}
public static partial class BindMethods
{
- public static Microsoft.AspNetCore.Components.EventCallback GetEventHandlerValue(Microsoft.AspNetCore.Components.EventCallback value) where T : Microsoft.AspNetCore.Components.UIEventArgs { throw null; }
- public static Microsoft.AspNetCore.Components.EventCallback GetEventHandlerValue(Microsoft.AspNetCore.Components.EventCallback value) where T : Microsoft.AspNetCore.Components.UIEventArgs { throw null; }
- public static System.MulticastDelegate GetEventHandlerValue(System.Action value) where T : Microsoft.AspNetCore.Components.UIEventArgs { throw null; }
- public static System.MulticastDelegate GetEventHandlerValue(System.Action value) where T : Microsoft.AspNetCore.Components.UIEventArgs { throw null; }
- public static System.MulticastDelegate GetEventHandlerValue(System.Func value) where T : Microsoft.AspNetCore.Components.UIEventArgs { throw null; }
- public static System.MulticastDelegate GetEventHandlerValue(System.Func value) where T : Microsoft.AspNetCore.Components.UIEventArgs { throw null; }
- public static string GetEventHandlerValue(string value) where T : Microsoft.AspNetCore.Components.UIEventArgs { throw null; }
public static string GetValue(System.DateTime value, string format) { throw null; }
public static T GetValue(T value) { throw null; }
}
@@ -442,31 +435,6 @@ public partial class UIEventArgs
public UIEventArgs() { }
public string Type { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
}
- public static partial class UIEventArgsRenderTreeBuilderExtensions
- {
- public static void AddAttribute(this Microsoft.AspNetCore.Components.RenderTree.RenderTreeBuilder builder, int sequence, string name, System.Action value) { }
- public static void AddAttribute(this Microsoft.AspNetCore.Components.RenderTree.RenderTreeBuilder builder, int sequence, string name, System.Action value) { }
- public static void AddAttribute(this Microsoft.AspNetCore.Components.RenderTree.RenderTreeBuilder builder, int sequence, string name, System.Action value) { }
- public static void AddAttribute(this Microsoft.AspNetCore.Components.RenderTree.RenderTreeBuilder builder, int sequence, string name, System.Action value) { }
- public static void AddAttribute(this Microsoft.AspNetCore.Components.RenderTree.RenderTreeBuilder builder, int sequence, string name, System.Action value) { }
- public static void AddAttribute(this Microsoft.AspNetCore.Components.RenderTree.RenderTreeBuilder builder, int sequence, string name, System.Action value) { }
- public static void AddAttribute(this Microsoft.AspNetCore.Components.RenderTree.RenderTreeBuilder builder, int sequence, string name, System.Action value) { }
- public static void AddAttribute(this Microsoft.AspNetCore.Components.RenderTree.RenderTreeBuilder builder, int sequence, string name, System.Action value) { }
- public static void AddAttribute(this Microsoft.AspNetCore.Components.RenderTree.RenderTreeBuilder builder, int sequence, string name, System.Action value) { }
- public static void AddAttribute(this Microsoft.AspNetCore.Components.RenderTree.RenderTreeBuilder builder, int sequence, string name, System.Action value) { }
- public static void AddAttribute(this Microsoft.AspNetCore.Components.RenderTree.RenderTreeBuilder builder, int sequence, string name, System.Action value) { }
- public static void AddAttribute(this Microsoft.AspNetCore.Components.RenderTree.RenderTreeBuilder builder, int sequence, string name, System.Func value) { }
- public static void AddAttribute(this Microsoft.AspNetCore.Components.RenderTree.RenderTreeBuilder builder, int sequence, string name, System.Func value) { }
- public static void AddAttribute(this Microsoft.AspNetCore.Components.RenderTree.RenderTreeBuilder builder, int sequence, string name, System.Func value) { }
- public static void AddAttribute(this Microsoft.AspNetCore.Components.RenderTree.RenderTreeBuilder builder, int sequence, string name, System.Func value) { }
- public static void AddAttribute(this Microsoft.AspNetCore.Components.RenderTree.RenderTreeBuilder builder, int sequence, string name, System.Func value) { }
- public static void AddAttribute(this Microsoft.AspNetCore.Components.RenderTree.RenderTreeBuilder builder, int sequence, string name, System.Func value) { }
- public static void AddAttribute(this Microsoft.AspNetCore.Components.RenderTree.RenderTreeBuilder builder, int sequence, string name, System.Func value) { }
- public static void AddAttribute(this Microsoft.AspNetCore.Components.RenderTree.RenderTreeBuilder builder, int sequence, string name, System.Func value) { }
- public static void AddAttribute(this Microsoft.AspNetCore.Components.RenderTree.RenderTreeBuilder builder, int sequence, string name, System.Func value) { }
- public static void AddAttribute(this Microsoft.AspNetCore.Components.RenderTree.RenderTreeBuilder builder, int sequence, string name, System.Func value) { }
- public static void AddAttribute(this Microsoft.AspNetCore.Components.RenderTree.RenderTreeBuilder builder, int sequence, string name, System.Func value) { }
- }
public partial class UIFocusEventArgs : Microsoft.AspNetCore.Components.UIEventArgs
{
public UIFocusEventArgs() { }
@@ -566,6 +534,13 @@ protected void SetAbsoluteUri(string uri) { }
protected void TriggerOnLocationChanged(bool isinterceptedLink) { }
}
}
+namespace Microsoft.AspNetCore.Components.CompilerServices
+{
+ public static partial class RuntimeHelpers
+ {
+ public static T TypeCheck(T value) { throw null; }
+ }
+}
namespace Microsoft.AspNetCore.Components.Forms
{
public sealed partial class EditContext
@@ -728,9 +703,7 @@ public RenderTreeBuilder(Microsoft.AspNetCore.Components.Rendering.Renderer rend
public void AddAttribute(int sequence, in Microsoft.AspNetCore.Components.RenderTree.RenderTreeFrame frame) { }
public void AddAttribute(int sequence, string name, Microsoft.AspNetCore.Components.EventCallback value) { }
public void AddAttribute(int sequence, string name, System.Action value) { }
- public void AddAttribute(int sequence, string name, System.Action value) { }
public void AddAttribute(int sequence, string name, bool value) { }
- public void AddAttribute(int sequence, string name, System.Func value) { }
public void AddAttribute(int sequence, string name, System.Func value) { }
public void AddAttribute(int sequence, string name, System.MulticastDelegate value) { }
public void AddAttribute(int sequence, string name, object value) { }
diff --git a/src/Components/Components/src/BindMethods.cs b/src/Components/Components/src/BindMethods.cs
index fb5b890ffb4d..13ca0e3fa09d 100644
--- a/src/Components/Components/src/BindMethods.cs
+++ b/src/Components/Components/src/BindMethods.cs
@@ -3,7 +3,6 @@
using System;
using System.Globalization;
-using System.Threading.Tasks;
namespace Microsoft.AspNetCore.Components
{
@@ -24,67 +23,6 @@ public static string GetValue(DateTime value, string format) =>
value == default ? null
: (format == null ? value.ToString() : value.ToString(format));
- ///
- /// Not intended to be used directly.
- ///
- public static string GetEventHandlerValue(string value)
- where T : UIEventArgs
- {
- return value;
- }
-
- ///
- /// Not intended to be used directly.
- ///
- public static MulticastDelegate GetEventHandlerValue(Action value)
- where T : UIEventArgs
- {
- return value;
- }
-
- ///
- /// Not intended to be used directly.
- ///
- public static MulticastDelegate GetEventHandlerValue(Func value)
- where T : UIEventArgs
- {
- return value;
- }
-
- ///
- /// Not intended to be used directly.
- ///
- public static MulticastDelegate GetEventHandlerValue(Action value)
- where T : UIEventArgs
- {
- return value;
- }
- ///
- /// Not intended to be used directly.
- ///
- public static MulticastDelegate GetEventHandlerValue(Func value)
- where T : UIEventArgs
- {
- return value;
- }
-
- ///
- /// Not intended to be used directly.
- ///
- public static EventCallback GetEventHandlerValue(EventCallback value)
- where T : UIEventArgs
- {
- return value;
- }
-
- ///
- /// Not intended to be used directly.
- ///
- public static EventCallback GetEventHandlerValue(EventCallback value)
- where T : UIEventArgs
- {
- return value;
- }
}
}
diff --git a/src/Components/Components/src/CompilerServices/RuntimeHelpers.cs b/src/Components/Components/src/CompilerServices/RuntimeHelpers.cs
new file mode 100644
index 000000000000..87ff64cd910c
--- /dev/null
+++ b/src/Components/Components/src/CompilerServices/RuntimeHelpers.cs
@@ -0,0 +1,20 @@
+// 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.CompilerServices
+{
+ ///
+ /// Used by generated code produced by the Components code generator. Not intended or supported
+ /// for use in application code.
+ ///
+ public static class RuntimeHelpers
+ {
+ ///
+ /// Not intended for use by application code.
+ ///
+ ///
+ ///
+ ///
+ public static T TypeCheck(T value) => value;
+ }
+}
diff --git a/src/Components/Components/src/Microsoft.AspNetCore.Components.csproj b/src/Components/Components/src/Microsoft.AspNetCore.Components.csproj
index 104048d5c09d..4a6ddef33d8f 100644
--- a/src/Components/Components/src/Microsoft.AspNetCore.Components.csproj
+++ b/src/Components/Components/src/Microsoft.AspNetCore.Components.csproj
@@ -1,4 +1,4 @@
-
+
netstandard2.0
diff --git a/src/Components/Components/src/RenderTree/RenderTreeBuilder.cs b/src/Components/Components/src/RenderTree/RenderTreeBuilder.cs
index e5773a41b2cb..3b48edd123aa 100644
--- a/src/Components/Components/src/RenderTree/RenderTreeBuilder.cs
+++ b/src/Components/Components/src/RenderTree/RenderTreeBuilder.cs
@@ -224,23 +224,6 @@ public void AddAttribute(int sequence, string name, Action value)
AddAttribute(sequence, name, (MulticastDelegate)value);
}
- ///
- ///
- /// Appends a frame representing an -valued attribute.
- ///
- ///
- /// The attribute is associated with the most recently added element. If the value is null and the
- /// current element is not a component, the frame will be omitted.
- ///
- ///
- /// An integer that represents the position of the instruction in the source code.
- /// The name of the attribute.
- /// The value of the attribute.
- public void AddAttribute(int sequence, string name, Action value)
- {
- AddAttribute(sequence, name, (MulticastDelegate)value);
- }
-
///
///
/// Appends a frame representing a -valued attribute.
@@ -258,23 +241,6 @@ public void AddAttribute(int sequence, string name, Func value)
AddAttribute(sequence, name, (MulticastDelegate)value);
}
- ///
- ///
- /// Appends a frame representing a -valued attribute.
- ///
- ///
- /// The attribute is associated with the most recently added element. If the value is null and the
- /// current element is not a component, the frame will be omitted.
- ///
- ///
- /// An integer that represents the position of the instruction in the source code.
- /// The name of the attribute.
- /// The value of the attribute.
- public void AddAttribute(int sequence, string name, Func value)
- {
- AddAttribute(sequence, name, (MulticastDelegate)value);
- }
-
///
///
/// Appends a frame representing a delegate-valued attribute.
@@ -287,14 +253,6 @@ public void AddAttribute(int sequence, string name, Func valu
/// An integer that represents the position of the instruction in the source code.
/// The name of the attribute.
/// The value of the attribute.
- ///
- /// This method is provided for infrastructure purposes, and is used to be
- /// to provide support for delegates of specific
- /// types. For a good programming experience when using a custom delegate type, define an
- /// extension method similar to
- ///
- /// that calls this method.
- ///
public void AddAttribute(int sequence, string name, MulticastDelegate value)
{
AssertCanAddAttribute();
diff --git a/src/Components/Components/src/RuntimeHelpers.cs b/src/Components/Components/src/RuntimeHelpers.cs
index b639ffd5307a..3f4fc66aa07a 100644
--- a/src/Components/Components/src/RuntimeHelpers.cs
+++ b/src/Components/Components/src/RuntimeHelpers.cs
@@ -1,10 +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 System;
-using System.Threading.Tasks;
-using Microsoft.AspNetCore.Components.Forms;
namespace Microsoft.AspNetCore.Components
{
diff --git a/src/Components/Components/src/UIEventArgsRenderTreeBuilderExtensions.cs b/src/Components/Components/src/UIEventArgsRenderTreeBuilderExtensions.cs
deleted file mode 100644
index 0efb06799712..000000000000
--- a/src/Components/Components/src/UIEventArgsRenderTreeBuilderExtensions.cs
+++ /dev/null
@@ -1,547 +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 System;
-using System.Threading.Tasks;
-using Microsoft.AspNetCore.Components.RenderTree;
-
-namespace Microsoft.AspNetCore.Components
-{
- ///
- /// Extensions methods on for event handlers.
- ///
- ///
- ///
- /// These methods enable method-group to delegate conversion for delegates and methods that accept
- /// types derived from .
- ///
- ///
- /// This enhances the programming experience for using event handlers with the render tree builder
- /// in components written in pure C#. These extension methods make it possible to write code like:
- ///
- /// builder.AddAttribute(0, "onkeypress", MyKeyPressHandler);
- ///
- /// Where void MyKeyPressHandler(UIKeyboardEventArgs e) is a method defined in the same class.
- /// In this example, the author knows that the onclick event is associated with the
- /// event args type. The component author is responsible for
- /// providing a delegate that matches the expected event args type, an error will result in a failure
- /// at runtime.
- ///
- ///
- /// When a component is authored in Razor (.cshtml), the Razor code generator will maintain a mapping
- /// between event names and event arg types that can be used to generate more strongly typed code.
- /// Generated code for the same case will look like:
- ///
- /// builder.AddAttribute(0, "onkeypress", BindMethods.GetEventHandlerValue<UIKeyboardEventArgs>(MyKeyPressHandler));
- ///
- ///
- ///
- public static class UIEventArgsRenderTreeBuilderExtensions
- {
- ///
- ///
- /// Appends a frame representing an -valued attribute.
- ///
- ///
- /// The attribute is associated with the most recently added element. If the value is null and the
- /// current element is not a component, the frame will be omitted.
- ///
- ///
- /// The .
- /// An integer that represents the position of the instruction in the source code.
- /// The name of the attribute.
- /// The value of the attribute.
- public static void AddAttribute(this RenderTreeBuilder builder, int sequence, string name, Action value)
- {
- if (builder == null)
- {
- throw new ArgumentNullException(nameof(builder));
- }
-
- builder.AddAttribute(sequence, name, (MulticastDelegate)value);
- }
-
- ///
- ///
- /// Appends a frame representing an -valued attribute.
- ///
- ///
- /// The attribute is associated with the most recently added element. If the value is null and the
- /// current element is not a component, the frame will be omitted.
- ///
- ///
- /// The .
- /// An integer that represents the position of the instruction in the source code.
- /// The name of the attribute.
- /// The value of the attribute.
- public static void AddAttribute(this RenderTreeBuilder builder, int sequence, string name, Func value)
- {
- if (builder == null)
- {
- throw new ArgumentNullException(nameof(builder));
- }
-
- builder.AddAttribute(sequence, name, (MulticastDelegate)value);
- }
-
- ///
- ///
- /// Appends a frame representing an -valued attribute.
- ///
- ///
- /// The attribute is associated with the most recently added element. If the value is null and the
- /// current element is not a component, the frame will be omitted.
- ///
- ///
- /// The .
- /// An integer that represents the position of the instruction in the source code.
- /// The name of the attribute.
- /// The value of the attribute.
- public static void AddAttribute(this RenderTreeBuilder builder, int sequence, string name, Action value)
- {
- if (builder == null)
- {
- throw new ArgumentNullException(nameof(builder));
- }
-
- builder.AddAttribute(sequence, name, (MulticastDelegate)value);
- }
-
- ///
- ///
- /// Appends a frame representing an -valued attribute.
- ///
- ///
- /// The attribute is associated with the most recently added element. If the value is null and the
- /// current element is not a component, the frame will be omitted.
- ///
- ///
- /// The .
- /// An integer that represents the position of the instruction in the source code.
- /// The name of the attribute.
- /// The value of the attribute.
- public static void AddAttribute(this RenderTreeBuilder builder, int sequence, string name, Func value)
- {
- if (builder == null)
- {
- throw new ArgumentNullException(nameof(builder));
- }
-
- builder.AddAttribute(sequence, name, (MulticastDelegate)value);
- }
-
- ///
- ///
- /// Appends a frame representing an -valued attribute.
- ///
- ///
- /// The attribute is associated with the most recently added element. If the value is null and the
- /// current element is not a component, the frame will be omitted.
- ///
- ///
- /// The .
- /// An integer that represents the position of the instruction in the source code.
- /// The name of the attribute.
- /// The value of the attribute.
- public static void AddAttribute(this RenderTreeBuilder builder, int sequence, string name, Action value)
- {
- if (builder == null)
- {
- throw new ArgumentNullException(nameof(builder));
- }
-
- builder.AddAttribute(sequence, name, (MulticastDelegate)value);
- }
-
- ///
- ///
- /// Appends a frame representing an -valued attribute.
- ///
- ///
- /// The attribute is associated with the most recently added element. If the value is null and the
- /// current element is not a component, the frame will be omitted.
- ///
- ///
- /// The .
- /// An integer that represents the position of the instruction in the source code.
- /// The name of the attribute.
- /// The value of the attribute.
- public static void AddAttribute(this RenderTreeBuilder builder, int sequence, string name, Func value)
- {
- if (builder == null)
- {
- throw new ArgumentNullException(nameof(builder));
- }
-
- builder.AddAttribute(sequence, name, (MulticastDelegate)value);
- }
-
- ///
- ///
- /// Appends a frame representing an -valued attribute.
- ///
- ///
- /// The attribute is associated with the most recently added element. If the value is null and the
- /// current element is not a component, the frame will be omitted.
- ///
- ///
- /// The .
- /// An integer that represents the position of the instruction in the source code.
- /// The name of the attribute.
- /// The value of the attribute.
- public static void AddAttribute(this RenderTreeBuilder builder, int sequence, string name, Action value)
- {
- if (builder == null)
- {
- throw new ArgumentNullException(nameof(builder));
- }
-
- builder.AddAttribute(sequence, name, (MulticastDelegate)value);
- }
-
- ///
- ///
- /// Appends a frame representing an -valued attribute.
- ///
- ///
- /// The attribute is associated with the most recently added element. If the value is null and the
- /// current element is not a component, the frame will be omitted.
- ///
- ///
- /// The .
- /// An integer that represents the position of the instruction in the source code.
- /// The name of the attribute.
- /// The value of the attribute.
- public static void AddAttribute(this RenderTreeBuilder builder, int sequence, string name, Func value)
- {
- if (builder == null)
- {
- throw new ArgumentNullException(nameof(builder));
- }
-
- builder.AddAttribute(sequence, name, (MulticastDelegate)value);
- }
-
- ///
- ///
- /// Appends a frame representing an -valued attribute.
- ///
- ///
- /// The attribute is associated with the most recently added element. If the value is null and the
- /// current element is not a component, the frame will be omitted.
- ///
- ///
- /// The .
- /// An integer that represents the position of the instruction in the source code.
- /// The name of the attribute.
- /// The value of the attribute.
- public static void AddAttribute(this RenderTreeBuilder builder, int sequence, string name, Action value)
- {
- if (builder == null)
- {
- throw new ArgumentNullException(nameof(builder));
- }
-
- builder.AddAttribute(sequence, name, (MulticastDelegate)value);
- }
-
- ///
- ///
- /// Appends a frame representing an -valued attribute.
- ///
- ///
- /// The attribute is associated with the most recently added element. If the value is null and the
- /// current element is not a component, the frame will be omitted.
- ///
- ///
- /// The .
- /// An integer that represents the position of the instruction in the source code.
- /// The name of the attribute.
- /// The value of the attribute.
- public static void AddAttribute(this RenderTreeBuilder builder, int sequence, string name, Func value)
- {
- if (builder == null)
- {
- throw new ArgumentNullException(nameof(builder));
- }
-
- builder.AddAttribute(sequence, name, (MulticastDelegate)value);
- }
-
- ///
- ///
- /// Appends a frame representing an -valued attribute.
- ///
- ///
- /// The attribute is associated with the most recently added element. If the value is null and the
- /// current element is not a component, the frame will be omitted.
- ///
- ///
- /// The .
- /// An integer that represents the position of the instruction in the source code.
- /// The name of the attribute.
- /// The value of the attribute.
- public static void AddAttribute(this RenderTreeBuilder builder, int sequence, string name, Action value)
- {
- if (builder == null)
- {
- throw new ArgumentNullException(nameof(builder));
- }
-
- builder.AddAttribute(sequence, name, (MulticastDelegate)value);
- }
-
- ///
- ///
- /// Appends a frame representing an -valued attribute.
- ///
- ///
- /// The attribute is associated with the most recently added element. If the value is null and the
- /// current element is not a component, the frame will be omitted.
- ///
- ///
- /// The .
- /// An integer that represents the position of the instruction in the source code.
- /// The name of the attribute.
- /// The value of the attribute.
- public static void AddAttribute(this RenderTreeBuilder builder, int sequence, string name, Func value)
- {
- if (builder == null)
- {
- throw new ArgumentNullException(nameof(builder));
- }
-
- builder.AddAttribute(sequence, name, (MulticastDelegate)value);
- }
-
- ///
- ///
- /// Appends a frame representing an -valued attribute.
- ///
- ///
- /// The attribute is associated with the most recently added element. If the value is null and the
- /// current element is not a component, the frame will be omitted.
- ///
- ///
- /// The .
- /// An integer that represents the position of the instruction in the source code.
- /// The name of the attribute.
- /// The value of the attribute.
- public static void AddAttribute(this RenderTreeBuilder builder, int sequence, string name, Action value)
- {
- if (builder == null)
- {
- throw new ArgumentNullException(nameof(builder));
- }
-
- builder.AddAttribute(sequence, name, (MulticastDelegate)value);
- }
-
- ///
- ///
- /// Appends a frame representing an -valued attribute.
- ///
- ///
- /// The attribute is associated with the most recently added element. If the value is null and the
- /// current element is not a component, the frame will be omitted.
- ///
- ///
- /// The .
- /// An integer that represents the position of the instruction in the source code.
- /// The name of the attribute.
- /// The value of the attribute.
- public static void AddAttribute(this RenderTreeBuilder builder, int sequence, string name, Func value)
- {
- if (builder == null)
- {
- throw new ArgumentNullException(nameof(builder));
- }
-
- builder.AddAttribute(sequence, name, (MulticastDelegate)value);
- }
-
- ///
- ///
- /// Appends a frame representing an -valued attribute.
- ///
- ///
- /// The attribute is associated with the most recently added element. If the value is null and the
- /// current element is not a component, the frame will be omitted.
- ///
- ///
- /// The .
- /// An integer that represents the position of the instruction in the source code.
- /// The name of the attribute.
- /// The value of the attribute.
- public static void AddAttribute(this RenderTreeBuilder builder, int sequence, string name, Action value)
- {
- if (builder == null)
- {
- throw new ArgumentNullException(nameof(builder));
- }
-
- builder.AddAttribute(sequence, name, (MulticastDelegate)value);
- }
-
- ///
- ///
- /// Appends a frame representing an -valued attribute.
- ///
- ///
- /// The attribute is associated with the most recently added element. If the value is null and the
- /// current element is not a component, the frame will be omitted.
- ///
- ///
- /// The .
- /// An integer that represents the position of the instruction in the source code.
- /// The name of the attribute.
- /// The value of the attribute.
- public static void AddAttribute(this RenderTreeBuilder builder, int sequence, string name, Func value)
- {
- if (builder == null)
- {
- throw new ArgumentNullException(nameof(builder));
- }
-
- builder.AddAttribute(sequence, name, (MulticastDelegate)value);
- }
-
- ///
- ///
- /// Appends a frame representing an -valued attribute.
- ///
- ///
- /// The attribute is associated with the most recently added element. If the value is null and the
- /// current element is not a component, the frame will be omitted.
- ///
- ///
- /// The .
- /// An integer that represents the position of the instruction in the source code.
- /// The name of the attribute.
- /// The value of the attribute.
- public static void AddAttribute(this RenderTreeBuilder builder, int sequence, string name, Action value)
- {
- if (builder == null)
- {
- throw new ArgumentNullException(nameof(builder));
- }
-
- builder.AddAttribute(sequence, name, (MulticastDelegate)value);
- }
-
- ///
- ///
- /// Appends a frame representing an -valued attribute.
- ///
- ///
- /// The attribute is associated with the most recently added element. If the value is null and the
- /// current element is not a component, the frame will be omitted.
- ///
- ///
- /// The .
- /// An integer that represents the position of the instruction in the source code.
- /// The name of the attribute.
- /// The value of the attribute.
- public static void AddAttribute(this RenderTreeBuilder builder, int sequence, string name, Func value)
- {
- if (builder == null)
- {
- throw new ArgumentNullException(nameof(builder));
- }
-
- builder.AddAttribute(sequence, name, (MulticastDelegate)value);
- }
-
- ///
- ///
- /// Appends a frame representing an -valued attribute.
- ///
- ///
- /// The attribute is associated with the most recently added element. If the value is null and the
- /// current element is not a component, the frame will be omitted.
- ///
- ///
- /// The .
- /// An integer that represents the position of the instruction in the source code.
- /// The name of the attribute.
- /// The value of the attribute.
- public static void AddAttribute(this RenderTreeBuilder builder, int sequence, string name, Action value)
- {
- if (builder == null)
- {
- throw new ArgumentNullException(nameof(builder));
- }
-
- builder.AddAttribute(sequence, name, (MulticastDelegate)value);
- }
-
- ///
- ///
- /// Appends a frame representing an -valued attribute.
- ///
- ///
- /// The attribute is associated with the most recently added element. If the value is null and the
- /// current element is not a component, the frame will be omitted.
- ///
- ///
- /// The .
- /// An integer that represents the position of the instruction in the source code.
- /// The name of the attribute.
- /// The value of the attribute.
- public static void AddAttribute(this RenderTreeBuilder builder, int sequence, string name, Func value)
- {
- if (builder == null)
- {
- throw new ArgumentNullException(nameof(builder));
- }
-
- builder.AddAttribute(sequence, name, (MulticastDelegate)value);
- }
-
- ///
- ///
- /// Appends a frame representing an -valued attribute.
- ///
- ///
- /// The attribute is associated with the most recently added element. If the value is null and the
- /// current element is not a component, the frame will be omitted.
- ///
- ///
- /// The .
- /// An integer that represents the position of the instruction in the source code.
- /// The name of the attribute.
- /// The value of the attribute.
- public static void AddAttribute(this RenderTreeBuilder builder, int sequence, string name, Action value)
- {
- if (builder == null)
- {
- throw new ArgumentNullException(nameof(builder));
- }
-
- builder.AddAttribute(sequence, name, (MulticastDelegate)value);
- }
-
- ///
- ///
- /// Appends a frame representing an -valued attribute.
- ///
- ///
- /// The attribute is associated with the most recently added element. If the value is null and the
- /// current element is not a component, the frame will be omitted.
- ///
- ///
- /// The .
- /// An integer that represents the position of the instruction in the source code.
- /// The name of the attribute.
- /// The value of the attribute.
- public static void AddAttribute(this RenderTreeBuilder builder, int sequence, string name, Func value)
- {
- if (builder == null)
- {
- throw new ArgumentNullException(nameof(builder));
- }
-
- builder.AddAttribute(sequence, name, (MulticastDelegate)value);
- }
- }
-}
diff --git a/src/Components/Components/test/RenderTreeBuilderTest.cs b/src/Components/Components/test/RenderTreeBuilderTest.cs
index bfd73e040dd1..c4efa96171cb 100644
--- a/src/Components/Components/test/RenderTreeBuilderTest.cs
+++ b/src/Components/Components/test/RenderTreeBuilderTest.cs
@@ -398,7 +398,7 @@ public void CannotAddAttributeAtRoot()
}
[Fact]
- public void CannotAddEventHandlerAttributeAtRoot()
+ public void CannotDelegateAttributeAtRoot()
{
// Arrange
var builder = new RenderTreeBuilder(new TestRenderer());
@@ -406,7 +406,7 @@ public void CannotAddEventHandlerAttributeAtRoot()
// Act/Assert
Assert.Throws(() =>
{
- builder.AddAttribute(0, "name", eventInfo => { });
+ builder.AddAttribute(0, "name", new Action(eventInfo => { }));
});
}
@@ -436,7 +436,7 @@ public void CannotAddEventHandlerAttributeToText()
{
builder.OpenElement(0, "some element");
builder.AddContent(1, "hello");
- builder.AddAttribute(2, "name", eventInfo => { });
+ builder.AddAttribute(2, "name", new Action(eventInfo => { }));
});
}
diff --git a/src/Components/Components/test/RendererTest.cs b/src/Components/Components/test/RendererTest.cs
index 054d5511bfb5..caf00fed9fb1 100644
--- a/src/Components/Components/test/RendererTest.cs
+++ b/src/Components/Components/test/RendererTest.cs
@@ -2197,12 +2197,12 @@ public async Task AllRendersTriggeredSynchronouslyDuringEventHandlerAreHandledAs
{
builder.AddContent(0, "Child event count: " + eventCount);
builder.OpenComponent(1);
- builder.AddAttribute(2, nameof(EventComponent.OnTest), args =>
+ builder.AddAttribute(2, nameof(EventComponent.OnTest), new Action(args =>
{
eventCount++;
rootComponent.TriggerRender();
childComponent.TriggerRender();
- });
+ }));
builder.CloseComponent();
});
var rootComponentId = renderer.AssignRootComponentId(rootComponent);
@@ -3637,7 +3637,7 @@ private void Render()
=> _renderHandle.Render(builder =>
{
builder.OpenElement(0, "my button");
- builder.AddAttribute(1, "my click handler", eventArgs => OnClick(eventArgs));
+ builder.AddAttribute(1, "my click handler", new Action(eventArgs => OnClick(eventArgs)));
builder.CloseElement();
});
}
@@ -4068,12 +4068,12 @@ protected override void BuildRenderTree(RenderTreeBuilder builder)
builder.OpenElement(0, "element with event");
builder.AddAttribute(1, nameof(BoundString), BoundString);
- builder.AddAttribute(2, "ontestevent", (UIChangeEventArgs eventArgs) =>
+ builder.AddAttribute(2, "ontestevent", new Action((UIChangeEventArgs eventArgs) =>
{
BoundString = (string)eventArgs.Value;
TriggerRender();
GC.KeepAlive(unrelatedThingToMakeTheLambdaCapture);
- });
+ }));
builder.SetUpdatesAttributeName(nameof(BoundString));
builder.CloseElement();
}