Пример #1
0
        public object this[string id]
        {
            get
            {
                IMixable mixable = null;

                if (_current.HasKey(id))
                {
                    object value = _current[id];

                    if (value is IMixable)
                    {
                        mixable = value as IMixable;

                        if (!mixable.IsMixMeaningful)
                        {
                            return(mixable);
                        }
                    }
                    else if (value != null)
                    {
                        return(value);
                    }
                }

                if (_style != null)
                {
                    for (int idx = 0; idx < _style.Length; ++idx)
                    {
                        if (_style[idx] != null)
                        {
                            object value = _style[idx][id];

                            if (value is IMixable)
                            {
                                if (mixable == null)
                                {
                                    mixable = value as IMixable;
                                }
                                else
                                {
                                    mixable = mixable.Mix(value as IMixable);
                                }

                                if (!mixable.IsMixMeaningful)
                                {
                                    return(mixable);
                                }
                            }
                            else if (value != null)
                            {
                                return(value);
                            }
                        }
                    }
                }

                return(mixable);
            }
        }
Пример #2
0
        public void Mix(IMixable otherMixable)
        {
            if (otherMixable.GetType() == typeof(Latte))
            {
                Console.Write("You got some milky weird mix!");
            }

            if (otherMixable.GetType() == typeof(Cortado))
            {
                Console.Write("You just got a very big Cortado! Nothing special!");
            }
        }
Пример #3
0
        static void Main(string[] args)
        {
            int  action      = 1;
            int  selectedObj = 0;
            Shop shop        = new Shop();

            while (action != 5)
            {
                ShowMenu();
                if (int.TryParse(Console.ReadLine(), out action))
                {
                    if (shop.CountSection > 0)
                    {
                        if (action > 0 && action < 5)
                        {
                            if ((selectedObj = GetObj()) != -1)
                            {
                                if (action == 3 && selectedObj != 3)
                                {
                                    selectedObj++;
                                }
                                IMixable obj = (IMixable)shop;
                                if (selectedObj == 2)
                                {
                                    obj = (IMixable)shop.GetSection();
                                }
                                else if (selectedObj == 3)
                                {
                                    obj = (IMixable)shop.GetCategory();
                                }
                                DoAction(obj, action);
                            }
                        }
                    }
                }
                else
                {
                    Console.WriteLine("You haven\'t any section. Create new (y/n)?");
                    if (Console.ReadKey(true).KeyChar == 'y')
                    {
                        shop.Add();
                    }
                }
            }
        }
Пример #4
0
        IMixable IMixable.Mix(IMixable lessImportant)
        {
            if (!(lessImportant is Margin))
            {
                throw new Exception("Cannot mix different types.");
            }

            Margin margin = new Margin();

            Margin lessImportantMargin = (Margin)lessImportant;

            margin._top    = _top ?? lessImportantMargin._top;
            margin._bottom = _bottom ?? lessImportantMargin._bottom;
            margin._left   = _left ?? lessImportantMargin._left;
            margin._right  = _right ?? lessImportantMargin._right;

            return(margin);
        }
Пример #5
0
 static void DoAction(IMixable obj, int act)
 {
     if (act == 1)
     {
         obj.Add();
     }
     else if (act == 2)
     {
         obj.Remove();
     }
     else if (act == 3)
     {
         obj.Update();
     }
     else if (act == 4)
     {
         obj.Show();
     }
 }
Пример #6
0
 public ThemeDirtyEventArgs(ThemeCategory category, ThemePart part, IMixable loadable = null)
 {
     Loadable = loadable;
     Category = category;
     Part     = part;
 }