Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
 public override void SetValue(Variables runtime, ExpBase exp)
 {
     if (typeof(TType) == typeof(int))
     {
         (this as ValueTyped <int>).Value = ((ExpTyped <int>)exp).Compute(runtime);
     }
     else if (typeof(TType) == typeof(float))
     {
         (this as ValueTyped <float>).Value = exp.RunAsFloat(runtime);
     }
     else if (typeof(TType) == typeof(string))
     {
         (this as ValueTyped <string>).Value = exp.RunAsString(runtime);
     }
     else if (typeof(TType) == typeof(bool))
     {
         (this as ValueTyped <bool>).Value = ((ExpTyped <bool>)exp).Compute(runtime);
     }
     else
     {
         throw new Exception("Unknown variable type.");
     }
 }