示例#1
0
        public void OverloadOperator(Operator.Name toOverload, string externalFuncName)
        {
            Function overload = (Function)Find(externalFuncName, AccessMode.EXTERNAL);

            if (overload == null)
            {
                throw new NotFoundException("No such function \"" + externalFuncName + "\" in object");
            }

            if (overload.GetParameter("this") == null)
            {
                throw new InvalidOperationException("Overload function as to be member function (with \"this\" parameter)");
            }

            Operator.Type opType = Operator.GetTypeOf(toOverload);

            if (opType == Operator.Type.UNARY && overload.GetParameter("this").Type != this)
            {
                throw new InvalidOperatorSignature("Unary operator must have 1 parameter named`\"Operand\" of type " + this.ToString());
            }

            if (opType == Operator.Type.BINARY && (overload.GetParameter("this").Type != this || overload.GetParameter(Operator.Right) == null))
            {
                throw new InvalidOperatorSignature("Binary operator must have 2 parameters named \"LeftOperand\" (of type " + this.ToString() + ") and \"RightOperand\"");
            }

            if (overload.GetReturn(Operator.Result) == null)
            {
                throw new InvalidOperatorSignature("Operator must have \"result\" return value");
            }

            overloadedOperators[toOverload] = overload;
        }
示例#2
0
 private dynamic CallOperator(Operator.Name tocall, dynamic lOp, dynamic rOp)
 {
     return(CallOperator(tocall, new Dictionary <string, dynamic>
     {
         { "this", lOp },
         { Operator.Right, rOp }
     })[Operator.Result]);
 }
示例#3
0
 private Dictionary <string, dynamic> CallOperator(Operator.Name tocall, Dictionary <string, dynamic> parameters)
 {
     if (!overloadedOperators.ContainsKey(tocall))
     {
         throw new OperatorNotOverloaded();
     }
     return(overloadedOperators[tocall].Call(parameters));
 }