/// <summary> /// Get parameter contract aspect /// </summary> /// <param name="method">Method</param> /// <param name="parameterOffset">Parameter Offset</param> /// <returns>ContractAspect</returns> public static ContractAspect GetParameterContractAspect(MethodInfo method, int parameterOffset) { var key = string.Concat(method.DeclaringType.FullName, method.Name, parameterOffset); ContractAspect contractAspect = null; if (!ContractAspects.TryGetValue(key, out contractAspect)) { contractAspect = ContractAspects[key] = method.GetParameters()[parameterOffset].GetCustomAttribute <ContractAspect>(); } return(contractAspect); }
/// <summary> /// Validate value against contract implementation /// </summary> /// <param name="value">Value</param> /// <param name="name">Name</param> /// <param name="isParameter">Flag indicating if value is from a parameter</param> /// <param name="contract">Contract</param> /// <returns>Exception</returns> public Exception Validate(object value, string name, bool isParameter, ContractAspect contract) { return(ValidateContract(value, name, isParameter, contract)); }
/// <summary> /// Validate value against contract implementation /// </summary> /// <param name="value">Value</param> /// <param name="name">Name</param> /// <param name="isParameter">Flag indicating if value is from a parameter</param> /// <param name="attr">Attribute</param> /// <returns>Exception</returns> protected abstract Exception ValidateContract(object value, string name, bool isParameter, ContractAspect attr);