コード例 #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());
 }
コード例 #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);
        }
コード例 #3
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);
        }