Doxy, -Wall -Werror, other cleanup and organization first round
This commit is contained in:
@ -1,9 +1,9 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Reflection;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Controllers;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Reflection;
|
||||
|
||||
namespace IO.Swagger.Attributes
|
||||
{
|
||||
@ -19,14 +19,13 @@ namespace IO.Swagger.Attributes
|
||||
public override void OnActionExecuting(ActionExecutingContext context)
|
||||
{
|
||||
// Per https://blog.markvincze.com/how-to-validate-action-parameters-with-dataannotation-attributes/
|
||||
var descriptor = context.ActionDescriptor as ControllerActionDescriptor;
|
||||
if (descriptor != null)
|
||||
if (context.ActionDescriptor is ControllerActionDescriptor descriptor)
|
||||
{
|
||||
foreach (var parameter in descriptor.MethodInfo.GetParameters())
|
||||
{
|
||||
object args = null;
|
||||
if (context.ActionArguments.ContainsKey(parameter.Name))
|
||||
{
|
||||
{
|
||||
args = context.ActionArguments[parameter.Name];
|
||||
}
|
||||
|
||||
@ -40,14 +39,13 @@ namespace IO.Swagger.Attributes
|
||||
}
|
||||
}
|
||||
|
||||
private void ValidateAttributes(ParameterInfo parameter, object args, ModelStateDictionary modelState)
|
||||
private static void ValidateAttributes(ParameterInfo parameter, object args, ModelStateDictionary modelState)
|
||||
{
|
||||
foreach (var attributeData in parameter.CustomAttributes)
|
||||
{
|
||||
var attributeInstance = parameter.GetCustomAttribute(attributeData.AttributeType);
|
||||
|
||||
var validationAttribute = attributeInstance as ValidationAttribute;
|
||||
if (validationAttribute != null)
|
||||
if (attributeInstance is ValidationAttribute validationAttribute)
|
||||
{
|
||||
var isValid = validationAttribute.IsValid(args);
|
||||
if (!isValid)
|
||||
|
||||
Reference in New Issue
Block a user