public IList <string> GetErrorMessages(T entity, string fieldname)
        {
            List <string> list = new List <string>();

            if (UseAttributes)
            {
                var validationResults = new List <ValidationResult>();
                var isValid           = ValidateProperty(entity, fieldname, validationResults);

                if (validationResults.Count > 0)
                {
                    list.AddRange(validationResults.Select(v => v.ErrorMessage));
                }
            }

            if (_propertyRules != null && PropertyRules.ContainsKey(fieldname))
            {
                string msg = PropertyRules[fieldname].GetMessage(entity, Accessors[fieldname](entity));
                if (!string.IsNullOrEmpty(msg))
                {
                    list.Add(msg);
                }
            }

            return(list);
        }
        public bool IsValid(T entity, string fieldname)
        {
            bool isValid = true;

            if (UseAttributes)
            {
                var validationResults = new List <ValidationResult>();
                isValid = ValidateProperty(entity, fieldname, validationResults);
            }
            if (!isValid)
            {
                return(false);
            }

            if (_propertyRules != null && PropertyRules.ContainsKey(fieldname))
            {
                if (PropertyRules[fieldname].Rule(entity, Accessors[fieldname](entity)))
                {
                    return(false);
                }
            }
            return(isValid);
        }