/// <summary> /// Initializes a new instance of the <see cref="ElementActioner<TElement>"/> class. /// </summary> /// <param name="dispatcher">The dispatcher.</param> /// <param name="collection">The collection.</param> /// <param name="addAction">The add action.</param> /// <param name="removeAction">The remove action.</param> public ElementActioner(IBindableCollection <TElement> collection, Action <TElement> addAction, Action <TElement> removeAction, IDispatcher dispatcher) : base(dispatcher) { _addAction = addAction; _removeAction = removeAction; _collection = collection; _copy = new BindableCollection <TElement>(dispatcher); _collection_CollectionChangedHandler = Weak.Event <NotifyCollectionChangedEventArgs>(Collection_CollectionChanged); _collection.CollectionChanged += _collection_CollectionChangedHandler.HandlerProxy.Handler; var internalBindableCollection = collection as IBindableCollection <TElement>; if (internalBindableCollection != null && !internalBindableCollection.HasEvaluated) { internalBindableCollection.Evaluating += (sender, e) => { foreach (var element in e.ItemsYieldedFromEvaluation) { HandleElement(NotifyCollectionChangedAction.Add, element); _copy.Add(element); } }; } else { _collection.ForEach(element => { HandleElement(NotifyCollectionChangedAction.Add, element); _copy.Add(element); }); } }
/// <summary> /// Applies an accumulator function over a sequence. The specified seed value is used as the /// initial accumulator value. /// </summary> /// <typeparam name="TSource">The type of the elements of <paramref name="source"/>.</typeparam> /// <typeparam name="TAccumulate">The type of the accumulator value.</typeparam> /// <param name="source">An <see cref="IBindableCollection{TElement}"/> to aggregate over.</param> /// <param name="seed">The initial accumulator value.</param> /// <param name="func">An accumulator function to be invoked on each element.</param> /// <param name="dependencyAnalysisMode">The dependency analysis mode.</param> /// <returns>The final accumulator value.</returns> public static IBindable <TAccumulate> Aggregate <TSource, TAccumulate>(this IBindableCollection <TSource> source, TAccumulate seed, Expression <Func <TAccumulate, TSource, TAccumulate> > func, DependencyDiscovery dependencyAnalysisMode) { source.ShouldNotBeNull("source"); func.ShouldNotBeNull("func"); seed.ShouldNotBeNull("seed"); var compiledAccumulator = func.Compile(); var function = new Func <IBindableCollection <TSource>, TAccumulate>( sourceElements => { var current = seed; foreach (var sourceElement in sourceElements) { current = compiledAccumulator(current, sourceElement); } return(current); } ); var result = new CustomAggregator <TSource, TAccumulate>(source, function, source.Dispatcher); if (dependencyAnalysisMode == DependencyDiscovery.Enabled) { return(result.DependsOnExpression(func, func.Parameters[1])); } return(result); }
public EditableSet(IBindableCollection <TElement> originals, Action <TElement> editItemAction, Action <TElement> addItemAction, Action <TElement> deleteItemAction) { _originals = originals; _deleteItemAction = deleteItemAction; _addItemAction = addItemAction; _editItemAction = editItemAction; _inserted = new ObservableCollection <Editable <TElement> >(); _editableOriginals = _originals.AsBindable().Select(orig => new Editable <TElement>(orig)); _editableOriginals.Evaluate(); _undoItemChangesCommand = new DelegateCommand <Editable <TElement> >( item => UndoItemChanges(item), item => item.HasChanges ); _deleteItemCommand = new DelegateCommand <Editable <TElement> >( item => DeleteItem(item), item => true ); _undoChangesCommand = new DelegateCommand( ignored => UndoChanges(), ignored => true ); _commitChangesCommand = new DelegateCommand( ignored => CommitChanges(), ignored => true ); }
public ElementActioner(IBindableCollection <TElement> collection, Action <TElement> addAction, Action <TElement> removeAction, IDispatcher dispatcher) : base(dispatcher) { _addAction = addAction; _removeAction = removeAction; _collection = collection; _copy = new BindableCollection <TElement>(dispatcher); _collection_CollectionChangedHandler = Weak.Event <NotifyCollectionChangedEventArgs>(Collection_CollectionChanged); _collection.CollectionChanged += _collection_CollectionChangedHandler.HandlerProxy.Handler; if (!(collection?.HasEvaluated ?? true)) { collection.Evaluating += delegate(object sender, EvaluatingEventArgs <TElement> e) { foreach (var item in e.ItemsYieldedFromEvaluation) { HandleElement(NotifyCollectionChangedAction.Add, item); _copy.Add(item); } }; } else { _collection.ForEach(delegate(TElement element) { HandleElement(NotifyCollectionChangedAction.Add, element); _copy.Add(element); }); } }
/// <summary> /// Projects each element of a sequence to an <see cref="IBindableCollection{TElement}"/> and flattens the resulting sequences into one sequence. /// </summary> /// <typeparam name="TSource">The type of the elements of <paramref name="source"/>.</typeparam> /// <typeparam name="TResult">The type of the elements of the sequence returned by <paramref name="selector"/>.</typeparam> /// <param name="source">A sequence of values to project.</param> /// <param name="selector">A transform function to apply to each element.</param> /// <param name="dependencyAnalysisMode">The dependency analysis mode.</param> /// <returns> /// An <see cref="IBindableCollection{TElement}"/> whose elements are the result of invoking the one-to-many transform function on each element of the input sequence. /// </returns> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="source"/> or <paramref name="selector"/> is null.</exception> public static IBindableCollection <TResult> SelectMany <TSource, TResult>(this IBindableCollection <TSource> source, Expression <Func <TSource, IBindableCollection <TResult> > > selector, DependencyDiscovery dependencyAnalysisMode) where TSource : class where TResult : class { source.ShouldNotBeNull("source"); return(source.Select(selector, dependencyAnalysisMode).UnionAll()); }
/// <summary> /// Projects the groups from a GroupBy into a new element type. /// </summary> /// <typeparam name="TKey">The type of the key returned by <paramref name="resultSelector"/>.</typeparam> /// <typeparam name="TElement">The type of the elements in each <see cref="T:System.Linq.IGrouping`2"/>.</typeparam> /// <typeparam name="TResult">The type of the result value returned by <paramref name="resultSelector"/>.</typeparam> /// <param name="source">An <see cref="IBindableCollection{TElement}"/> whose elements to group.</param> /// <param name="resultSelector">A function to create a result value from each group.</param> /// <returns> /// A collection of elements of type <typeparamref name="TResult"/> where each element represents a projection over a group and its key. /// </returns> public static IBindableCollection <TResult> Into <TKey, TElement, TResult>(this IBindableCollection <IBindableGrouping <TKey, TElement> > source, Expression <Func <TKey, IBindableCollection <TElement>, TResult> > resultSelector) where TElement : class where TResult : class { var func = resultSelector.Compile(); return(source.Select(g => func(g.Key, g), DependencyDiscovery.Disabled)); }
private void WireInterceptor(IBindableCollection <TElement> source) { _source = source; _source.CollectionChanged += _weakHandler.Handler; _propertyChangeObserver = new PropertyChangeObserver(Element_PropertyChanged); _addActioner = new ElementActioner <TElement>(_source, element => _propertyChangeObserver.Attach(element), element => _propertyChangeObserver.Detach(element), Dispatcher); }
private void ChildCollectionAdded(IBindableCollection <TElement> collection) { _childCollectionActioners[collection] = new ElementActioner <TElement>( collection, item => ResultCollection.Add(item), item => ResultCollection.Remove(item), Dispatcher); }
public ItemDependency(string propertyPath, IBindableCollection <TElement> sourceElements, IPathNavigator pathNavigator) { _pathNavigator = pathNavigator; _sourceElementObservers = new Dictionary <TElement, IToken>(); _propertyPath = propertyPath; _sourceElements = sourceElements; _actioner = new ElementActioner <TElement>(sourceElements, AddItem, RemoveItem, sourceElements.Dispatcher); }
/// <summary> /// Returns distinct elements from a sequence by using a specified <see cref="T:System.Collections.Generic.IEqualityComparer`1"/> to compare values. /// </summary> /// <typeparam name="TSource">The type of the elements of <paramref name="source"/>.</typeparam> /// <param name="source">The sequence to remove duplicate elements from.</param> /// <param name="comparer">An <see cref="T:System.Collections.Generic.IEqualityComparer`1"/> to compare values.</param> /// <returns> /// An <see cref="IBindableCollection{TElement}"/> that contains distinct elements from the source sequence. /// </returns> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="source"/> is null.</exception> public static IBindableCollection <TSource> Distinct <TSource>(this IBindableCollection <TSource> source, IEqualityComparer <TSource> comparer) where TSource : class { if (comparer == null) { comparer = new DefaultComparer <TSource>(); } return(source.GroupBy(c => comparer.GetHashCode(c), DependencyDiscovery.Disabled).Select(group => group.First().Current, DependencyDiscovery.Disabled)); }
/// <summary> /// Initializes a new instance of the <see cref="GroupByIterator<TKey, TSource, TElement>"/> class. /// </summary> /// <param name="sourceCollection">The source collection.</param> /// <param name="keySelector">The key selector.</param> /// <param name="elementSelector">The element selector.</param> /// <param name="keyComparer">The key comparer.</param> /// <param name="dispatcher">The dispatcher.</param> public GroupByIterator(IBindableCollection <TSource> sourceCollection, Expression <Func <TSource, TKey> > keySelector, Expression <Func <TSource, TElement> > elementSelector, IEqualityComparer <TKey> keyComparer, IDispatcher dispatcher) : base(sourceCollection, dispatcher) { _keySelector = keySelector; _keySelectorCompiled = keySelector.Compile(); _elementSelector = elementSelector; _keyComparer = keyComparer; }
/// <summary> /// Initializes a new instance of the <see cref="BindableGrouping<TKey, TElement>"/> class. /// </summary> /// <param name="key">The key.</param> /// <param name="groupWhereQuery">The group query.</param> /// <param name="dispatcher">The dispatcher.</param> public BindableGrouping(TKey key, IBindableCollection <TElement> groupWhereQuery, IDispatcher dispatcher) : base(dispatcher) { _key = key; _groupWhereQuery = groupWhereQuery; _groupWhereQuery.Evaluating += (sender, e) => OnEvaluating(e); _groupWhereQuery.CollectionChanged += (sender, e) => OnCollectionChanged(e); _groupWhereQuery.PropertyChanged += (sender, e) => OnPropertyChanged(e); }
/// <summary> /// Initializes a new instance of the <see cref="Iterator<TSource, TResult>"/> class. /// </summary> protected Iterator(IBindableCollection <TSource> sourceCollection, IDispatcher dispatcher) : base(dispatcher) { _resultCollection = new BindableCollection <TResult>(dispatcher); _resultCollection.CollectionChanged += ((sender, e) => OnCollectionChanged(e)); _sourceCollection = sourceCollection; _sourceCollection.CollectionChanged += Weak.Event <NotifyCollectionChangedEventArgs>((sender, e) => Dispatcher.Dispatch(() => ReactToCollectionChanged(e))).KeepAlive(InstanceLifetime).HandlerProxy.Handler; }
/// <summary> /// Determines whether a sequence contains any elements. /// </summary> /// <param name="source">The <see cref="IBindableCollection{TElement}" /> to check for emptiness.</param> /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam> /// <returns>true if the source sequence contains any elements; otherwise, false.</returns> public static IBindable <bool> Any <TSource>(this IBindableCollection <TSource> source) { source.ShouldNotBeNull("source"); return(source.Count() .Switch() .Case(count => count >= 1, true) .Default(false) .EndSwitch()); }
/// <summary> /// Determines whether all elements of a sequence satisfy a condition. /// </summary> /// <param name="source">An <see cref="IBindableCollection{TElement}" /> that contains the elements to apply the predicate to.</param> /// <param name="predicate">A function to test each element for a condition.</param> /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam> /// <returns> /// true if every element of the source sequence passes the test in the specified /// predicate, or if the sequence is empty; otherwise, false. /// </returns> public static IBindable <bool> All <TSource>(this IBindableCollection <TSource> source, Expression <Func <TSource, bool> > predicate) where TSource : class { source.ShouldNotBeNull("source"); predicate.ShouldNotBeNull("predicate"); return(source.Where(predicate).Count() .Switch() .Case(count => count >= 1, true) .Default(false) .EndSwitch()); }
/// <summary> /// Produces the set union of two sequences by using the default equality comparer. /// </summary> /// <typeparam name="TSource">The type of the elements of the input sequences.</typeparam> /// <param name="first">An <see cref="IBindableCollection{TElement}"/> whose distinct elements form the first set for the union.</param> /// <param name="second">An <see cref="IBindableCollection{TElement}"/> whose distinct elements form the second set for the union.</param> /// <returns> /// An <see cref="IBindableCollection{TElement}"/> that contains the elements from both input sequences, excluding duplicates. /// </returns> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="first"/> or <paramref name="second"/> is null.</exception> public static IBindableCollection <TSource> Union <TSource>(this IBindableCollection <TSource> first, IBindableCollection <TSource> second) where TSource : class { first.ShouldNotBeNull("first"); second.ShouldNotBeNull("second"); var sources = new BindableCollection <IBindableCollection <TSource> >(first.Dispatcher) { first, second }; return(new UnionIterator <TSource>(sources, first.Dispatcher)); }
private void UnwireInterceptor() { _addActioner.Dispose(); _propertyChangeObserver.Dispose(); _source.CollectionChanged -= _weakHandler.Handler; if (_source != _originalSource) { _source.Dispose(); } _source = null; }
/// <summary> /// Projects each element of a sequence into a new form. /// </summary> /// <typeparam name="TSource">The type of the elements of <paramref name="source"/>.</typeparam> /// <typeparam name="TResult">The type of the value returned by <paramref name="selector"/>.</typeparam> /// <param name="source">A sequence of values to invoke a transform function on.</param> /// <param name="selector">A transform function to apply to each element.</param> /// <param name="dependencyAnalysisMode">The dependency analysis mode.</param> /// <returns> /// An <see cref="IBindableCollection{TElement}"/> whose elements are the result of invoking the transform function on each element of <paramref name="source"/>. /// </returns> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="source"/> or <paramref name="selector"/> is null.</exception> public static IBindableCollection <TResult> Select <TSource, TResult>(this IBindableCollection <TSource> source, Expression <Func <TSource, TResult> > selector, DependencyDiscovery dependencyAnalysisMode) where TSource : class { source.ShouldNotBeNull("source"); selector.ShouldNotBeNull("selector"); var result = new SelectIterator <TSource, TResult>(source, selector.Compile(), source.Dispatcher); if (dependencyAnalysisMode == DependencyDiscovery.Enabled) { result = result.DependsOnExpression(selector.Body, selector.Parameters[0]); } return(result); }
/// <summary> /// Bindable LINQ: Filters a sequence of values based on a predicate. Each item will be re-evaluated if it raises a property changed event, or if any properties /// accessed in the filter expression raise events. Items will be re-evaluated when the source collection raises CollectionChanged events. The entire collection /// will be re-evaluated if the source collection raises a Reset event, or if any addtional dependencies added via the <see cref="WithDependencies{TResult}"/> /// extension method tell it to re-evaluate. /// </summary> /// <typeparam name="TSource">The type of the elements of <paramref name="source"/>.</typeparam> /// <param name="source">An <see cref="IBindableCollection{TElement}"/> to filter.</param> /// <param name="predicate">A function to test each element for a condition.</param> /// <param name="dependencyAnalysisMode">The dependency analysis mode.</param> /// <returns> /// An <see cref="IBindableCollection{TElement}"/> that contains elements from the input sequence that satisfy the condition. /// </returns> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="source"/> or <paramref name="predicate"/> is null.</exception> public static IBindableCollection <TSource> Where <TSource>(this IBindableCollection <TSource> source, Expression <Func <TSource, bool> > predicate, DependencyDiscovery dependencyAnalysisMode) where TSource : class { source.ShouldNotBeNull("source"); predicate.ShouldNotBeNull("predicate"); var result = new WhereIterator <TSource>(source, predicate.Compile(), source.Dispatcher); if (dependencyAnalysisMode == DependencyDiscovery.Enabled) { return(result.DependsOnExpression(predicate.Body, predicate.Parameters[0])); } return(result); }
/// <summary> /// Sorts the elements of a sequence in ascending order by using a specified comparer. /// </summary> /// <typeparam name="TSource">The type of the elements of <paramref name="source"/>.</typeparam> /// <typeparam name="TKey">The type of the key returned by <paramref name="keySelector"/>.</typeparam> /// <param name="source">A sequence of values to order.</param> /// <param name="keySelector">A function to extract a key from an element.</param> /// <param name="comparer">An <see cref="T:System.Collections.Generic.IComparer`1"/> to compare keys.</param> /// <param name="dependencyAnalysisMode">The dependency analysis mode.</param> /// <returns> /// An <see cref="T:System.Linq.IOrderedEnumerable`1"/> whose elements are sorted according to a key. /// </returns> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="source"/> or <paramref name="keySelector"/> is null.</exception> public static IOrderedBindableCollection <TSource> OrderBy <TSource, TKey>(this IBindableCollection <TSource> source, Expression <Func <TSource, TKey> > keySelector, IComparer <TKey> comparer, DependencyDiscovery dependencyAnalysisMode) where TSource : class { source.ShouldNotBeNull("source"); keySelector.ShouldNotBeNull("keySelector"); var result = new OrderByIterator <TSource, TKey>(source, new ItemSorter <TSource, TKey>(null, keySelector.Compile(), comparer, true), source.Dispatcher); if (dependencyAnalysisMode == DependencyDiscovery.Enabled) { return(result.DependsOnExpression(keySelector.Body, keySelector.Parameters[0])); } return(result); }
/// <summary> /// Applies an accumulator function over a sequence. /// </summary> /// <typeparam name="TSource">The type of the elements of <paramref name="source"/>.</typeparam> /// <typeparam name="TResult">The type of the result.</typeparam> /// <param name="source">An <see cref="IBindableCollection{TSource}"/> to aggregate over.</param> /// <param name="func">An accumulator function to be invoked on each element.</param> /// <param name="dependencyAnalysisMode">The dependency analysis mode.</param> /// <returns>The final accumulator value.</returns> public static IBindable <TResult> Aggregate <TSource, TResult>(this IBindableCollection <TSource> source, Expression <Func <IBindableCollection <TSource>, TResult> > func, DependencyDiscovery dependencyAnalysisMode) { source.ShouldNotBeNull("source"); func.ShouldNotBeNull("func"); var result = new CustomAggregator <TSource, TResult>(source, func.Compile(), source.Dispatcher); if (dependencyAnalysisMode == DependencyDiscovery.Enabled) { return(result.DependsOnExpression(func, func.Parameters[0])); } return(result); }
/// <summary> /// Initializes a new instance of the <see cref="Scenario<TInput>"/> class. /// </summary> /// <param name="title">The title.</param> /// <param name="inputs">The inputs.</param> /// <param name="steps">The steps.</param> /// <param name="bindableLinqQuery">The bindable linq query.</param> /// <param name="standardLinqQuery">The standard linq query.</param> public Scenario(string title, ObservableCollection <TInput> inputs, IEnumerable <Step> steps, IBindableCollection bindableLinqQuery, IEnumerable standardLinqQuery) { _title = title; _inputs = inputs; _steps = steps.ToList(); _bindableLinqQuery = bindableLinqQuery; _standardLinqQuery = standardLinqQuery; _eventMonitor = new CollectionEventMonitor(_bindableLinqQuery); foreach (var step in _steps) { step.Scenario = this; } }
/// <summary> /// Initializes a new instance of the <see cref="UnionIterator<TElement>"/> class. /// </summary> /// <param name="elements">The elements.</param> /// <param name="dispatcher">The dispatcher.</param> public UnionIterator(IBindableCollection <IBindableCollection <TElement> > elements, IDispatcher dispatcher) : base(elements, dispatcher) { // A map of actioners for each of the collections being unioned _childCollectionActioners = new Dictionary <IBindableCollection <TElement>, ElementActioner <TElement> >(); // An actioner that invokes the Added/Removed delegates each time a collection is added to the list of // collections being unioned _rootActioner = new ElementActioner <IBindableCollection <TElement> >( SourceCollection, ChildCollectionAdded, ChildCollectionRemoved, Dispatcher); }
public IteratorQueryNode(IBindableCollection query) { _iterator = query; _events = new ObservableCollection<IQueryNodeEvent>(); _iterator.CollectionChanged += delegate(object sender, NotifyCollectionChangedEventArgs e) { _events.Add(new NotifyCollectionChangedQueryNodeEvent(e)); }; _iterator.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e) { _events.Add(new PropertyChangedQueryNodeEvent(e)); }; _childNodes = _iterator.AsBindable<object>() .Select(c => QueryNodeFactory.Create(c)); }
public IteratorQueryNode(IBindableCollection query) { _iterator = query; _events = new ObservableCollection <IQueryNodeEvent>(); _iterator.CollectionChanged += delegate(object sender, NotifyCollectionChangedEventArgs e) { _events.Add(new NotifyCollectionChangedQueryNodeEvent(e)); }; _iterator.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e) { _events.Add(new PropertyChangedQueryNodeEvent(e)); }; _childNodes = _iterator.AsBindable <object>() .Select(c => QueryNodeFactory.Create(c)); }
public BrowserSelector(IBrowserProvider[] browsers, ISettingsManager settings) { browsers = browsers.Where(x => x.IsSupported).ToArray(); AvailableBrowsers = browsers.Select(x => x.Id).ToBindable(); BrowserEngine = settings.Register <string>("browser_engine"); DefaultUrl = settings.Register("browser.game_url", "http://www.dmm.com/netgame_s/kancolle/"); string engine = BrowserEngine.InitialValue; SelectedBrowser = browsers.FirstOrDefault(x => x.Id == engine) ?? browsers.FirstOrDefault() ?? throw new InvalidOperationException("It must have at least one browser provider."); SelectedBrowser.Initialize(); }
/// <summary> /// Executes the scenario and verifies the expectations attached to it. /// </summary> public void Execute() { Tracer.WriteLine("Validating scenario: {0}", this.Title); int stepCount = 1; using (Tracer.Indent()) { foreach (var step in _steps) { Tracer.Write("Step {0} ", stepCount); try { step.Execute(); Tracer.WriteLine(""); } catch { Tracer.WriteLine("failed"); Tracer.WriteLine(""); Tracer.WriteLine("Exception details:"); throw; } stepCount++; } // Ensure no additional events are in the queue Tracer.WriteLine("Finalizing: Verifying additional events were not raised."); Assert.IsNull(EventMonitor.DequeueNextEvent(), "The test has completed, but there are still events in the queue that were not expected."); // Compare with LINQ to Objects Tracer.WriteLine("Finalizing: Comparing final results to LINQ to Objects"); CompatibilityValidator.CompareWithLinq(CompatabilityLevel.FullyCompatible, BindableLinqQuery, StandardLinqQuery); // Forget all references to the query and ensure it is garbage collected Tracer.WriteLine("Finalizing: Detecting memory leaks and event handlers that have not been unhooked."); WeakReference bindableQuery = new WeakReference(this.BindableLinqQuery, false); _bindableLinqQuery = null; _eventMonitor.Dispose(); GC.Collect(); GC.WaitForPendingFinalizers(); Assert.IsFalse(bindableQuery.IsAlive, "There should be no live references to the bindable query at this point. This may indicate that the query or items within the query have event handlers that have not been unhooked."); } }
public BindableGrouping(TKey key, IBindableCollection <TElement> groupWhereQuery, IDispatcher dispatcher) : base(dispatcher) { Key = key; _groupWhereQuery = groupWhereQuery; var groupWhereQuery2 = _groupWhereQuery; void Handler(object sender, EvaluatingEventArgs <TElement> e) { OnEvaluating(e); } groupWhereQuery2.Evaluating += Handler; _groupWhereQuery.CollectionChanged += delegate(object sender, NotifyCollectionChangedEventArgs e) { OnCollectionChanged(e); }; _groupWhereQuery.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e) { OnPropertyChanged(e); }; }
/// <summary> /// Initializes a new instance of the <see cref="BindingListAdapter<TElement>"/> class. /// </summary> /// <param name="source">The source.</param> /// <param name="dispatcher">The dispatcher.</param> public BindingListAdapter(IBindableCollection <TElement> source, IDispatcher dispatcher) : base(dispatcher) { source.ShouldNotBeNull("source"); _originalSource = source; _eventHandler = Source_CollectionChanged; _weakHandler = new WeakEventProxy <NotifyCollectionChangedEventArgs>(_eventHandler); _sortDirection = ListSortDirection.Ascending; WireInterceptor(_originalSource); _propertyDescriptors = new Dictionary <string, PropertyDescriptor>(); var properties = TypeDescriptor.GetProperties(typeof(TElement)); foreach (PropertyDescriptor descriptor in properties) { if (descriptor != null && descriptor.Name != null) { _propertyDescriptors[descriptor.Name] = descriptor; } } }
public PizzaCustomizer(Pizza pizza) { _pizza = pizza; _availableToppings = _pizza.AvailableToppings .AsBindable() .Select(topping => new SelectableTopping(topping)); _selectedToppings = _availableToppings .Where(selectableTopping => selectableTopping.IsSelected) .Select(selectableTopping => selectableTopping.Topping); _healthWarningMessage = _selectedToppings.Count() .Switch() .Case(0, "Surely you would like more toppings?") .Case(toppings => toppings >= 3, "Too many toppings!") .Default( "Perfecto!") .EndSwitch(); _totalPrice = _selectedToppings.Sum(topping => topping.Price).Project(toppingsTotal => toppingsTotal + pizza.BasePrice); }
/// <summary> /// Groups the elements of a sequence according to a specified key selector function and projects the elements for each group by using a specified function. /// </summary> /// <typeparam name="TSource">The type of the elements of <paramref name="source"/>.</typeparam> /// <typeparam name="TKey">The type of the key returned by <paramref name="keySelector"/>.</typeparam> /// <typeparam name="TElement">The type of the elements in the <see cref="T:System.Linq.IGrouping`2"/>.</typeparam> /// <param name="source">An <see cref="IBindableCollection{TElement}"/> whose elements to group.</param> /// <param name="keySelector">A function to extract the key for each element.</param> /// <param name="elementSelector">A function to map each source element to an element in the <see cref="T:System.Linq.IGrouping`2"/>.</param> /// <returns> /// An IEnumerable<IGrouping<TKey, TElement>> in C# or IEnumerable(Of IGrouping(Of TKey, TElement)) in Visual Basic where each <see cref="T:System.Linq.IGrouping`2"/> object contains a collection of objects of type TElement and a key. /// </returns> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="source"/> or <paramref name="keySelector"/> or <paramref name="elementSelector"/> is null.</exception> public static IBindableCollection <IBindableGrouping <TKey, TElement> > GroupBy <TSource, TKey, TElement>(this IBindableCollection <TSource> source, Expression <Func <TSource, TKey> > keySelector, Expression <Func <TSource, TElement> > elementSelector) where TSource : class where TElement : class { return(GroupBy(source, keySelector, elementSelector, DefaultDependencyAnalysis)); }
public void Initialize(IPluginContext pluginContext) { this.commandRunner = pluginContext.CommandRunner; this.standAloneCommands = pluginContext.CommandProvider.StandAloneCommands; this.standAloneCommands.CollectionChanged += (sender, e) => { foreach (var command in e.NewItems.OfType<ICommand>()) { IncludeDefaultBindings(command); } }; string extensionPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var compositionContainer = new CompositionContainer(new DirectoryCatalog(extensionPath)); Recompose(compositionContainer); compositionContainer.ExportsChanged += (sender, e) => Recompose(compositionContainer); SetUp(); }