Esempio n. 1
0
 public void WriteNamespace(INamespace namespaceDeclaration)
 {
     if (_injectXmlDoc)
     {
         // inject XML documentation into generated namespace
         string nsStr = GetNamespaceAsString(namespaceDeclaration);
         _formatter.Write(nsStr);
     }
     else
     {
         // write it as the original implementor does it
         _writer.WriteNamespace(namespaceDeclaration);
     }
 }
Esempio n. 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);
        }
Esempio n. 3
0
        // get the original text from the LanguageWriter
        private string GetItemAsString(object item, int indent)
        {
            TextFormatter   formatter = new TextFormatter();
            ILanguageWriter writer    = _language.GetWriter(formatter, _configuration);

            for (int i = 0; i < indent; i++)
            {
                formatter.WriteIndent();
            }

            if (item is INamespace)
            {
                writer.WriteNamespace(item as INamespace);
            }
            if (item is ITypeDeclaration)
            {
                writer.WriteTypeDeclaration(item as ITypeDeclaration);
            }
            if (item is IEventDeclaration)
            {
                writer.WriteEventDeclaration(item as IEventDeclaration);
            }
            if (item is IFieldDeclaration)
            {
                writer.WriteFieldDeclaration(item as IFieldDeclaration);
            }
            if (item is IMethodDeclaration)
            {
                writer.WriteMethodDeclaration(item as IMethodDeclaration);
            }
            if (item is IPropertyDeclaration)
            {
                writer.WritePropertyDeclaration(item as IPropertyDeclaration);
            }

            return(formatter.ToString());
        }
        public string Decompile(int languageIndex, object o)
        {
            if (o == null)
            {
                return(String.Empty);
            }

            IFormatter      formatter  = CreateFormatter(this.LanguageManager.Languages[languageIndex].Name);
            ILanguageWriter writer     = this.LanguageManager.Languages[languageIndex].GetWriter(formatter, _langurageWriterConfiguration);
            ITranslator     translator = this.TranslatorManager.CreateDisassembler(null, null);

            if (o is IMethodDeclaration)
            {
                IMethodDeclaration m2;
                if (IsIL(languageIndex))
                {
                    m2 = (IMethodDeclaration)o;
                }
                else
                {
                    m2 = translator.TranslateMethodDeclaration((IMethodDeclaration)o);
                }
                writer.WriteMethodDeclaration(m2);
            }
            else if (o is IPropertyDeclaration)
            {
                IPropertyDeclaration p2 = translator.TranslatePropertyDeclaration((IPropertyDeclaration)o);
                writer.WritePropertyDeclaration(p2);
            }
            else if (o is IFieldDeclaration)
            {
                IFieldDeclaration f2 = translator.TranslateFieldDeclaration((IFieldDeclaration)o);
                writer.WriteFieldDeclaration(f2);
            }
            else if (o is ITypeDeclaration)
            {
                ITypeDeclaration t2 = translator.TranslateTypeDeclaration((ITypeDeclaration)o, true, false);
                writer.WriteTypeDeclaration(t2);
            }
            else if (o is IEventDeclaration)
            {
                IEventDeclaration e2 = translator.TranslateEventDeclaration((IEventDeclaration)o);
                writer.WriteEventDeclaration(e2);
            }
            else if (o is IModule)
            {
                IModule m2 = translator.TranslateModule((IModule)o, true);
                writer.WriteModule(m2);
            }
            else if (o is IModuleReference)
            {
                IModuleReference mr2 = translator.TranslateModuleReference((IModuleReference)o);
                writer.WriteModuleReference(mr2);
            }
            else if (o is IAssembly)
            {
                IAssembly a2 = translator.TranslateAssembly((IAssembly)o, true);
                writer.WriteAssembly(a2);
            }
            else if (o is IAssemblyReference)
            {
                IAssemblyReference ar2 = translator.TranslateAssemblyReference((IAssemblyReference)o);
                writer.WriteAssemblyReference(ar2);
            }
            else if (o is IResource)
            {
                writer.WriteResource((IResource)o);
            }
            else if (o is INamespace)
            {
                writer.WriteNamespace((INamespace)o);
            }

            return(formatter.ToString());
        }