public static bool TryCreateMultiplication(Quantity left, Quantity right, IReadOnlyList <Unit> allUnits, out OperatorOverload result)
        {
            var prod    = left.Unit.Parts * right.Unit.Parts;
            var product = allUnits.SingleOrDefault(u => u.Parts == prod)?.Quantity;

            if (product != null)
            {
                result = new OperatorOverload(left, Generator.Operator.Multiply, right, product);
                return(true);
            }

            result = null;
            return(false);
        }
        public static bool TryCreateDivision(Quantity left, Quantity right, IReadOnlyList <Unit> allUnits, out OperatorOverload result)
        {
            if (left == right)
            {
                result = null;
                return(false);
            }

            var div      = left.Unit.Parts / right.Unit.Parts;
            var division = allUnits.SingleOrDefault(u => u.Parts == div)?.Quantity;

            if (division != null)
            {
                result = new OperatorOverload(left, Generator.Operator.Divide, right, division);
                return(true);
            }

            result = null;
            return(false);
        }
Beispiel #3
0
 protected bool Equals(OperatorOverload other)
 {
     return(this.Left.Name.Equals(other.Left.Name) && this.Right.Name.Equals(other.Right.Name) && this.Result.Name.Equals(other.Result.Name) &&
            string.Equals(this.Operator, other.Operator));
 }