Example #1
0
        private void ImportScriptAssembly(MetadataSource mdSource, string assemblyPath, bool coreAssembly)
        {
            string scriptNamespace = null;
            string scriptName      = null;

            AssemblyDefinition assembly;

            if (coreAssembly)
            {
                assembly = mdSource.CoreAssemblyMetadata;
            }
            else
            {
                assembly        = mdSource.GetMetadata(assemblyPath);
                scriptNamespace = MetadataHelpers.GetScriptNamespace(assembly);
            }

            scriptName = MetadataHelpers.GetScriptAssemblyName(assembly);
            if (String.IsNullOrEmpty(scriptName) == false)
            {
                _options.AddReferencedDependency(scriptName);
            }

            if (coreAssembly)
            {
                // Always add an execution reference to the core assembly, since
                // it contains things like the type system, and other APIs assumed by the compiler
                Debug.Assert(String.IsNullOrEmpty(scriptName) == false);
                _options.AddExecutionDependency(scriptName);
            }

            foreach (TypeDefinition type in assembly.MainModule.Types)
            {
                try {
                    if (MetadataHelpers.IsCompilerGeneratedType(type))
                    {
                        continue;
                    }

                    ImportType(mdSource, type, coreAssembly, scriptNamespace, scriptName);
                }
                catch (Exception e) {
                    Debug.Fail(e.ToString());
                }
            }
        }