public object Convert(object value, Type targetType, object parameter, string language)
        {
            //validate
            if (value == null)
            {
                return(DefaultReturn);
            }

            //get string
            var str = value as string;

            if (value.GetType().IsPrimitive || value.GetType().IsEnum)
            {
                str = value.ToString();
            }

            //select return value
            if (str == null)
            {
                return(DefaultReturn);
            }
            if (If1 != null && If1.Split(',').Contains(str))
            {
                return(Return1);
            }
            if (If2 != null && If2.Split(',').Contains(value))
            {
                return(Return2);
            }
            if (If3 != null && If3.Split(',').Contains(value))
            {
                return(Return3);
            }
            if (If4 != null && If4.Split(',').Contains(value))
            {
                return(Return4);
            }
            if (If5 != null && If5.Split(',').Contains(value))
            {
                return(Return5);
            }
            if (If6 != null && If6.Split(',').Contains(value))
            {
                return(Return6);
            }
            if (If7 != null && If7.Split(',').Contains(value))
            {
                return(Return7);
            }
            if (If8 != null && If8.Split(',').Contains(value))
            {
                return(Return8);
            }
            if (If9 != null && If9.Split(',').Contains(value))
            {
                return(Return9);
            }
            if (If10 != null && If10.Split(',').Contains(value))
            {
                return(Return10);
            }
            return(DefaultReturn);
        }
示例#2
0
    //This function actually creates the object associated with each Instruction by using a long switch statement. The object
    //created is polymorphed up to an IInstruction and then returned from the function to be stored in the encodedInstrs list.
    //Ugly? Very. Effective? Extremely.
    private IInstruction createObject(string comm, int valToUse, int currentInstruc)
    {
        IInstruction retVal = null;

        switch (comm)
        {
        case "exit":
            retVal = new Exit(valToUse) as IInstruction;
            break;

        case "swap":
            retVal = new Swap() as IInstruction;
            break;

        case "inpt":
            retVal = new Inpt() as IInstruction;
            break;

        case "nop":
            retVal = new Nop() as IInstruction;
            break;

        case "pop":
            retVal = new Pop() as IInstruction;
            break;

        case "add":
            retVal = new Add() as IInstruction;
            break;

        case "sub":
            retVal = new Sub() as IInstruction;
            break;

        case "mul":
            retVal = new Mul() as IInstruction;
            break;

        case "div":
            retVal = new Div() as IInstruction;
            break;

        case "rem":
            retVal = new Rem() as IInstruction;
            break;

        case "and":
            retVal = new And() as IInstruction;
            break;

        case "or":
            retVal = new Or() as IInstruction;
            break;

        case "xor":
            retVal = new Xor() as IInstruction;
            break;

        case "neg":
            retVal = new Neg() as IInstruction;
            break;

        case "not":
            retVal = new Not() as IInstruction;
            break;

        case "goto":
            retVal = new Goto(valToUse) as IInstruction;
            break;

        case "ifeq":
            retVal = new If1(0, valToUse, currentInstruc) as IInstruction;
            break;

        case "ifne":
            retVal = new If1(1, valToUse, currentInstruc) as IInstruction;
            break;

        case "iflt":
            retVal = new If1(2, valToUse, currentInstruc) as IInstruction;
            break;

        case "ifgt":
            retVal = new If1(3, valToUse, currentInstruc) as IInstruction;
            break;

        case "ifle":
            retVal = new If1(4, valToUse, currentInstruc) as IInstruction;
            break;

        case "ifge":
            retVal = new If1(5, valToUse, currentInstruc) as IInstruction;
            break;

        case "ifez":
            retVal = new If2(0, valToUse, currentInstruc) as IInstruction;
            break;

        case "ifnz":
            retVal = new If2(1, valToUse, currentInstruc) as IInstruction;
            break;

        case "ifmi":
            retVal = new If2(2, valToUse, currentInstruc) as IInstruction;
            break;

        case "ifpl":
            retVal = new If2(3, valToUse, currentInstruc) as IInstruction;
            break;

        case "dup":
            retVal = new Dup(valToUse) as IInstruction;
            break;

        case "print":
            retVal = new Print() as IInstruction;
            break;

        case "dump":
            retVal = new Dump() as IInstruction;
            break;

        case "push":
            retVal = new Push(valToUse) as IInstruction;
            break;
        }
        return(retVal);
    }