コード例 #1
0
        private int WriteAssemblyInfo(IAssembly assembly, ILanguageWriterConfiguration configuration)
        {
            ILanguage   language   = LanguageManager.ActiveLanguage;
            ITranslator translator = TranslatorManager.CreateDisassembler("Xml", null);

            int exceptions = 0;

            using (StreamWriter streamWriter = CreateFile(string.Empty, "AssemblyInfo"))
            {
                TextFormatter formatter = new TextFormatter();
                try
                {
                    ILanguageWriter writer = language.GetWriter(formatter, configuration);
                    assembly = translator.TranslateAssembly(assembly, false);
                    writer.WriteAssembly(assembly);

                    foreach (IModule module in assembly.Modules)
                    {
                        IModule visitedModule = translator.TranslateModule(module, false);
                        writer.WriteModule(visitedModule);

                        foreach (IAssemblyReference assemblyReference in module.AssemblyReferences)
                        {
                            IAssemblyReference visitedAssemblyReference = translator.TranslateAssemblyReference(assemblyReference);
                            writer.WriteAssemblyReference(visitedAssemblyReference);
                        }

                        foreach (IModuleReference moduleReference in module.ModuleReferences)
                        {
                            IModuleReference visitedModuleReference = translator.TranslateModuleReference(moduleReference);
                            writer.WriteModuleReference(visitedModuleReference);
                        }
                    }

                    foreach (IResource resource in assembly.Resources)
                    {
                        writer.WriteResource(resource);
                    }
                }
                catch (Exception exception)
                {
                    streamWriter.WriteLine(exception.ToString());
                    WriteLine(exception.ToString());
                    exceptions++;
                }

                string output = formatter.ToString().Replace("\r\n", "\n").Replace("\n", "\r\n");
                streamWriter.WriteLine(output);
            }
            return(exceptions);
        }
コード例 #2
0
        private int WriteTypeDeclaration(ITypeDeclaration typeDeclaration, ILanguageWriterConfiguration configuration)
        {
            ILanguage   language   = LanguageManager.ActiveLanguage;
            ITranslator translator = TranslatorManager.CreateDisassembler("Xml", null);

            int exceptions = 0;

            using (StreamWriter streamWriter = CreateTypeDeclarationFile(typeDeclaration))
            {
                INamespace namespaceItem = new Namespace();
                namespaceItem.Name = typeDeclaration.Namespace;

                try
                {
                    if (language.Translate)
                    {
                        typeDeclaration = translator.TranslateTypeDeclaration(typeDeclaration, true, true);
                    }
                    namespaceItem.Types.Add(typeDeclaration);
                }
                catch (Exception ex)
                {
                    streamWriter.WriteLine(ex.ToString());
                    WriteLine(ex.ToString());
                    exceptions++;
                }

                TextFormatter   formatter = new TextFormatter();
                ILanguageWriter writer    = language.GetWriter(formatter, configuration);
                try
                {
                    writer.WriteNamespace(namespaceItem);
                }
                catch (Exception exception)
                {
                    streamWriter.WriteLine(exception.ToString());
                    WriteLine(exception.ToString());
                }

                string output = formatter.ToString().Replace("\r\n", "\n").Replace("\n", "\r\n");
                streamWriter.WriteLine(output);
            }

            return(exceptions);
        }