public object HandleUnaryOperation(string Operator, object Operand, operatortypeconstants optype) { //throw new NotImplementedException(); Object resultvalue; if (useOverloadedUnaryOperator(Operand, Operator, out resultvalue)) { return(resultvalue); } switch (Operator.ToUpper()) { case "-": if (typeof(System.Double) == Operand.GetType()) { return(-(double)Operand); } else if (typeof(System.String) == Operand.GetType()) { return(((String)Operand).Reverse()); } break; case "!": return(factorial(Convert.ToInt32(Operand))); } return(null); }
public string getHandledOperators(operatortypeconstants requesttype) { StringBuilder buildreturn = new StringBuilder(); if ((requesttype & operatortypeconstants.operator_binary) == operatortypeconstants.operator_binary) { buildreturn.Append(HandledOperatorString); } if ((requesttype & operatortypeconstants.operator_unary_prefix) == operatortypeconstants.operator_unary_prefix) { buildreturn.Append(" " + HandledPrefixOps); } if ((requesttype & operatortypeconstants.operator_unary_postfix) == operatortypeconstants.operator_unary_postfix) { buildreturn.Append(" " + HandledPostfixOps); } return(buildreturn.ToString()); }
public int CanHandleOperator(string Operator, out operatortypeconstants optype) { bool isassignment = false; //determine if it is a assignment expression. if (Operator == "=") { isassignment = true; optype = operatortypeconstants.operator_binary; //all assignments are binary return(int.MaxValue / 2); //really low precedence. } int binaryops = HandledOperatorString.IndexOf(" " + Operator + " ") + 1; int prefixops = HandledPrefixOps.IndexOf(" " + Operator + " ") + 1; int postfixops = HandledPostfixOps.IndexOf(" " + Operator + " ") + 1; int ret = 0; optype = operatortypeconstants.operator_binary; if (binaryops != 0) { optype = operatortypeconstants.operator_binary; ret = binaryops; } if (prefixops != 0) { optype = (operatortypeconstants)(((int)optype) & (int)(operatortypeconstants.operator_unary_prefix)); ret += prefixops; } if (postfixops != 0) { optype = (operatortypeconstants)(((int)optype) & (int)(operatortypeconstants.operator_unary_postfix)); ret += postfixops; } //return +1; so that -1 (not found) becomes 0 and everything else becomes positive. 0 is not found, anything else represents a priority //of the operator. (lower means higher priority) return(ret); }
public object HandleUnaryOperation(string Operator, object Operand, operatortypeconstants optype) { return(null); }
public string getHandledOperators(operatortypeconstants requesttype) { return(""); }
public int CanHandleOperator(string Operator, out operatortypeconstants opconstants) { opconstants = operatortypeconstants.operator_binary; return(0); }