Пример #1
0
        private IDecompilationResults GetAssemblyAttributesDecompilationResults(string assemblyAttributesFilePath)
        {
            AvalonEditCodeFormatter formatter = new AvalonEditCodeFormatter(new StringWriter());

            IWriterSettings          settings             = new WriterSettings(writeExceptionsAsComments: true);
            IAssemblyAttributeWriter writer               = language.GetAssemblyAttributeWriter(formatter, this.exceptionFormater, settings);
            IWriterContextService    writerContextService = new TypeCollisionWriterContextService(new ProjectGenerationDecompilationCacheService(), decompilationPreferences.RenameInvalidMembers);

            string fileContent;

            try
            {
                writer.WriteAssemblyInfo(assembly, writerContextService, true,
                                         new string[1] {
                    "System.Runtime.Versioning.TargetFrameworkAttribute"
                }, new string[1] {
                    "System.Security.UnverifiableCodeAttribute"
                });

                fileContent = formatter.GetSourceCode().GetSourceCode();
            }
            catch (Exception e)
            {
                string[] exceptionMessageLines = exceptionFormater.Format(e, null, assemblyAttributesFilePath);
                fileContent = string.Join(Environment.NewLine, exceptionMessageLines);
            }

            using (StreamWriter outfile = new StreamWriter(assemblyAttributesFilePath))
            {
                outfile.Write(fileContent);
            }

            JustDecompile.EngineInfrastructure.ICodeViewerResults originalcodeViewerResults = formatter.GetSourceCode();

            if (!(originalcodeViewerResults is JustDecompile.EngineInfrastructure.DecompiledSourceCode))
            {
                throw new Exception("Unexpected code viewer results type.");
            }

            JustDecompile.EngineInfrastructure.DecompiledSourceCode decompiledSourceCode = originalcodeViewerResults as JustDecompile.EngineInfrastructure.DecompiledSourceCode;

            ICodeViewerResults codeViewerResults = new CodeViewerResults(decompiledSourceCode);

            return(new DecompilationResults(assemblyAttributesFilePath, codeViewerResults,
                                            new Dictionary <uint, IOffsetSpan>(), new Dictionary <uint, IOffsetSpan>(), new Dictionary <uint, IOffsetSpan>(), new Dictionary <uint, IOffsetSpan>(), new HashSet <uint>()));
        }
Пример #2
0
        protected override void RecordGeneratedFileData(TypeDefinition type, string sourceFilePath, StringWriter theWriter, IFormatter formatter, IWriterContextService writerContextService, List <WritingInfo> writingInfos)
        {
            lock (recordGeneratedFileDataLock)
            {
                if (!(formatter is AvalonEditCodeFormatter))
                {
                    throw new Exception("Unexpected formatter type.");
                }

                AvalonEditCodeFormatter languageCodeFormatter = formatter as AvalonEditCodeFormatter;

                JustDecompile.EngineInfrastructure.ICodeViewerResults originalcodeViewerResults = languageCodeFormatter.GetSourceCode();

                if (!(originalcodeViewerResults is JustDecompile.EngineInfrastructure.DecompiledSourceCode))
                {
                    throw new Exception("Unexpected code viewer results type.");
                }

                JustDecompile.EngineInfrastructure.DecompiledSourceCode decompiledSourceCode = originalcodeViewerResults as JustDecompile.EngineInfrastructure.DecompiledSourceCode;

                ICodeViewerResults             codeViewerResults = new CodeViewerResults(decompiledSourceCode);
                Dictionary <uint, IOffsetSpan> memberDeclarationToCodePostionMap = GetMemberDeclarationToCodePostionMap(writingInfos);
                Dictionary <uint, IOffsetSpan> memberTokenToDocumentationMap     = GetMemberTokenToDocumentationMap(writingInfos);
                Dictionary <uint, IOffsetSpan> memberTokenToAttributesMap        = GetMemberTokenToAttributesMap(writingInfos);
                Dictionary <uint, IOffsetSpan> memberTokenToDecompiledCodeMap    = GetMemberTokenToDecompiledCodeMap(writingInfos);
                ICollection <uint>             membersWithExceptions             = GetMembersWithExceptions(writingInfos);

                IDecompilationResults typeDecompilationResults = new DecompilationResults(sourceFilePath, codeViewerResults, memberDeclarationToCodePostionMap,
                                                                                          memberTokenToDocumentationMap, memberTokenToAttributesMap, memberTokenToDecompiledCodeMap, membersWithExceptions);

                uint moduleToken = type.Module.MetadataToken.ToUInt32();
                if (!this.decompilationResults.ContainsKey(moduleToken))
                {
                    this.decompilationResults.Add(moduleToken, new Dictionary <uint, IDecompilationResults>());
                }

                Dictionary <uint, IDecompilationResults> moduleTypes = this.decompilationResults[moduleToken];
                moduleTypes.Add(type.MetadataToken.ToUInt32(), typeDecompilationResults);
            }
        }