コード例 #1
0
ファイル: CodeHelper.cs プロジェクト: kameronbrooks/UnityCCL
        public void FindVariables(string code)
        {
            _variables.Clear();
            _code = code;
            int index = 0;

            while (!IsEOF(index))
            {
                bool isArray = false;

                CullOther(ref index);
                string ident1 = ParseIdentifier(ref index);

                if (assembly.IsTypeName(ident1))
                {
                    CullWhitespace(ref index);
                    if (IsEOF(index))
                    {
                        return;
                    }
                    if (_code[index] == '.' || _code[index] == ')')
                    {
                        continue;
                    }
                    if (_code[index] == '[')
                    {
                        isArray = true;
                        CullOther(ref index);
                    }

                    string ident2 = ParseIdentifier(ref index);
                    if (ident2 == "")
                    {
                        continue;
                    }
                    Core.TypeDef typeDef = assembly.GetTypeDef(ident1);
                    System.Type  t       = (isArray) ? Array.CreateInstance(typeDef.type, 0).GetType() : typeDef.type;

                    if (!IsEOF(index) && _code[index] == '(')
                    {
                        t = typeof(Func <>).MakeGenericType(t);
                    }

                    _variables.Add(ident2, t);

                    CullStatement(ref index);
                }
            }
        }