2
2
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3
3
4
4
using System ;
5
+ using System . Threading . Tasks ;
5
6
6
7
namespace Microsoft . AspNetCore . Components
7
8
{
@@ -17,6 +18,43 @@ public static class RuntimeHelpers
17
18
/// <typeparam name="T"></typeparam>
18
19
/// <param name="value"></param>
19
20
/// <returns></returns>
21
+ //
22
+ // This method is used to create an expression binding site with a compile-time known type. This helps with providing
23
+ // good error messages, as well as proper method-group-to-delegate conversion when assigning component parameters.
20
24
public static T TypeCheck < T > ( T value ) => value ;
25
+
26
+ /// <summary>
27
+ /// Not intended for use by application code.
28
+ /// </summary>
29
+ /// <param name="receiver"></param>
30
+ /// <param name="callback"></param>
31
+ /// <param name="value"></param>
32
+ /// <returns></returns>
33
+ //
34
+ // This method is used with `@bind-Value` for components. When a component has a generic type, it's
35
+ // really messy to write to try and write the parameter type for ValueChanged - because it can contain generic
36
+ // type parameters. We're using a trick of type inference to generate the proper typing for the delegate
37
+ // so that method-group-to-delegate conversion works.
38
+ public static EventCallback < T > CreateInferredEventCallback < T > ( object receiver , Action < T > callback , T value )
39
+ {
40
+ return EventCallback . Factory . Create < T > ( receiver , callback ) ;
41
+ }
42
+
43
+ /// <summary>
44
+ /// Not intended for use by application code.
45
+ /// </summary>
46
+ /// <param name="receiver"></param>
47
+ /// <param name="callback"></param>
48
+ /// <param name="value"></param>
49
+ /// <returns></returns>
50
+ //
51
+ // This method is used with `@bind-Value` for components. When a component has a generic type, it's
52
+ // really messy to write to try and write the parameter type for ValueChanged - because it can contain generic
53
+ // type parameters. We're using a trick of type inference to generate the proper typing for the delegate
54
+ // so that method-group-to-delegate conversion works.
55
+ public static EventCallback < T > CreateInferredEventCallback < T > ( object receiver , Func < T , Task > callback , T value )
56
+ {
57
+ return EventCallback . Factory . Create < T > ( receiver , callback ) ;
58
+ }
21
59
}
22
60
}
0 commit comments