Exemple #1
0
        // Generate sub-group based on property equality
        void GroupBy(INTERNAL_PropertyGroupDescription operation)
        {
            List <Collection <object> > childGroups = new List <Collection <object> >();

            foreach (object item in Items)
            {
                bool find = false;

                foreach (Collection <object> child in childGroups)
                {
                    if (Object.Equals(GetValue(child[0], operation), GetValue(item, operation)))
                    {
                        child.Add(item);
                        find = true;
                        break;
                    }
                }

                if (!find)
                {
                    childGroups.Add(new Collection <object>());
                    childGroups[childGroups.Count - 1].Add(item);
                }
            }

            foreach (Collection <object> child in childGroups)
            {
                INTERNAL_CollectionViewGroupInternal newView = new INTERNAL_CollectionViewGroupInternal(child, this, _operations, _level + 1);
                _operations.Requester.AddView(newView); // create child branch (level matter in grouping views)
            }
        }
Exemple #2
0
        // Execute the next operation requested in the operations list
        void ExecuteOperation(object operation)
        {
            if (operation != null)
            {
                IsLeaf = false;

                if (operation is FilterDescription)
                {
                    FilterDescription filterOperation = (FilterDescription)operation;

                    // both cannot be null and both cannot be not null
                    if (filterOperation.FilterUsingAnEvent != null)
                    {
                        Filter(filterOperation.FilterUsingAnEvent);
                    }
                    else
                    {
                        Filter(filterOperation.FilterUsingAPredicate);
                    }
                }
                else if (operation is PropertySortDescription)
                {
                    PropertySortDescription sortOperation = (PropertySortDescription)operation;

                    if (sortOperation.Comparer == null)
                    {
                        Sort(sortOperation);
                    }
                    else
                    {
                        CustomSort(sortOperation);
                    }
                }
                else if (operation is INTERNAL_PropertyGroupDescription)
                {
                    INTERNAL_PropertyGroupDescription groupOperation = (INTERNAL_PropertyGroupDescription)operation;

                    GroupBy(groupOperation);
                }
                else
                {
                    throw new InvalidOperationException("unknow operation type");
                }
            }
            else // if the operation to do on this view is null, that mean we have reach the end of the operation list and this view is usable as data source
            {
                IsLeaf = true;
            }
        }
Exemple #3
0
 // Get the value of the property described in operation by reflection
 object GetValue(object obj, INTERNAL_PropertyGroupDescription operation)
 {
     return(obj.GetType().GetProperty(operation.PropertyName).GetValue(obj, null));
 }