/// <summary> /// Searches for object by masters KeyProperty, since it is unique /// </summary> /// <param name="aObject"> /// A <see cref="System.Object"/> /// </param> /// <returns> /// A <see cref="System.Int32"/> /// </returns> public int FindObject(object aObject) { for (int i = 0; i < Count; i++) { object b = this[i]; int r = master.CompareData(master.KeyProperty, aObject, b); if (r == 0) { return(i); } } return(-1); }
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); }