Exemplo n.º 1
0
    private SD_NameSpace InitializeGlobalNamespace()
    {
        //	var timer = new Stopwatch();
        //	timer.Start();

        _globalNamespace = new SD_NameSpace {
            name = "", kind = SymbolKind.Namespace, parentSymbol = this
        };

        if (assembly != null)
        {
            var types = assemblyId != UnityAssembly.None ? assembly.GetTypes() : assembly.GetExportedTypes();
            foreach (var t in types)
            {
                if (t.IsNested)
                {
                    continue;
                }

                SymbolDefinition current = _globalNamespace;

                if (!string.IsNullOrEmpty(t.Namespace))
                {
                    var ns = t.Namespace.Split('.');
                    for (var i = 0; i < ns.Length; ++i)
                    {
                        var nsName     = ns[i];
                        var definition = current.FindName(nsName, 0, true);
                        if (definition != null)
                        {
                            current = definition;
                        }
                        else
                        {
                            var nsd = new SD_NameSpace
                            {
                                kind         = SymbolKind.Namespace,
                                name         = nsName,
                                parentSymbol = current,
                                accessLevel  = AccessLevel.Public,
                                modifiers    = Modifiers.Public,
                            };
                            current.AddMember(nsd);
                            current = nsd;
                        }
                    }
                }

                current.ImportReflectedType(t);
            }
        }

        //	timer.Stop();
        //	UnityEngine.Debug.Log(timer.ElapsedMilliseconds + " ms\n" + string.Join(", ", _globalNamespace.members.Keys.ToArray()));
        //	Debug.Log(_globalNamespace.Dump());

        if (builtInTypes == null)
        {
            builtInTypes = new Dictionary <string, TypeDefinitionBase>
            {
                { "int", builtInTypes_int = DefineBuiltInType(typeof(int)) },
                { "uint", builtInTypes_uint = DefineBuiltInType(typeof(uint)) },
                { "byte", builtInTypes_byte = DefineBuiltInType(typeof(byte)) },
                { "sbyte", builtInTypes_sbyte = DefineBuiltInType(typeof(sbyte)) },
                { "short", builtInTypes_short = DefineBuiltInType(typeof(short)) },
                { "ushort", builtInTypes_ushort = DefineBuiltInType(typeof(ushort)) },
                { "long", builtInTypes_long = DefineBuiltInType(typeof(long)) },
                { "ulong", builtInTypes_ulong = DefineBuiltInType(typeof(ulong)) },
                { "float", builtInTypes_float = DefineBuiltInType(typeof(float)) },
                { "double", builtInTypes_double = DefineBuiltInType(typeof(float)) },
                { "decimal", builtInTypes_decimal = DefineBuiltInType(typeof(decimal)) },
                { "char", builtInTypes_char = DefineBuiltInType(typeof(char)) },
                { "string", builtInTypes_string = DefineBuiltInType(typeof(string)) },
                { "bool", builtInTypes_bool = DefineBuiltInType(typeof(bool)) },
                { "object", builtInTypes_object = DefineBuiltInType(typeof(object)) },
                { "void", builtInTypes_void = DefineBuiltInType(typeof(void)) },
            };

            builtInTypes_Array         = DefineBuiltInType(typeof(System.Array));
            builtInTypes_Nullable      = DefineBuiltInType(typeof(System.Nullable <>));
            builtInTypes_IEnumerable   = DefineBuiltInType(typeof(System.Collections.IEnumerable));
            builtInTypes_IEnumerable_1 = DefineBuiltInType(typeof(System.Collections.Generic.IEnumerable <>));
            builtInTypes_Exception     = DefineBuiltInType(typeof(System.Exception));
        }

        return(_globalNamespace);
    }