コード例 #1
0
        public static IInstanceMember ParseProperty <T>(string value)
        {
            try
            {
                if (string.IsNullOrEmpty(value))
                {
                    return(null);
                }

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

                // const
                if (tokens.Count == 1)
                {
                    string typeName = Utils.GetNativeTypeName(typeof(T));

                    return(AgentMeta.CreateInstanceConst(typeName, value));
                }

                return(ParseProperty(value));
            }
            catch (System.Exception e)
            {
                Debug.Check(false, e.Message);
            }

            return(null);
        }
コード例 #2
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);
        }