Пример #1
0
        public static ValueBase Create(DefType theType, Variables runtime, ExpBase exp)
        {
            ValueBase variable;

            switch (theType)
            {
            case DefType.Int: variable = new ValueTyped <int>()
            {
                    Value = ((ExpTyped <int>)exp).Compute(runtime)
            }; break;

            case DefType.String: variable = new ValueTyped <string>()
            {
                    Value = exp.RunAsString(runtime)
            }; break;

            case DefType.Float: variable = new ValueTyped <float>()
            {
                    Value = exp.RunAsFloat(runtime)
            }; break;

            case DefType.Bool: variable = new ValueTyped <bool>()
            {
                    Value = ((ExpTyped <bool>)exp).Compute(runtime)
            }; break;

            case DefType.Void:
                throw new Exception("Can't create a variable of type void.");

            default:
                throw new Exception("Unknown variable type.");
            }

            return(variable);
        }
Пример #2
0
        public static ValueBase Create(DefType theType)
        {
            ValueBase variable;

            switch (theType)
            {
            case DefType.Int: variable = new ValueTyped <int>(); break;

            case DefType.String: variable = new ValueTyped <string>(); break;

            case DefType.Float: variable = new ValueTyped <float>(); break;

            case DefType.Bool: variable = new ValueTyped <bool>(); break;

            case DefType.Void:
                throw new Exception("Can't create a variable of type void.");

            default:
                throw new Exception("Unknown variable type.");
            }

            return(variable);
        }