Пример #1
0
        public Variable GetProperty(string propName, ParsingScript script = null)
        {
            Variable result = Variable.EmptyInstance;

            int ind = propName.IndexOf('.');

            if (ind > 0)
            { // The case x = a.b.c ... is dealt here recursively
                string   varName        = propName.Substring(0, ind);
                string   actualPropName = propName.Substring(ind + 1);
                Variable property       = GetProperty(varName, script);
                result = string.IsNullOrEmpty(actualPropName) ? property :
                         property.GetProperty(actualPropName, script);
                return(result);
            }

            if (Object is ScriptObject)
            {
                ScriptObject obj   = Object as ScriptObject;
                string       match = GetActualPropertyName(propName, obj.GetProperties());
                if (!string.IsNullOrWhiteSpace(match))
                {
                    List <Variable> args = null;
                    if (script != null &&
                        (script.Pointer == 0 || script.Prev == Constants.START_ARG))
                    {
                        args = script.GetFunctionArgs();
                    }
                    else if (script != null)
                    {
                        args = new List <Variable>();
                    }
                    var task = obj.GetProperty(match, args, script);
                    result = task != null ? task.Result : null;
                    if (result != null)
                    {
                        return(result);
                    }
                }
            }

            return(GetCoreProperty(propName, script));
        }
Пример #2
0
        public Variable GetEnumProperty(string propName, ParsingScript script, string baseName = "")
        {
            propName = Constants.ConvertName(propName);
            if (script.Prev == Constants.START_ARG)
            {
                Variable value = Utils.GetItem(script);
                if (propName == Constants.TO_STRING)
                {
                    return(ConvertEnumToString(value));
                }
                else
                {
                    return(new Variable(m_enumMap != null && m_enumMap.ContainsKey(value.AsInt())));
                }
            }

            string[] tokens = propName.Split('.');
            if (tokens.Length > 1)
            {
                propName = tokens[0];
            }

            string match = GetActualPropertyName(propName, GetAllProperties(), baseName, this);

            Variable result = GetCoreProperty(match, script);

            if (tokens.Length > 1)
            {
                result = ConvertEnumToString(result);
                if (tokens.Length > 2)
                {
                    string rest = string.Join(".", tokens, 2, tokens.Length - 2);
                    result = result.GetProperty(rest, script);
                }
            }

            return(result);
        }