コード例 #1
0
        public Linker(IAssembly assembly)
        {
            if (assembly == null)
            {
                throw new ArgumentNullException("assembly");
            }

            var data = assembly.CustomData();

            if (data.Linker != null)
            {
                throw new InvalidOperationException();
            }

            data.Linker = this;

            Assembly = assembly;

            // we should always listen TypeLoaded event to fill AssemblyLinked
            if (Assembly.Loader != null)
            {
                Assembly.Loader.TypeLoaded += OnTypeLoaded;
            }

            var resource = Assembly.MainModule.Resources.FirstOrDefault(
                x => x.Name.EndsWith(".abc", StringComparison.OrdinalIgnoreCase) ||
                x.Name.EndsWith(".swc", StringComparison.OrdinalIgnoreCase));

            if (resource != null)
            {
                data.Flags |= InternalAssembyFlags.HasAbcImports;

                if (resource.Name.EndsWith(".abc", StringComparison.OrdinalIgnoreCase))
                {
                    _abc = new AbcFile(resource.Data)
                    {
                        Assembly = Assembly
                    };
                    data.Abc = _abc;
                    _cache   = new AbcCache();
                    _cache.Add(_abc);
                }
                else if (resource.Name.EndsWith(".swc", StringComparison.OrdinalIgnoreCase))
                {
                    string swcName = GetResFileName(resource.Name);

                    _swcDeps = LoadSwcDep(swcName);
                    _swc     = new SwcFile(resource.Data)
                    {
                        Assembly = Assembly,
                        Name     = swcName
                    };
                    _cache = _swc.AbcCache;

                    data.SWC = _swc;
                }
            }

            // create all linkers to subscribe on AssemblyLoader.TypeLoaded event before we start process
            assembly.ProcessReferences(true,
                                       asm =>
            {
                if (asm.CustomData().Linker == null)
                {
                    asm.CustomData().Linker = new Linker(asm);
                }
            });

            if (_swc != null)
            {
                _swc.ResolveDependencies(this, _swcDeps);
            }
        }