public static IAgenteHipatiaList GetList(IList <IAgenteHipatia> list) { IAgenteHipatiaList flist = new IAgenteHipatiaList(new List <IAgenteHipatia>()); if (list.Count > 0) { foreach (IAgenteHipatia item in list) { flist.Add(item); } } return(flist); }
/// <summary> /// Devuelve una lista ordenada y filtrada a partir de los datos de la lista /// actual /// </summary> /// <param name="criteria">Filtro</param> /// <param name="sortProperty">Campo de ordenación</param> /// <param name="sortDirection">Sentido de ordenación</param> /// <returns>Lista ordenada</returns> public IAgenteHipatiaList GetSortedSubList(FCriteria criteria, string sortProperty, ListSortDirection sortDirection) { IAgenteHipatiaList sortedList = new IAgenteHipatiaList(new List <IAgenteHipatia>()); if (this.Count == 0) { return(sortedList); } PropertyDescriptor property = TypeDescriptor.GetProperties(this[0]).Find(criteria.GetProperty(), false); switch (criteria.Operation) { case Operation.StartsWith: { foreach (IAgenteHipatia item in this) { foreach (PropertyDescriptor prop in TypeDescriptor.GetProperties(item)) { if (prop.Name == property.Name) { object value = prop.GetValue(item); if (value.ToString().ToLower().StartsWith(criteria.GetValue().ToString().ToLower())) { sortedList.Add(item); } break; } } } } break; case Operation.Equal: { foreach (IAgenteHipatia item in this) { foreach (PropertyDescriptor prop in TypeDescriptor.GetProperties(item)) { if (prop.Name == property.Name) { object value = prop.GetValue(item); if (criteria.Equal(value)) { sortedList.Add(item); } break; } } } } break; case Operation.Less: { foreach (IAgenteHipatia item in this) { foreach (PropertyDescriptor prop in TypeDescriptor.GetProperties(item)) { if (prop.Name == property.Name) { object value = prop.GetValue(item); if (criteria.Less(value)) { sortedList.Add(item); } break; } } } } break; case Operation.LessOrEqual: { foreach (IAgenteHipatia item in this) { foreach (PropertyDescriptor prop in TypeDescriptor.GetProperties(item)) { if (prop.Name == property.Name) { object value = prop.GetValue(item); if (criteria.LessOrEqual(value)) { sortedList.Add(item); } break; } } } } break; case Operation.Greater: { foreach (IAgenteHipatia item in this) { foreach (PropertyDescriptor prop in TypeDescriptor.GetProperties(item)) { if (prop.Name == property.Name) { object value = prop.GetValue(item); if (criteria.Greater(value)) { sortedList.Add(item); } break; } } } } break; case Operation.GreaterOrEqual: { foreach (IAgenteHipatia item in this) { foreach (PropertyDescriptor prop in TypeDescriptor.GetProperties(item)) { if (prop.Name == property.Name) { object value = prop.GetValue(item); if (criteria.GreaterOrEqual(value)) { sortedList.Add(item); } break; } } } } break; default: { foreach (IAgenteHipatia item in this) { foreach (PropertyDescriptor prop in TypeDescriptor.GetProperties(item)) { if (prop.Name == property.Name) { object value = prop.GetValue(item); if (value.ToString().ToLower().Contains(criteria.GetValue().ToString().ToLower())) { sortedList.Add(item); } break; } } } } break; } sortedList.ApplySort(sortProperty, sortDirection); return(sortedList); }