/// <summary> /// Creates an enabling condition for an action method. /// If the action method takes no input parameters or parameterless = true /// then mayDependOnState should be true, /// otherwise the condition will either always hold or never hold. /// </summary> internal EnablingCondition(ActionInfo actionInfo, bool mayDependOnState, bool parameterless) { this.actionInfo = actionInfo; Type type = actionInfo.model.GetType(); Type[] paramTypes = (parameterless ? Type.EmptyTypes : actionInfo.inputParameterTypes); foreach (ModelRequirementAttribute attr in ActionInfo.GetModelRequirementAttributes(actionInfo.method)) { MethodInfo pred = type.GetMethod(attr.MethodName, paramTypes); if (pred != null && pred.ReturnType == typeof(bool) && (mayDependOnState || IsStateIndependent(pred))) { predicates.Add(pred); } } }