Doxy, -Wall -Werror, other cleanup and organization first round

This commit is contained in:
2023-08-19 20:46:31 -04:00
parent 1fedd4d016
commit 49de8aa8d7
43 changed files with 728 additions and 354 deletions

View File

@ -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)