Example #1
0
        //Nastavení hodnoty pomocí řetězce.
        public void Set(string valueString)
        {
            IngredientValue i = ParseValue(valueString);

            this.pType  = i.pType;
            this.pValue = i.pValue;
        }
Example #2
0
        // Odečtení hodnoty pomocí řetězce.
        public void Sub(string valueString)
        {
            IngredientValue i = ParseValue(valueString);

            if (i.Type != this.Type)
            {
                throw new Exception(String.Format("Can not subtract unit of type {0} from unit of type {1}!", i.Type, this.Type));
            }
            else
            {
                this.pValue -= i.Value;
            }
        }
Example #3
0
        // Přičtení hodnoty pomocí řetězce.
        public void Add(string valueString)
        {
            IngredientValue i = ParseValue(valueString);

            if (i.Type != this.Type)
            {
                throw new Exception(String.Format("Can not add unit of type {0} to unit of type {1}!", i.Type, this.Type));
            }
            else
            {
                this.pValue += i.Value;
            }
        }
Example #4
0
        // Přetížení operátoru na přičítání - verze s objektem:
        public static IngredientValue operator +(IngredientValue a, IngredientValue b)
        {
            if ((object)a == null || (object)b == null)
            {
                if ((object)a == null)
                {
                    return(b);
                }
                return(a);
            }

            IngredientValue i = new IngredientValue(a.Get());

            i.Add(b.Get());
            return(i);
        }
Example #5
0
        // Přetížení operátoru na odečítání - verze s objektem:
        public static IngredientValue operator -(IngredientValue a, IngredientValue b)
        {
            if ((object)a == null || (object)b == null)
            {
                if ((object)a == null)
                {
                    IngredientValue i = new IngredientValue(b.Value * -1, b.Type);
                    return(b);
                }
                return(a);
            }

            IngredientValue j = new IngredientValue(a.Get());

            j.Sub(b.Get());
            return(j);
        }