Пример #1
0
        ///<summary>Binds this selection to a collection of data. This creates a new selection with Enter and Exit selections, which can then be used to create missing elements and/or delete excess elements.</summary>
        ///<remarks>In a typical case, you would use <see href="Selection{E,T}.Join{T2}" />Join function, which handles Enter and Exit selections for you.</remarks>
        ///<param name="bindingFunc">A callback function that is called once for each group, and should provide the data collection for this group. It's parameters are parent's data object and the collection of elements.</param>
        public Selection <TElementType, TNewDataType, TParentDataType> Bind <TNewDataType>(Func <object, IReadOnlyCollection <TElementType>, IEnumerable <TNewDataType> > bindingFunc)
        {
            var enters  = new EnterSelection <TNewDataType, TParentDataType> .EnterGroup[_groups.Count];
            var updates = new Selection <TElementType, TNewDataType, TParentDataType> .GroupWithData[_groups.Count];
            var exits   = new Selection <TElementType, TNewDataType, TParentDataType> .GroupWithData[_groups.Count];

            int counter = 0;

            foreach (var groupWithData in _groups)
            {
                var tuple = Bind(groupWithData, bindingFunc(groupWithData.GroupParent.GetBoundData(), groupWithData.Elements));

                enters[counter]  = tuple.Item1;
                updates[counter] = tuple.Item2;
                exits[counter]   = tuple.Item3;
                counter++;
            }

            var enterSelection = new EnterSelection <TNewDataType, TParentDataType>(enters);
            var exitSelection  = new Selection <TElementType, TNewDataType, TParentDataType>(exits);

            return(new Selection <TElementType, TNewDataType, TParentDataType>(updates, enterSelection, exitSelection));
        }
Пример #2
0
 internal Selection(IReadOnlyCollection <GroupWithData> groups, EnterSelection <TDataType, TParentDataType> enter, Selection <TElementType, TDataType, TParentDataType> exit)
 {
     _groups         = groups;
     _enterSelection = enter;
     _exitSelection  = exit;
 }
Пример #3
0
 internal Selection(IReadOnlyCollection <GroupWithData> groups)
 {
     _groups         = groups;
     _enterSelection = null;
     _exitSelection  = null;
 }
Пример #4
0
 ///<summary>Creates a selection from a read-only collection. The collection is not copied, so Selection expects it not to change during it's existence.</summary>
 public Selection(IReadOnlyCollection <TElementType> selected)
 {
     _groups         = new [] { new GroupWithData(null, selected) };
     _enterSelection = null;
     _exitSelection  = null;
 }