Skip to content

Instantly share code, notes, and snippets.

@BenjaminAdams
Created October 13, 2016 18:20
Show Gist options
  • Select an option

  • Save BenjaminAdams/b05f75068f7df9b3cf7cef8909d20c50 to your computer and use it in GitHub Desktop.

Select an option

Save BenjaminAdams/b05f75068f7df9b3cf7cef8909d20c50 to your computer and use it in GitHub Desktop.

Revisions

  1. BenjaminAdams created this gist Oct 13, 2016.
    25 changes: 25 additions & 0 deletions CheckModelForNullAttribute.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    using System;
    using System.Web.Http.Controllers;
    using System.Web.Http.Filters;

    namespace Payments.Productization.Process.FilterAttributes
    {
    [AttributeUsage(AttributeTargets.Class)]
    public class CheckModelForNullAttribute : ActionFilterAttribute
    {
    public override void OnActionExecuting(HttpActionContext context)
    {
    if (context == null) throw new ArgumentNullException("Input Payload was malformed, invalid, or empty");

    foreach (var arg in context.ActionArguments)
    {
    if (arg.Value == null)
    {
    throw new ArgumentException("Input Payload was malformed, invalid, or empty", arg.Key);
    }
    }

    base.OnActionExecuting(context);
    }
    }
    }