Example #1
0
        private RewriterResults RewriteImpl()
        {
            if (!this.options.Rewrite)
            {
                return(RewriterResults.Warning("Not asked to rewrite"));
            }

            if (!this.options.Assembly.IsSet)
            {
                return(RewriterResults.Error("No assembly given to rewrite"));
            }

            var readerParameters = new ReaderParameters();

            if (options.Debug)
            {
                readerParameters.ReadSymbols = true;
            }

            var assembly = this.options.Assembly.IsFilename ?
                           AssemblyDefinition.ReadAssembly(options.Assembly.Filename, readerParameters) :
                           AssemblyDefinition.ReadAssembly(options.Assembly.Streams.Assembly, readerParameters);

            if (this.options.ForceAssemblyRename != null)
            {
                assembly.Name.Name = this.options.ForceAssemblyRename;
            }
            else if (this.options.OutputFile.IsSet && this.options.OutputFile.IsFilename)
            {
                assembly.Name.Name = Path.GetFileNameWithoutExtension(this.options.OutputFile.Filename);
            }

            var output           = this.options.OutputFile.IsSet ? this.options.OutputFile : this.options.Assembly;
            var writerParameters = new WriterParameters();

            if (options.WritePdbFile)
            {
                if (!options.Debug)
                {
                    return(RewriterResults.Error("Must specify -debug if using -writePDBFile."));
                }

                writerParameters.WriteSymbols = true;
            }

            PerformRewrite rewriter = new PerformRewrite(this.options);

            rewriter.Rewrite(assembly);

            if (output.IsFilename)
            {
                assembly.Write(output.Filename, writerParameters);
            }
            else
            {
                assembly.Write(output.Streams.Assembly, writerParameters);
            }

            return(new RewriterResults(warnings, errors));
        }
Example #2
0
		private RewriterResults RewriteImpl ()
		{
			if (!this.options.Rewrite) {
				return RewriterResults.Warning ("Not asked to rewrite");
			}

			if (!this.options.Assembly.IsSet) {
				return RewriterResults.Error ("No assembly given to rewrite");
			}
			AssemblyDefinition assembly = this.options.Assembly.IsFilename ?
				AssemblyFactory.GetAssembly (this.options.Assembly.Filename) :
				AssemblyFactory.GetAssembly (this.options.Assembly.Streams.Assembly);
			
			if (this.options.ForceAssemblyRename != null) {
				assembly.Name.Name = this.options.ForceAssemblyRename;
			} else if (this.options.OutputFile.IsSet && this.options.OutputFile.IsFilename) {
				assembly.Name.Name = Path.GetFileNameWithoutExtension(this.options.OutputFile.Filename);
			}

			if (options.Debug) {
				this.LoadSymbolReader (assembly);
			}

			var output = this.options.OutputFile.IsSet ? this.options.OutputFile : this.options.Assembly;
			ISymbolWriter symWriter = null;
			if (options.WritePdbFile) {
				if (!options.Debug) {
					return RewriterResults.Error ("Must specify -debug if using -writePDBFile.");
				}
				if (output.IsStream && output.Streams.Symbols==null){
					return RewriterResults.Error ("-writePDFFile specified, but no output symbol stream provided.");
				}
				symWriter = this.LoadSymbolWriter (assembly, output);
			}
			
			try {
				PerformRewrite rewriter = new PerformRewrite (symWriter, this.options);
				rewriter.Rewrite (assembly);

				if (output.IsFilename) {
					AssemblyFactory.SaveAssembly(assembly, output.Filename);
				} else {
					AssemblyFactory.SaveAssembly(assembly, output.Streams.Assembly);
				}
			} finally {
				if (symWriter != null) {
					symWriter.Dispose ();
				}
			}

			return new RewriterResults (warnings, errors);
		}
Example #3
0
		private RewriterResults RewriteImpl ()
		{
			if (!this.options.Rewrite) {
				return RewriterResults.Warning ("Not asked to rewrite");
			}

			if (!this.options.Assembly.IsSet) {
				return RewriterResults.Error ("No assembly given to rewrite");
			}

			var readerParameters = new ReaderParameters ();

			if (options.Debug)
				readerParameters.ReadSymbols = true;

			var assembly = this.options.Assembly.IsFilename ?
				AssemblyDefinition.ReadAssembly (options.Assembly.Filename, readerParameters) :
				AssemblyDefinition.ReadAssembly (options.Assembly.Streams.Assembly, readerParameters);
			
			if (this.options.ForceAssemblyRename != null) {
				assembly.Name.Name = this.options.ForceAssemblyRename;
			} else if (this.options.OutputFile.IsSet && this.options.OutputFile.IsFilename) {
				assembly.Name.Name = Path.GetFileNameWithoutExtension(this.options.OutputFile.Filename);
			}

			var output = this.options.OutputFile.IsSet ? this.options.OutputFile : this.options.Assembly;
			var writerParameters = new WriterParameters ();
			if (options.WritePdbFile) {
				if (!options.Debug) {
					return RewriterResults.Error ("Must specify -debug if using -writePDBFile.");
				}
				
				writerParameters.WriteSymbols = true;
			}
			
			PerformRewrite rewriter = new PerformRewrite (this.options);
			rewriter.Rewrite (assembly);

			if (output.IsFilename) {
				assembly.Write (output.Filename, writerParameters);
			} else {
				assembly.Write (output.Streams.Assembly, writerParameters);
			}
		
			return new RewriterResults (warnings, errors);
		}