public CacheKeyList(CacheList aMaster, string aKeyName) : base() { if (aMaster == null) { throw new Exception("Trying to create CacheKeyList with null master"); } master = aMaster; if (master.IsValidField(aKeyName) == false) { throw new Exception("Trying to assign invalid key: " + aKeyName); } keyName = aKeyName; }
public int CompareData(string aField, object aComparer, object aObject) { PropertyInfo info = CacheType.GetProperty(aField); if (aField == null) { throw new Exception("Trying to sort with non existant property"); } if ((aObject == null) || (aComparer == null)) { throw new Exception("Trying to sort with null object:\n" + " Comparer: " + aComparer + "\n" + " Object: " + aObject); } if ((aObject.GetType() != CacheType) || (aComparer.GetType() != CacheType)) { throw new Exception("Trying to sort with wrong object"); } if (info.PropertyType is IComparable) { return((info.GetValue(aComparer, null) as IComparable).CompareTo(info.GetValue(aObject, null))); } if ((info.PropertyType == typeof(int)) || (info.PropertyType == typeof(System.Int32))) { int a = (int)info.GetValue(aComparer, null); int b = (int)info.GetValue(aObject, null); return(CacheList.CompareData(a, b)); } if ((info.PropertyType is string) || (info.PropertyType == typeof(System.String))) { string a = (string)info.GetValue(aComparer, null); string b = (string)info.GetValue(aObject, null); return(CacheList.CompareData(a, b)); } if (info.PropertyType is DateTime) { DateTime a = (DateTime)info.GetValue(aComparer, null); DateTime b = (DateTime)info.GetValue(aObject, null); return(CacheList.CompareData(a, b)); } throw new Exception("Wrong type comparision: " + info.PropertyType); }
private int CompareKeyData(object aComparer, object aObject) { if ((aObject == null) || (aComparer == null)) { throw new Exception("Trying to sort with null object:\n" + " Comparer: " + aComparer + "\n" + " Object: " + aObject); } if ((aObject.GetType() != CacheType) || (aComparer.GetType() != CacheType)) { throw new Exception("Trying to sort with wrong object"); } if (keyinfo.PropertyType is IComparable) { return((keyinfo.GetValue(aComparer, null) as IComparable).CompareTo(keyinfo.GetValue(aObject, null))); } if ((keyinfo.PropertyType == typeof(int)) || (keyinfo.PropertyType == typeof(System.Int32))) { int a = (int)keyinfo.GetValue(aComparer, null); int b = (int)keyinfo.GetValue(aObject, null); return(CacheList.CompareData(a, b)); } if ((keyinfo.PropertyType is string) || (keyinfo.PropertyType == typeof(System.String))) { string a = (string)keyinfo.GetValue(aComparer, null); string b = (string)keyinfo.GetValue(aObject, null); return(CacheList.CompareData(a, b)); } if (keyinfo.PropertyType is DateTime) { DateTime a = (DateTime)keyinfo.GetValue(aComparer, null); DateTime b = (DateTime)keyinfo.GetValue(aObject, null); return(CacheList.CompareData(a, b)); } throw new Exception("Wrong type comparision: " + keyinfo.PropertyType); }
public KeyCompare(CacheList aMaster, string aKeyName) { master = new WeakReference(aMaster); keyName = aKeyName; }