parent
79e576b86c
commit
f629f9a659
|
|
@ -135,12 +135,15 @@ namespace Microsoft.AspNetCore.Mvc.ViewComponents
|
|||
// Internal for testing
|
||||
internal IDictionary<string, object> GetArgumentDictionary(ViewComponentDescriptor descriptor, object arguments)
|
||||
{
|
||||
if (descriptor.Parameters.Count == 1 && descriptor.Parameters[0].ParameterType.IsAssignableFrom(arguments.GetType()))
|
||||
if (arguments != null)
|
||||
{
|
||||
return new Dictionary<string, object>(capacity: 1, comparer: StringComparer.OrdinalIgnoreCase)
|
||||
if (descriptor.Parameters.Count == 1 && descriptor.Parameters[0].ParameterType.IsAssignableFrom(arguments.GetType()))
|
||||
{
|
||||
{ descriptor.Parameters[0].Name, arguments }
|
||||
};
|
||||
return new Dictionary<string, object>(capacity: 1, comparer: StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
{ descriptor.Parameters[0].Name, arguments }
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return PropertyHelper.ObjectToDictionary(arguments);
|
||||
|
|
|
|||
|
|
@ -15,6 +15,21 @@ namespace Microsoft.AspNetCore.Mvc.ViewComponents
|
|||
{
|
||||
public class DefaultViewComponentHelperTest
|
||||
{
|
||||
[Fact]
|
||||
public void GetArgumentDictionary_SupportsNullArguments()
|
||||
{
|
||||
// Arrange
|
||||
var helper = CreateHelper();
|
||||
var descriptor = CreateDescriptorForType(typeof(ViewComponentSingleParam));
|
||||
|
||||
// Act
|
||||
var argumentDictionary = helper.GetArgumentDictionary(descriptor, null);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(0, argumentDictionary.Count);
|
||||
Assert.IsType(typeof(Dictionary<string,object>),argumentDictionary);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetArgumentDictionary_SupportsAnonymouslyTypedArguments()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue