public NameRuleError(NameRuleViolations violation, string nameSpace, string className, string method, string parameter, string propOrField) { Violation = violation; NameSpace = nameSpace; ClassName = className; Method = method; Parameter = parameter; PropOrField = propOrField; }
private void CheckPropRuleAndUpdateErrorList(string propName, string accessMod) { string currentRegexString = string.Empty; NameRuleViolations violation = NameRuleViolations.Default; switch (accessMod.ToLower()) { case "private": //startswith _ and followed by camelCase (_fieldName) //currentRegexString = RegexConstants.PrivatePropertyRegex; //violation = NameRuleViolations.PrivatePropertyNameRuleViolation; var privRule = ValidationRuleProvider <PrivatePropertyValidationAttribute>(nameof(CheckPropRuleAndUpdateErrorList)) as PrivatePropertyValidationAttribute; if (privRule != null) { privRule.Validate(_currentNamespace, _currentClassName, _currentMethodName, string.Empty, propName); } break; case "public": //violation = NameRuleViolations.PublicPropertyNameRuleViolation; //currentRegexString = RegexConstants.PublicPropertyRegex; var pubRule = ValidationRuleProvider <PublicPropertyValidationAttribute>(nameof(CheckPropRuleAndUpdateErrorList)) as PublicPropertyValidationAttribute; if (pubRule != null) { pubRule.Validate(_currentNamespace, _currentClassName, _currentMethodName, string.Empty, propName); } break; case "protected": //camelCase without _ //violation = NameRuleViolations.ProtectedPropertyNameRuleViolation; //currentRegexString = RegexConstants.PublicPropertyRegex; var protRule = ValidationRuleProvider <ProtectedPropertyValidationAttribute>(nameof(CheckPropRuleAndUpdateErrorList)) as ProtectedPropertyValidationAttribute; if (protRule != null) { protRule.Validate(_currentNamespace, _currentClassName, _currentMethodName, string.Empty, propName); } break; default: break; } //var match = Regex.Match(propName, currentRegexString); //if (match.Length < propName.Length) //{ // _nameRuleErrorsList?.Add(new NameRuleError(violation, _currentNamespace, _currentClassName, string.Empty, propName)); //} }
/// <summary> /// Check Field Rule /// </summary> /// <param name="propOrFieldName"></param> /// <param name="accessMod"></param> private void CheckFieldRuleAndUpdateErrorList(string propOrFieldName, string accessMod) { string currentRegexString = string.Empty; NameRuleViolations violation = NameRuleViolations.Default; switch (accessMod.ToLower()) { case "private": //startswith _ and followed by camelCase (_fieldName) currentRegexString = RegexConstants.PrivatePropertyRegex; violation = NameRuleViolations.PrivateFieldNameRuleViolation; break; case "public": violation = NameRuleViolations.PublicFieldNameRuleViolation; currentRegexString = RegexConstants.PublicPropertyRegex; break; case "protected": //camelCase without _ violation = NameRuleViolations.ProtectedFieldNameRuleViolation; currentRegexString = RegexConstants.PublicPropertyRegex; break; default: currentRegexString = RegexConstants.PrivatePropertyRegex; violation = NameRuleViolations.PrivateFieldNameRuleViolation; break; } var match = Regex.Match(propOrFieldName, currentRegexString); if (match.Length < propOrFieldName.Length) { _nameRuleErrorsList?.Add(new NameRuleError(violation, _currentNamespace, _currentClassName, string.Empty, string.Empty, propOrFieldName)); } }
/// <summary> /// Ctor only to be used when doing Length validation /// </summary> /// <param name="maxLength"></param> public BaseValidationAttribute(int maxLength, NameRuleViolations violationType) { MaxLenth = maxLength; NameRuleViolationInstance = violationType; }
public BaseValidationAttribute() { NameRuleViolationInstance = NameRuleViolations.Default; }
public MaxLengthValidationAttribute(int maxLength, NameRuleViolations violationType) : base(maxLength, violationType) { }