From c41d40c56b0bd0295a3a142fc3b56a8ef33d8e35 Mon Sep 17 00:00:00 2001 From: Ryan Nowak Date: Mon, 8 Jul 2019 20:18:23 -0700 Subject: [PATCH] Prepare to move `CreateInferred` Part of: #11907 --- ...ft.AspNetCore.Components.netstandard2.0.cs | 2 + .../Components/src/RuntimeHelpers.cs | 38 +++++++++++++++++++ 2 files changed, 40 insertions(+) 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 fa82390216..a7593aa8a7 100644 --- a/src/Components/Components/ref/Microsoft.AspNetCore.Components.netstandard2.0.cs +++ b/src/Components/Components/ref/Microsoft.AspNetCore.Components.netstandard2.0.cs @@ -419,6 +419,8 @@ namespace Microsoft.AspNetCore.Components } public static partial class RuntimeHelpers { + public static Microsoft.AspNetCore.Components.EventCallback CreateInferredEventCallback(object receiver, System.Action callback, T value) { throw null; } + public static Microsoft.AspNetCore.Components.EventCallback CreateInferredEventCallback(object receiver, System.Func callback, T value) { throw null; } public static T TypeCheck(T value) { throw null; } } public partial class UIChangeEventArgs : Microsoft.AspNetCore.Components.UIEventArgs diff --git a/src/Components/Components/src/RuntimeHelpers.cs b/src/Components/Components/src/RuntimeHelpers.cs index 3f4fc66aa0..6e5823fec2 100644 --- a/src/Components/Components/src/RuntimeHelpers.cs +++ b/src/Components/Components/src/RuntimeHelpers.cs @@ -2,6 +2,7 @@ // 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 { @@ -17,6 +18,43 @@ namespace Microsoft.AspNetCore.Components /// /// /// + // + // This method is used to create an expression binding site with a compile-time known type. This helps with providing + // good error messages, as well as proper method-group-to-delegate conversion when assigning component parameters. public static T TypeCheck(T value) => value; + + /// + /// Not intended for use by application code. + /// + /// + /// + /// + /// + // + // This method is used with `@bind-Value` for components. When a component has a generic type, it's + // really messy to write to try and write the parameter type for ValueChanged - because it can contain generic + // type parameters. We're using a trick of type inference to generate the proper typing for the delegate + // so that method-group-to-delegate conversion works. + public static EventCallback CreateInferredEventCallback(object receiver, Action callback, T value) + { + return EventCallback.Factory.Create(receiver, callback); + } + + /// + /// Not intended for use by application code. + /// + /// + /// + /// + /// + // + // This method is used with `@bind-Value` for components. When a component has a generic type, it's + // really messy to write to try and write the parameter type for ValueChanged - because it can contain generic + // type parameters. We're using a trick of type inference to generate the proper typing for the delegate + // so that method-group-to-delegate conversion works. + public static EventCallback CreateInferredEventCallback(object receiver, Func callback, T value) + { + return EventCallback.Factory.Create(receiver, callback); + } } }