Beispiel #1
0
        public static Property LoadRight(string value, ref string typeName)
        {
            Property opr = null;

            if (!string.IsNullOrEmpty(value))
            {
                if (value.StartsWith("const"))
                {
                    //const Int32 0
                    const int kConstLength = 5;
                    string    strRemaining = value.Substring(kConstLength + 1);
                    int       p            = StringUtils.FirstToken(strRemaining, ' ', ref typeName);

                    typeName = typeName.Replace("::", ".");

                    string strVale = strRemaining.Substring(p + 1);
                    opr = Property.Create(typeName, strVale);
                }
                else
                {
                    opr = ParseProperty(value, ref typeName);
                }
            }

            return(opr);
        }
Beispiel #2
0
        public static Property LoadRight(string value, string propertyName, ref string typeName)
        {
            Property property = null;

            if (string.IsNullOrEmpty(value))
            {
                return(property);
            }
            if (value.StartsWith("const"))
            {
                string str  = value.Substring(6);
                int    num2 = StringUtils.FirstToken(str, ' ', ref typeName);
                typeName = typeName.Replace("::", ".");
                string str2 = str.Substring(num2 + 1);
                return(Property.Create(typeName, propertyName, str2, false, true));
            }
            char[]   separator = new char[] { ' ' };
            string[] strArray  = value.Split(separator);
            if (strArray[0] == "static")
            {
                typeName = strArray[1].Replace("::", ".");
                return(Property.Create(typeName, strArray[2], null, true, false));
            }
            typeName = strArray[0].Replace("::", ".");
            return(Property.Create(typeName, strArray[1], null, false, false));
        }
Beispiel #3
0
        public static Property LoadRight(string value, string propertyName, ref string typeName)
        {
            Property result = null;

            if (!string.IsNullOrEmpty(value))
            {
                if (value.StartsWith("const"))
                {
                    string text = value.Substring(6);
                    int    num  = StringUtils.FirstToken(text, ' ', ref typeName);
                    typeName = typeName.Replace("::", ".");
                    string value2 = text.Substring(num + 1);
                    result = Property.Create(typeName, propertyName, value2, false, true);
                }
                else
                {
                    string[] array = value.Split(new char[]
                    {
                        ' '
                    });
                    if (array[0] == "static")
                    {
                        typeName = array[1].Replace("::", ".");
                        result   = Property.Create(typeName, array[2], null, true, false);
                    }
                    else
                    {
                        typeName = array[0].Replace("::", ".");
                        result   = Property.Create(typeName, array[1], null, false, false);
                    }
                }
            }
            return(result);
        }
Beispiel #4
0
        public static Property LoadRight(string value, string propertyName, ref string typeName)
        {
            Property opr = null;

            if (!string.IsNullOrEmpty(value))
            {
                if (value.StartsWith("const"))
                {
                    //const Int32 0
                    const int kConstLength = 5;
                    string    strRemaining = value.Substring(kConstLength + 1);
                    int       p            = StringUtils.FirstToken(strRemaining, ' ', ref typeName);

                    typeName = typeName.Replace("::", ".");

                    string strVale = strRemaining.Substring(p + 1);
                    opr = Property.Create(typeName, propertyName, strVale, false, true);
                }
                else
                {
                    string[] tokens = value.Split(' ');

                    if (tokens[0] == "static")
                    {
                        //static int Property1
                        Debug.Check(tokens.Length == 3);
                        typeName = tokens[1].Replace("::", ".");
                        opr      = Property.Create(typeName, tokens[2], null, true, false);
                    }
                    else
                    {
                        //int Property1
                        Debug.Check(tokens.Length == 2);
                        typeName = tokens[0].Replace("::", ".");
                        opr      = Property.Create(typeName, tokens[1], null, false, false);
                    }
                }
            }

            return(opr);
        }
Beispiel #5
0
        public static IInstanceMember ParseProperty(string value)
        {
            try
            {
                if (string.IsNullOrEmpty(value))
                {
                    return(null);
                }

                List <string> tokens   = StringUtils.SplitTokens(value);
                string        typeName = "";

                if (tokens[0] == "const")
                {
                    // const Int32 0
                    Debug.Check(tokens.Count == 3);

                    const int kConstLength = 5;
                    string    strRemaining = value.Substring(kConstLength + 1);
                    int       p            = StringUtils.FirstToken(strRemaining, ' ', ref typeName);

                    typeName = typeName.Replace("::", ".");

                    string strVale = strRemaining.Substring(p + 1);

                    // const
                    return(AgentMeta.CreateInstanceConst(typeName, strVale));
                }
                else
                {
                    string propStr      = "";
                    string indexPropStr = "";

                    if (tokens[0] == "static")
                    {
                        // static float Self.AgentNodeTest::s_float_type_0
                        // static float Self.AgentNodeTest::s_float_type_0[int Self.AgentNodeTest::par_int_type_2]
                        Debug.Check(tokens.Count == 3 || tokens.Count == 4);

                        typeName = tokens[1];
                        propStr  = tokens[2];
                        if (tokens.Count == 4) // array index
                        {
                            indexPropStr = tokens[3];
                        }
                    }
                    else
                    {
                        // float Self.AgentNodeTest::par_float_type_1
                        // float Self.AgentNodeTest::par_float_type_1[int Self.AgentNodeTest::par_int_type_2]
                        Debug.Check(tokens.Count == 2 || tokens.Count == 3);

                        typeName = tokens[0];
                        propStr  = tokens[1];
                        if (tokens.Count == 3) // array index
                        {
                            indexPropStr = tokens[2];
                        }
                    }

                    string          arrayItem   = "";
                    IInstanceMember indexMember = null;
                    if (!string.IsNullOrEmpty(indexPropStr))
                    {
                        arrayItem   = "[]";
                        indexMember = ParseProperty <int>(indexPropStr);
                    }

                    typeName = typeName.Replace("::", ".");
                    propStr  = propStr.Replace("::", ".");

                    string[] props = propStr.Split('.');
                    Debug.Check(props.Length >= 3);

                    string instantceName = props[0];
                    string propName      = props[props.Length - 1];
                    string className     = props[1];

                    for (int i = 2; i < props.Length - 1; ++i)
                    {
                        className += "." + props[i];
                    }

                    uint      classId = Utils.MakeVariableId(className);
                    AgentMeta meta    = AgentMeta.GetMeta(classId);
                    Debug.Check(meta != null, "please add the exported 'AgentProperties.cs' and 'customizedtypes.cs' into the project!");

                    uint propId = Utils.MakeVariableId(propName + arrayItem);

                    // property
                    IProperty p = meta.GetProperty(propId);
                    if (p != null)
                    {
                        return(p.CreateInstance(instantceName, indexMember));
                    }

                    // local var
                    return(AgentMeta.CreateInstanceProperty(typeName, instantceName, indexMember, propId));
                }
            }
            catch (System.Exception e)
            {
                Debug.Check(false, e.Message);
            }

            return(null);
        }