1
1
// Licensed to the .NET Foundation under one or more agreements.
2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
4
+ using System . Collections . ObjectModel ;
4
5
using System . Diagnostics . CodeAnalysis ;
5
6
using Microsoft . AspNetCore . Components ;
6
7
using Microsoft . AspNetCore . Components . Endpoints ;
@@ -22,7 +23,7 @@ public class RazorComponentResult : IResult
22
23
/// </summary>
23
24
/// <param name="componentType">The type of the component to render. This must implement <see cref="IComponent"/>.</param>
24
25
public RazorComponentResult ( [ DynamicallyAccessedMembers ( Component ) ] Type componentType )
25
- : this ( componentType , null )
26
+ : this ( componentType , ReadOnlyDictionary < string , object ? > . Empty )
26
27
{
27
28
}
28
29
@@ -31,8 +32,10 @@ public RazorComponentResult([DynamicallyAccessedMembers(Component)] Type compone
31
32
/// </summary>
32
33
/// <param name="componentType">The type of the component to render. This must implement <see cref="IComponent"/>.</param>
33
34
/// <param name="parameters">Parameters for the component.</param>
34
- public RazorComponentResult ( [ DynamicallyAccessedMembers ( Component ) ] Type componentType , object ? parameters )
35
- : this ( componentType , CoerceParametersObjectToDictionary ( parameters ) )
35
+ public RazorComponentResult (
36
+ [ DynamicallyAccessedMembers ( Component ) ] Type componentType ,
37
+ [ DynamicallyAccessedMembers ( DynamicallyAccessedMemberTypes . All ) ] object parameters )
38
+ : this ( componentType , CoerceParametersObjectToDictionary ( parameters ) ! )
36
39
{
37
40
}
38
41
@@ -41,19 +44,20 @@ public RazorComponentResult([DynamicallyAccessedMembers(Component)] Type compone
41
44
/// </summary>
42
45
/// <param name="componentType">The type of the component to render. This must implement <see cref="IComponent"/>.</param>
43
46
/// <param name="parameters">Parameters for the component.</param>
44
- public RazorComponentResult ( [ DynamicallyAccessedMembers ( Component ) ] Type componentType , IReadOnlyDictionary < string , object ? > ? parameters )
47
+ public RazorComponentResult ( [ DynamicallyAccessedMembers ( Component ) ] Type componentType , IReadOnlyDictionary < string , object ? > parameters )
45
48
{
49
+ ArgumentNullException . ThrowIfNull ( componentType ) ;
50
+ ArgumentNullException . ThrowIfNull ( parameters ) ;
51
+
46
52
// Note that the Blazor renderer will validate that componentType implements IComponent and throws a suitable
47
53
// exception if not, so we don't need to duplicate that logic here.
48
-
49
- ArgumentNullException . ThrowIfNull ( componentType ) ;
50
54
ComponentType = componentType ;
51
55
Parameters = parameters ?? EmptyParameters ;
52
56
}
53
57
54
58
private static IReadOnlyDictionary < string , object ? > ? CoerceParametersObjectToDictionary ( object ? parameters )
55
59
=> parameters is null
56
- ? null
60
+ ? throw new ArgumentNullException ( nameof ( parameters ) )
57
61
: ( IReadOnlyDictionary < string , object ? > ) PropertyHelper . ObjectToDictionary ( parameters ) ;
58
62
59
63
/// <summary>
0 commit comments