ComparableCheck.cs

Go to the documentation of this file.
00001 using System;
00002 using System.Collections.Generic;
00003 using System.Text;
00004 
00005 namespace HouseOver.THARM.Search
00006 {
00010     [Serializable]
00011     public class ComparableCheck : Check
00012     {
00014         object minValue;
00016         object maxValue;
00017 
00021         public object MaxValue
00022         {
00023             get { return maxValue; }
00024             set {
00025                 try { maxValue = (IComparable)Convert.ChangeType(value, FieldType); }
00026                 catch { maxValue = null; }
00027             }
00028         }
00029 
00033         public object MinValue
00034         {
00035             get { return minValue; }
00036             set {
00037                 try { minValue = (IComparable)Convert.ChangeType(value, FieldType); }
00038                 catch { minValue = null; }
00039             }
00040         }
00041 
00051         public ComparableCheck(string fieldName, string humanReadableName, bool fieldRequired, Type fieldType, object minValue, object maxValue)
00052             : base(fieldName, humanReadableName, fieldRequired, fieldType)
00053         {
00054             this.minValue = minValue;
00055             this.maxValue = maxValue;
00056 
00057         }
00058 
00064         public override bool Verify(object c)
00065         {
00066             if (minValue == null || maxValue == null || !fieldRequired)
00067                 return true;
00068             IComparable ic;
00069             try
00070             {
00071                 ic = (IComparable)Convert.ChangeType(c, FieldType);
00072             }
00073             catch  {
00074                 return false;
00075             }
00076             return ic.CompareTo(minValue) >= 0 && ic.CompareTo(maxValue) <= 0;
00077         }
00078     }
00079 }

Generated on Wed Jan 10 03:42:42 2007 for THARM by  doxygen 1.5.1-p1