ICSharpCode.ILSpy.LoadedAssembly.DisableAssemblyLoad C# (CSharp) Method

DisableAssemblyLoad() public static method

public static DisableAssemblyLoad ( ) : IDisposable
return IDisposable
		public static IDisposable DisableAssemblyLoad()
		{
			assemblyLoadDisableCount++;
			return new DecrementAssemblyLoadDisableCount();
		}
		

Usage Example

Beispiel #1
0
        public override void DecompileAssembly(LoadedAssembly assembly, ITextOutput output, DecompilationOptions options)
        {
            if (options.FullDecompilation && options.SaveAsProjectDirectory != null)
            {
                //Checks if must create a solution
                if (options.CreateSolution)
                {
                    //Solution directory
                    var solutionDir = options.SaveAsProjectDirectory;

                    //List of the project names and their guid
                    List <Tuple <string, string> > projects = new List <Tuple <string, string> >();

                    //For each module
                    foreach (var module in assembly.AssemblyDefinition.Modules)
                    {
                        //Creates the project and the various files
                        var projectDir = Path.Combine(solutionDir, TextView.DecompilerTextView.CleanUpName(Path.GetFileNameWithoutExtension(module.Name)));
                        Directory.CreateDirectory(projectDir);
                        options.SaveAsProjectDirectory = projectDir;
                        HashSet <string> directories = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
                        var files = WriteCodeFilesInProject(module, options, directories).ToList();
                        files.AddRange(WriteResourceFilesInProject(module, options, directories));
                        using (var writer = new StreamWriter(Path.Combine(projectDir, Path.GetFileName(projectDir) + this.ProjectFileExtension), false, System.Text.Encoding.UTF8))
                            projects.Add(Tuple.Create(
                                             Path.GetFileName(projectDir),
                                             "{" + WriteProjectFile(writer, files, module, options).ToString().ToUpperInvariant() + "}"
                                             ));
                    }

                    //Writes the solution
                    WriteSolutionFile(new TextOutputWriter(output), Enumerable.Reverse(projects));
                }
                else
                {
                    HashSet <string> directories = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
                    var files = assembly.AssemblyDefinition.Modules.SelectMany(m => WriteCodeFilesInProject(m, options, directories)).ToList();
                    files.AddRange(assembly.AssemblyDefinition.Modules.SelectMany(m => WriteResourceFilesInProject(m, options, directories)));
                    WriteProjectFile(new TextOutputWriter(output), files, assembly.AssemblyDefinition.MainModule, options);
                }
            }
            else
            {
                base.DecompileAssembly(assembly, output, options);
                output.WriteLine();
                output.WriteLine("// Main module:");
                ModuleDefinition mainModule = assembly.AssemblyDefinition.MainModule;
                WriteModuleAttributes(mainModule, output, options);
                output.WriteLine();

                // don't automatically load additional assemblies when an assembly node is selected in the tree view
                using (options.FullDecompilation ? null : LoadedAssembly.DisableAssemblyLoad()) {
                    AstBuilder codeDomBuilder = CreateAstBuilder(options, currentModule: assembly.AssemblyDefinition.MainModule);
                    codeDomBuilder.AddAssembly(assembly.AssemblyDefinition, onlyAssemblyLevel: !options.FullDecompilation);
                    codeDomBuilder.RunTransformations(transformAbortCondition);
                    codeDomBuilder.GenerateCode(output);
                }
            }
            OnDecompilationFinished(null);
        }
All Usage Examples Of ICSharpCode.ILSpy.LoadedAssembly::DisableAssemblyLoad