/// <summary>
 /// Aplica o filtro sobre a coleção.
 /// </summary>
 /// <typeparam name="T">Tipo que é armazenado na coleção.</typeparam>
 /// <param name="collection">Coleção que será filtrada.</param>
 /// <param name="filter">Predicato que será utilizado.</param>
 public static Collections.FilteredObservableCollection <T> ApplyFilter <T>(this Collections.IObservableCollection <T> collection, Predicate <T> filter)
 {
     if (collection == null)
     {
         return(null);
     }
     return(new Collections.FilteredObservableCollection <T>(collection, filter));
 }
        /// <summary>
        /// Cria um indice do tipo hash para a coleção.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="PropertyType"></typeparam>
        /// <param name="collection"></param>
        /// <param name="property"></param>
        public static void CreateHashIndex <T, PropertyType>(this Collections.IObservableCollection <T> collection, System.Linq.Expressions.Expression <Func <T, PropertyType> > property)
        {
            var indexedCollection = collection as Collections.IIndexedObservableCollection <T>;

            if (indexedCollection == null)
            {
                return;
            }
            indexedCollection.CreateIndex <PropertyType>(property, Collections.ObservableCollectionIndexType.Hash);
        }
        /// <summary>
        /// Cria uma coleção ordena.
        /// </summary>
        /// <param name="source">Coleção de origem dos dados.</param>
        /// <param name="properties">Propriedade que serão utilizadas na ordenação.</param>
        /// <returns></returns>
        public static Collections.IObservableCollection OrderByObservableCollection(this Collections.IObservableCollection source, params string[] properties)
        {
            source.Require("source").NotNull();
            properties.Require("properties").NotNull().NotEmptyCollection();
            var type = source.GetType().FindInterfaces((t, m) => t.IsGenericType && typeof(Collections.IObservableCollection <>).IsAssignableFrom(t.GetGenericTypeDefinition()), null).Select(f => f.GetGenericArguments().FirstOrDefault()).FirstOrDefault();

            if (type == null)
            {
                throw new InvalidOperationException("Invalid source");
            }
            var comparer = typeof(PropertiesComparer <>).MakeGenericType(type).GetConstructor(new Type[] {
                typeof(string[])
            }).Invoke(new object[] {
                properties
            });

            return((Collections.IObservableCollection)Activator.CreateInstance(typeof(Collections.SortableObservableCollection <>).MakeGenericType(type), source, comparer));
        }
 /// <summary>
 /// Faz o cast da coleção informada para a coleção do tipo TDestination.
 /// </summary>
 /// <typeparam name="TDestination"></typeparam>
 /// <param name="source"></param>
 /// <returns></returns>
 public static Collections.IObservableCollection <TDestination> CastObservableCollection <TDestination>(this Collections.IObservableCollection source)
 {
     if (source == null)
     {
         return(null);
     }
     return(new Collections.ObservableCollectionWrapper <TDestination>(source));
 }
 public static Collections.IObservableCollection <T> OrderByObservableCollection <T>(this Collections.IObservableCollection <T> source, params System.Linq.Expressions.Expression <Func <T, object> >[] properties)
 {
     source.Require("source").NotNull();
     properties.Require("properties").NotNull().NotEmptyCollection();
     return(new Collections.SortableObservableCollection <T>(source, new PropertiesComparer <T>(properties)));
 }
Beispiel #6
0
 /// <summary>
 /// Construtor para lista com items personalizados.
 /// </summary>
 /// <param name="controller"></param>
 /// <param name="items"></param>
 /// <param name="selected"></param>
 /// <param name="itemCreator"></param>
 public EntitySelectionList(Colosoft.Business.IEntity controller, Collections.IObservableCollection <TBusiness> items, Collections.IObservableCollection <TBusiness> selected, Func <Colosoft.Business.IEntity, TBusiness, Collections.IObservableCollection <TBusiness>, Item> itemCreator) : base(items, e => itemCreator(controller, e, selected))
 {
     _selected = selected;
 }