Example #1
0
        public object EvaluateValues(ExecContext context)
        {
            bool   isNum       = valueType.CanStoreValue(context, IntrinsicTypeDefs.NUMBER);
            double nextInteger = 0;
            bool   isString    = valueType.CanStoreValue(context, IntrinsicTypeDefs.STRING);

            for (int ii = 0; ii < _values.Count; ++ii)
            {
                ClassValue_Enum val = (ClassValue_Enum)_classDef.Allocate(context);
                val.Get(mrName).value          = _values[ii].name;
                _classDef.staticVars[ii].value = val;

                if (null == _values[ii].initializer)
                {
                    if (isNum)
                    {
                        // If number, use next consecutive integer.
                        val.Get(mrValue).value = nextInteger;
                        nextInteger            = Math.Floor(nextInteger + 1);
                    }
                    else if (isString)
                    {
                        // If string, just use name.
                        val.Get(mrValue).value = _values[ii].name;
                    }
                    else
                    {
                        // Use the default value.
                        val.Get(mrValue).value = valueType.GetDefaultValue(context);
                    }
                }
                else
                {
                    object init = _values[ii].initializer.Evaluate(context);
                    if (context.IsRuntimeErrorSet())
                    {
                        return(null);
                    }
                    val.Get(mrValue).value = init;

                    if (isNum)
                    {
                        nextInteger = Math.Floor((double)init + 1);
                    }
                }
            }

            return(false);
        }