[Adapdev-commits] Adapdev/src/Adapdev CompositeValidator.cs,NONE,1.1 ICompositeValidator.cs,NONE,1.1
Status: Beta
Brought to you by:
intesar66
Update of /cvsroot/adapdev/Adapdev/src/Adapdev In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10621/src/Adapdev Modified Files: Adapdev.csproj Added Files: CompositeValidator.cs ICompositeValidator.cs IValidationRule.cs IValidator.cs ObjectComparer.cs ValidationResult.cs Log Message: MIgrated reusable Perseus components Added SmartTreeView Added new caching framework Several Sql fixes Added business rule validation classes Added FieldAccessor for IL generation --- NEW FILE: ICompositeValidator.cs --- using System; namespace Adapdev { /// <summary> /// Summary description for IRuleValidatable. /// </summary> public interface ICompositeValidator : IValidator { void AddRule(IValidationRule rule); } } --- NEW FILE: IValidationRule.cs --- using System; namespace Adapdev { /// <summary> /// Summary description for IRule. /// </summary> public interface IValidationRule { ValidationResult Validate(); } } --- NEW FILE: IValidator.cs --- using System; namespace Adapdev { /// <summary> /// Summary description for IValidator. /// </summary> public interface IValidator { ValidationResult Validate(); } } Index: Adapdev.csproj =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev/Adapdev.csproj,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Adapdev.csproj 19 May 2005 03:31:01 -0000 1.6 --- Adapdev.csproj 25 May 2005 05:17:48 -0000 1.7 *************** *** 151,154 **** --- 151,164 ---- /> <File + RelPath = "CompositeValidator.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "ICompositeValidator.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "IProgressCallback.cs" SubType = "Code" *************** *** 156,159 **** --- 166,179 ---- /> <File + RelPath = "IValidationRule.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "IValidator.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "LongLivingMarshalByRefObject.cs" SubType = "Code" *************** *** 161,164 **** --- 181,189 ---- /> <File + RelPath = "ObjectComparer.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "ObjectSorter.cs" SubType = "Code" *************** *** 176,179 **** --- 201,209 ---- /> <File + RelPath = "ValidationResult.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "Commands\ICommand.cs" SubType = "Code" *************** *** 266,269 **** --- 296,339 ---- /> <File + RelPath = "Mock\SuppliersEntity.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Reflection\ClassAccessor.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Reflection\ClassAccessorCache.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Reflection\FieldAccessor.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Reflection\FieldAccessorException.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Reflection\IValueAccessor.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Reflection\PropertyAccessor.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Reflection\PropertyAccessorException.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "Reflection\ReflectionCache.cs" SubType = "Code" --- NEW FILE: ValidationResult.cs --- using System; using System.Text; namespace Adapdev { /// <summary> /// Summary description for ValidationResult. /// </summary> public class ValidationResult { private bool _isValid = true; private StringBuilder _sb = new StringBuilder(); public string Message { get{return this._sb.ToString();} } public bool IsValid { get{return this._isValid;} set{this._isValid = value;} } public void AddMessage(string message) { if(message.Length > 0) { this._sb.Append(message); this._sb.Append(Environment.NewLine); } } } } --- NEW FILE: CompositeValidator.cs --- using System; using System.Collections; namespace Adapdev { /// <summary> /// Summary description for AbstractCompositeValidator. /// </summary> public class CompositeValidator : ICompositeValidator { private ArrayList _rules = new ArrayList(); #region ICompositeValidator Members public void AddRule(IValidationRule rule) { this._rules.Add(rule); } #endregion #region IValidator Members public virtual ValidationResult Validate() { ValidationResult vr = new ValidationResult(); ValidationResult temp = new ValidationResult(); foreach(IValidationRule rule in this._rules) { temp = rule.Validate(); if(!temp.IsValid) { vr.IsValid = false; vr.AddMessage(temp.Message); } } return vr; } #endregion } } --- NEW FILE: ObjectComparer.cs --- using System; using Adapdev.Reflection; namespace Adapdev { /// <summary> /// Summary description for ObjectComparer. /// </summary> public class ObjectComparer { private ObjectComparer() { } public static bool AreEqual(object x, object y) { Type t = x.GetType(); ClassAccessor accessor = ClassAccessorCache.Get(t); try { object p1 = null; object p2 = null; PropertyAccessor property = null; foreach(string key in accessor.GetPropertyAccessors().Keys) { property = accessor.GetPropertyAccessor(key); p1 = accessor.GetPropertyValue(x, key); p2 = accessor.GetPropertyValue(y, key); if(!p1.Equals(Convert.ChangeType(p2, property.PropertyType))) return false; } return true; } catch(ArgumentException) { return false; } } } } |