Skip to content

Commit

Permalink
NRE for FromQuery fixed
Browse files Browse the repository at this point in the history
Faced with NRE on `Apply` when some class passes as FromQuery param in controller action. Fixed.
```csharp
//controller
[HttpGet]
public IActionResult TestAction([FromQuery]SomeClass some)
 { return Ok(); }
...
//class
public class SomeClass
{  public string Value { get; set; } }
```
  • Loading branch information
OlegShatin authored Dec 23, 2019
1 parent 5a9fd7d commit 7b1865a
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ public class XEnumNamesParameterFilter : IParameterFilter
{
public void Apply(IParameter parameter, ParameterFilterContext context)
{
var typeInfo = context.ParameterInfo.ParameterType;
var typeInfo = context.ParameterInfo?.ParameterType?? context.PropertyInfo.PropertyType;
if (typeInfo.IsEnum)
{
var names = Enum.GetNames(context.ParameterInfo.ParameterType);
var names = Enum.GetNames(typeInfo);
parameter.Extensions.Add("x-enumNames", names);
}
else if (typeInfo.IsGenericType && !parameter.Extensions.ContainsKey("x-enumNames"))
Expand Down

0 comments on commit 7b1865a

Please sign in to comment.