Last active
December 20, 2015 01:49
-
-
Save jpolvora/6051985 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RequireRouteValuesAttribute : ActionMethodSelectorAttribute { | |
public string[] ValueNames { get; private set; } | |
public RequireRouteValuesAttribute(params string[] valueNames) { | |
ValueNames = valueNames; | |
} | |
/// <summary> | |
/// Check for all strings | |
/// </summary> | |
/// <param name="controllerContext"></param> | |
/// <param name="methodInfo"></param> | |
/// <returns>Returns true only if all values are found</returns> | |
public override bool IsValidForRequest(ControllerContext controllerContext, MethodInfo methodInfo) { | |
var contains = false; | |
foreach (var value in ValueNames) { | |
contains = controllerContext.Controller.ValueProvider.GetValue(value) != null; | |
if (!contains) break; | |
} | |
return contains; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment