PageRenderTime 16ms CodeModel.GetById 10ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/ILSpy/DecompilationOptions.cs

http://github.com/icsharpcode/ILSpy
C# | 108 lines | 46 code | 12 blank | 50 comment | 2 complexity | b60fd4d61e8bc7db6f48d926ad3a8c3c MD5 | raw file
  1// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
  2// 
  3// Permission is hereby granted, free of charge, to any person obtaining a copy of this
  4// software and associated documentation files (the "Software"), to deal in the Software
  5// without restriction, including without limitation the rights to use, copy, modify, merge,
  6// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
  7// to whom the Software is furnished to do so, subject to the following conditions:
  8// 
  9// The above copyright notice and this permission notice shall be included in all copies or
 10// substantial portions of the Software.
 11// 
 12// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
 13// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 14// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
 15// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 16// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 17// DEALINGS IN THE SOFTWARE.
 18
 19using System;
 20using System.Threading;
 21using ICSharpCode.ILSpy.Options;
 22
 23namespace ICSharpCode.ILSpy
 24{
 25	/// <summary>
 26	/// Options passed to the decompiler.
 27	/// </summary>
 28	public class DecompilationOptions
 29	{
 30		/// <summary>
 31		/// Gets whether a full decompilation (all members recursively) is desired.
 32		/// If this option is false, language bindings are allowed to show the only headers of the decompiled element's children.
 33		/// </summary>
 34		public bool FullDecompilation { get; set; }
 35		
 36		/// <summary>
 37		/// Gets/Sets the directory into which the project is saved.
 38		/// </summary>
 39		public string SaveAsProjectDirectory { get; set; }
 40
 41		/// <summary>
 42		/// Gets/sets whether invalid identifiers should be escaped (and therefore the code be made compilable).
 43		/// This setting is ignored in case <see cref="SaveAsProjectDirectory"/> is set.
 44		/// </summary>
 45		public bool EscapeInvalidIdentifiers { get; set; }
 46		
 47		/// <summary>
 48		/// Gets the cancellation token that is used to abort the decompiler.
 49		/// </summary>
 50		/// <remarks>
 51		/// Decompilers should regularly call <c>options.CancellationToken.ThrowIfCancellationRequested();</c>
 52		/// to allow for cooperative cancellation of the decompilation task.
 53		/// </remarks>
 54		public CancellationToken CancellationToken { get; set; }
 55		
 56		/// <summary>
 57		/// Gets the settings for the decompiler.
 58		/// </summary>
 59		public Decompiler.DecompilerSettings DecompilerSettings { get; private set; }
 60
 61		/// <summary>
 62		/// Gets/sets an optional state of a decompiler text view.
 63		/// </summary>
 64		/// <remarks>
 65		/// This state is used to restore test view's state when decompilation is started by Go Back/Forward action.
 66		/// </remarks>
 67		public TextView.DecompilerTextViewState TextViewState { get; set; }
 68
 69		/// <summary>
 70		/// Used internally for debugging.
 71		/// </summary>
 72		internal int StepLimit = int.MaxValue;
 73		internal bool IsDebug = false;
 74
 75		public DecompilationOptions()
 76			: this(MainWindow.Instance.CurrentLanguageVersion, DecompilerSettingsPanel.CurrentDecompilerSettings, DisplaySettingsPanel.CurrentDisplaySettings)
 77		{
 78		}
 79
 80		public DecompilationOptions(LanguageVersion version)
 81			: this(version, DecompilerSettingsPanel.CurrentDecompilerSettings, DisplaySettingsPanel.CurrentDisplaySettings)
 82		{
 83		}
 84
 85		public DecompilationOptions(LanguageVersion version, Decompiler.DecompilerSettings settings, Options.DisplaySettings displaySettings)
 86		{
 87			if (!Enum.TryParse(version?.Version, out Decompiler.CSharp.LanguageVersion languageVersion)) 
 88				languageVersion = Decompiler.CSharp.LanguageVersion.Latest;
 89			var newSettings = this.DecompilerSettings = settings.Clone();
 90			newSettings.SetLanguageVersion(languageVersion);
 91			newSettings.ExpandMemberDefinitions = displaySettings.ExpandMemberDefinitions;
 92			newSettings.ExpandUsingDeclarations = displaySettings.ExpandUsingDeclarations;
 93			newSettings.FoldBraces = displaySettings.FoldBraces;
 94			newSettings.ShowDebugInfo = displaySettings.ShowDebugInfo;
 95			newSettings.CSharpFormattingOptions.IndentationString = GetIndentationString(displaySettings);
 96		}
 97
 98		private string GetIndentationString(DisplaySettings displaySettings)
 99		{
100			if (displaySettings.IndentationUseTabs) {
101				int numberOfTabs = displaySettings.IndentationSize / displaySettings.IndentationTabSize;
102				int numberOfSpaces = displaySettings.IndentationSize % displaySettings.IndentationTabSize;
103				return new string('\t', numberOfTabs) + new string(' ', numberOfSpaces);
104			}
105			return new string(' ', displaySettings.IndentationSize);
106		}
107	}
108}