Example #1
0
 /// <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());
 }
Example #2
0
        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);
        }
        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);
        }