public bool AddBeverage(Beverage bev) { if (HasType(bev.GetType()) && !_multipleAllows.Contains(bev.GetType())) { return(false); } _types.Add(bev.GetType()); _beverage.Add(bev); return(true); }
public IEnumerable <int> Start() { if (_beverage.GetType() == typeof(Beverages.HotChocolate)) { return(HotChocolate()); } if (_beverage.GetType() == typeof(Beverages.IcedCoffe)) { return(IcedCoffe()); } if (_beverage.GetType() == typeof(Beverages.LemonTea)) { return(LemonTea()); } if (_beverage.GetType() == typeof(Beverages.WhiteCoffee)) { return(WhiteCoffee()); } throw new InvalidOperationException("There is no such Beverage!"); }
public static T GetProperty <T>(this Beverage beverage, Expression <Func <BeverageListItemDto, T> > predicate) where T : IConvertible { if (!(predicate.Body is MemberExpression memberExpression)) { return(default(T)); } var property = beverage.GetType().GetProperty(memberExpression.Member.Name); if (property == null) { return(default(T)); } return((T)Convert.ChangeType(property.GetValue(beverage), typeof(T))); }