/// <summary> /// Finds all the loaded business objects that match the type T and the Criteria given. /// </summary> /// <param name="criteria">The Criteria to match on</param> /// <param name="boType">The business object type being searched for</param> /// <returns>A collection of all loaded matching business objects</returns> public IList Find(Criteria criteria, Type boType) { lock (_lock) { IList collection = new ArrayList(); var valueArray = new WeakReference[_loadedBusinessObjects.Count]; _loadedBusinessObjects.Values.CopyTo(valueArray, 0); foreach (var bo in valueArray.Select(GetBusinessObject).Where(bo => bo != null)) { try { if (boType.IsInstanceOfType(bo) && (criteria == null || criteria.IsMatch(bo, false))) { collection.Add(bo); } } //For Dynamic Business Objects the Props may have been added since the business object was loaded. catch (InvalidPropertyNameException) { //Do Nothing } } return(collection); } }
/// <summary> /// Finds all the loaded business objects that match the type T and the Criteria given. /// </summary> /// <typeparam name="T">The Type of business object to find</typeparam> /// <param name="criteria">The Criteria to match on</param> /// <returns>A collection of all loaded matching business objects</returns> public IList <T> Find <T>(Criteria criteria) where T : class, IBusinessObject, new() { lock (_lock) { var collection = new List <T>(); var valueArray = new WeakReference[_loadedBusinessObjects.Count]; _loadedBusinessObjects.Values.CopyTo(valueArray, 0); foreach (var bo in valueArray.Select(GetBusinessObject).Where(bo => bo != null)) { try { if (bo is T && (criteria == null || criteria.IsMatch(bo, false))) { collection.Add(bo as T); } } //For Dynamic Business Objects the Props may have been added since the business object was loaded. catch (InvalidPropertyNameException) { //Do Nothing } } return(collection); } }
/// <summary> /// Finds the First Business Object that matches the classDef classDef and the Criteria given. /// </summary> /// <param name="criteria">Criteria to match on.</param> /// <param name="classDef">ClassDef that the BusinessObject must match.</param> /// <returns></returns> public IBusinessObject FindFirst(Criteria criteria, IClassDef classDef) { lock (_lock) { var valueArray = new WeakReference[_loadedBusinessObjects.Count]; _loadedBusinessObjects.Values.CopyTo(valueArray, 0); foreach (IBusinessObject bo in valueArray.Select(GetBusinessObject).Where(bo => bo != null)) { try { if (bo.ClassDef == classDef && (criteria == null || criteria.IsMatch(bo, false))) { return(bo); } } //For Dynamic Business Objects the Props may have been added since the business object was loaded. catch (InvalidPropertyNameException) { //Do Nothing } } return(null); } }