You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1832 lines
46 KiB

5 years ago
  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. using System;
  19. using System.ComponentModel;
  20. using System.Runtime.CompilerServices;
  21. using ICSharpCode.Decompiler.CSharp.OutputVisitor;
  22. namespace ICSharpCode.Decompiler
  23. {
  24. /// <summary>
  25. /// Settings for the decompiler.
  26. /// </summary>
  27. public class DecompilerSettings : INotifyPropertyChanged
  28. {
  29. /// <summary>
  30. /// Equivalent to <c>new DecompilerSettings(LanguageVersion.Latest)</c>
  31. /// </summary>
  32. public DecompilerSettings()
  33. {
  34. }
  35. /// <summary>
  36. /// Creates a new DecompilerSettings instance with initial settings
  37. /// appropriate for the specified language version.
  38. /// </summary>
  39. /// <remarks>
  40. /// This does not imply that the resulting code strictly uses only language features from
  41. /// that version. Language constructs like generics or ref locals cannot be removed from
  42. /// the compiled code.
  43. /// </remarks>
  44. public DecompilerSettings(CSharp.LanguageVersion languageVersion)
  45. {
  46. SetLanguageVersion(languageVersion);
  47. }
  48. /// <summary>
  49. /// Deactivates all language features from versions newer than <paramref name="languageVersion"/>.
  50. /// </summary>
  51. public void SetLanguageVersion(CSharp.LanguageVersion languageVersion)
  52. {
  53. // By default, all decompiler features are enabled.
  54. // Disable some of them based on language version:
  55. if (languageVersion < CSharp.LanguageVersion.CSharp2)
  56. {
  57. anonymousMethods = false;
  58. liftNullables = false;
  59. yieldReturn = false;
  60. useImplicitMethodGroupConversion = false;
  61. }
  62. if (languageVersion < CSharp.LanguageVersion.CSharp3)
  63. {
  64. anonymousTypes = false;
  65. useLambdaSyntax = false;
  66. objectCollectionInitializers = false;
  67. automaticProperties = false;
  68. extensionMethods = false;
  69. queryExpressions = false;
  70. expressionTrees = false;
  71. }
  72. if (languageVersion < CSharp.LanguageVersion.CSharp4)
  73. {
  74. dynamic = false;
  75. namedArguments = false;
  76. optionalArguments = false;
  77. }
  78. if (languageVersion < CSharp.LanguageVersion.CSharp5)
  79. {
  80. asyncAwait = false;
  81. }
  82. if (languageVersion < CSharp.LanguageVersion.CSharp6)
  83. {
  84. awaitInCatchFinally = false;
  85. useExpressionBodyForCalculatedGetterOnlyProperties = false;
  86. nullPropagation = false;
  87. stringInterpolation = false;
  88. dictionaryInitializers = false;
  89. extensionMethodsInCollectionInitializers = false;
  90. useRefLocalsForAccurateOrderOfEvaluation = false;
  91. getterOnlyAutomaticProperties = false;
  92. }
  93. if (languageVersion < CSharp.LanguageVersion.CSharp7)
  94. {
  95. outVariables = false;
  96. throwExpressions = false;
  97. tupleTypes = false;
  98. tupleConversions = false;
  99. discards = false;
  100. localFunctions = false;
  101. deconstruction = false;
  102. patternMatching = false;
  103. }
  104. if (languageVersion < CSharp.LanguageVersion.CSharp7_2)
  105. {
  106. introduceReadonlyAndInModifiers = false;
  107. introduceRefModifiersOnStructs = false;
  108. nonTrailingNamedArguments = false;
  109. refExtensionMethods = false;
  110. }
  111. if (languageVersion < CSharp.LanguageVersion.CSharp7_3)
  112. {
  113. introduceUnmanagedConstraint = false;
  114. stackAllocInitializers = false;
  115. tupleComparisons = false;
  116. patternBasedFixedStatement = false;
  117. }
  118. if (languageVersion < CSharp.LanguageVersion.CSharp8_0)
  119. {
  120. nullableReferenceTypes = false;
  121. readOnlyMethods = false;
  122. asyncUsingAndForEachStatement = false;
  123. asyncEnumerator = false;
  124. useEnhancedUsing = false;
  125. staticLocalFunctions = false;
  126. ranges = false;
  127. switchExpressions = false;
  128. }
  129. if (languageVersion < CSharp.LanguageVersion.Preview)
  130. {
  131. nativeIntegers = false;
  132. initAccessors = false;
  133. functionPointers = false;
  134. forEachWithGetEnumeratorExtension = false;
  135. recordClasses = false;
  136. withExpressions = false;
  137. usePrimaryConstructorSyntax = false;
  138. }
  139. }
  140. public CSharp.LanguageVersion GetMinimumRequiredVersion()
  141. {
  142. if (nativeIntegers || initAccessors || functionPointers || forEachWithGetEnumeratorExtension || recordClasses)
  143. return CSharp.LanguageVersion.Preview;
  144. if (nullableReferenceTypes || readOnlyMethods || asyncEnumerator || asyncUsingAndForEachStatement
  145. || staticLocalFunctions || ranges || switchExpressions)
  146. return CSharp.LanguageVersion.CSharp8_0;
  147. if (introduceUnmanagedConstraint || tupleComparisons || stackAllocInitializers
  148. || patternBasedFixedStatement)
  149. return CSharp.LanguageVersion.CSharp7_3;
  150. if (introduceRefModifiersOnStructs || introduceReadonlyAndInModifiers
  151. || nonTrailingNamedArguments || refExtensionMethods)
  152. return CSharp.LanguageVersion.CSharp7_2;
  153. // C# 7.1 missing
  154. if (outVariables || throwExpressions || tupleTypes || tupleConversions
  155. || discards || localFunctions || deconstruction || patternMatching)
  156. return CSharp.LanguageVersion.CSharp7;
  157. if (awaitInCatchFinally || useExpressionBodyForCalculatedGetterOnlyProperties || nullPropagation
  158. || stringInterpolation || dictionaryInitializers || extensionMethodsInCollectionInitializers
  159. || useRefLocalsForAccurateOrderOfEvaluation || getterOnlyAutomaticProperties)
  160. return CSharp.LanguageVersion.CSharp6;
  161. if (asyncAwait)
  162. return CSharp.LanguageVersion.CSharp5;
  163. if (dynamic || namedArguments || optionalArguments)
  164. return CSharp.LanguageVersion.CSharp4;
  165. if (anonymousTypes || objectCollectionInitializers || automaticProperties
  166. || queryExpressions || expressionTrees)
  167. return CSharp.LanguageVersion.CSharp3;
  168. if (anonymousMethods || liftNullables || yieldReturn || useImplicitMethodGroupConversion)
  169. return CSharp.LanguageVersion.CSharp2;
  170. return CSharp.LanguageVersion.CSharp1;
  171. }
  172. bool nativeIntegers = true;
  173. /// <summary>
  174. /// Use C# 9 <c>nint</c>/<c>nuint</c> types.
  175. /// </summary>
  176. [Category("C# 9.0 / VS 2019.8")]
  177. [Description("DecompilerSettings.NativeIntegers")]
  178. public bool NativeIntegers {
  179. get { return nativeIntegers; }
  180. set {
  181. if (nativeIntegers != value)
  182. {
  183. nativeIntegers = value;
  184. OnPropertyChanged();
  185. }
  186. }
  187. }
  188. bool initAccessors = true;
  189. /// <summary>
  190. /// Use C# 9 <c>init;</c> property accessors.
  191. /// </summary>
  192. [Category("C# 9.0 / VS 2019.8")]
  193. [Description("DecompilerSettings.InitAccessors")]
  194. public bool InitAccessors {
  195. get { return initAccessors; }
  196. set {
  197. if (initAccessors != value)
  198. {
  199. initAccessors = value;
  200. OnPropertyChanged();
  201. }
  202. }
  203. }
  204. bool recordClasses = true;
  205. /// <summary>
  206. /// Use C# 9 <c>record</c> classes.
  207. /// </summary>
  208. [Category("C# 9.0 / VS 2019.8")]
  209. [Description("DecompilerSettings.RecordClasses")]
  210. public bool RecordClasses {
  211. get { return recordClasses; }
  212. set {
  213. if (recordClasses != value)
  214. {
  215. recordClasses = value;
  216. OnPropertyChanged();
  217. }
  218. }
  219. }
  220. bool withExpressions = true;
  221. /// <summary>
  222. /// Use C# 9 <c>with</c> initializer expressions.
  223. /// </summary>
  224. [Category("C# 9.0 / VS 2019.8")]
  225. [Description("DecompilerSettings.WithExpressions")]
  226. public bool WithExpressions {
  227. get { return withExpressions; }
  228. set {
  229. if (withExpressions != value)
  230. {
  231. withExpressions = value;
  232. OnPropertyChanged();
  233. }
  234. }
  235. }
  236. bool usePrimaryConstructorSyntax = true;
  237. /// <summary>
  238. /// Use primary constructor syntax with records.
  239. /// </summary>
  240. [Category("C# 9.0 / VS 2019.8")]
  241. [Description("DecompilerSettings.UsePrimaryConstructorSyntax")]
  242. public bool UsePrimaryConstructorSyntax {
  243. get { return usePrimaryConstructorSyntax; }
  244. set {
  245. if (usePrimaryConstructorSyntax != value)
  246. {
  247. usePrimaryConstructorSyntax = value;
  248. OnPropertyChanged();
  249. }
  250. }
  251. }
  252. bool functionPointers = true;
  253. /// <summary>
  254. /// Use C# 9 <c>delegate* unmanaged</c> types.
  255. /// If this option is disabled, function pointers will instead be decompiled with type `IntPtr`.
  256. /// </summary>
  257. [Category("C# 9.0 / VS 2019.8")]
  258. [Description("DecompilerSettings.FunctionPointers")]
  259. public bool FunctionPointers {
  260. get { return functionPointers; }
  261. set {
  262. if (functionPointers != value)
  263. {
  264. functionPointers = value;
  265. OnPropertyChanged();
  266. }
  267. }
  268. }
  269. bool switchExpressions = true;
  270. /// <summary>
  271. /// Use C# 8 switch expressions.
  272. /// </summary>
  273. [Category("C# 8.0 / VS 2019")]
  274. [Description("DecompilerSettings.SwitchExpressions")]
  275. public bool SwitchExpressions {
  276. get { return switchExpressions; }
  277. set {
  278. if (switchExpressions != value)
  279. {
  280. switchExpressions = value;
  281. OnPropertyChanged();
  282. }
  283. }
  284. }
  285. bool anonymousMethods = true;
  286. /// <summary>
  287. /// Decompile anonymous methods/lambdas.
  288. /// </summary>
  289. [Category("C# 2.0 / VS 2005")]
  290. [Description("DecompilerSettings.DecompileAnonymousMethodsLambdas")]
  291. public bool AnonymousMethods {
  292. get { return anonymousMethods; }
  293. set {
  294. if (anonymousMethods != value)
  295. {
  296. anonymousMethods = value;
  297. OnPropertyChanged();
  298. }
  299. }
  300. }
  301. bool anonymousTypes = true;
  302. /// <summary>
  303. /// Decompile anonymous types.
  304. /// </summary>
  305. [Category("C# 3.0 / VS 2008")]
  306. [Description("DecompilerSettings.DecompileAnonymousTypes")]
  307. public bool AnonymousTypes {
  308. get { return anonymousTypes; }
  309. set {
  310. if (anonymousTypes != value)
  311. {
  312. anonymousTypes = value;
  313. OnPropertyChanged();
  314. }
  315. }
  316. }
  317. bool useLambdaSyntax = true;
  318. /// <summary>
  319. /// Use C# 3 lambda syntax if possible.
  320. /// </summary>
  321. [Category("C# 3.0 / VS 2008")]
  322. [Description("DecompilerSettings.UseLambdaSyntaxIfPossible")]
  323. public bool UseLambdaSyntax {
  324. get { return useLambdaSyntax; }
  325. set {
  326. if (useLambdaSyntax != value)
  327. {
  328. useLambdaSyntax = value;
  329. OnPropertyChanged();
  330. }
  331. }
  332. }
  333. bool expressionTrees = true;
  334. /// <summary>
  335. /// Decompile expression trees.
  336. /// </summary>
  337. [Category("C# 3.0 / VS 2008")]
  338. [Description("DecompilerSettings.DecompileExpressionTrees")]
  339. public bool ExpressionTrees {
  340. get { return expressionTrees; }
  341. set {
  342. if (expressionTrees != value)
  343. {
  344. expressionTrees = value;
  345. OnPropertyChanged();
  346. }
  347. }
  348. }
  349. bool yieldReturn = true;
  350. /// <summary>
  351. /// Decompile enumerators.
  352. /// </summary>
  353. [Category("C# 2.0 / VS 2005")]
  354. [Description("DecompilerSettings.DecompileEnumeratorsYieldReturn")]
  355. public bool YieldReturn {
  356. get { return yieldReturn; }
  357. set {
  358. if (yieldReturn != value)
  359. {
  360. yieldReturn = value;
  361. OnPropertyChanged();
  362. }
  363. }
  364. }
  365. bool dynamic = true;
  366. /// <summary>
  367. /// Decompile use of the 'dynamic' type.
  368. /// </summary>
  369. [Category("C# 4.0 / VS 2010")]
  370. [Description("DecompilerSettings.DecompileUseOfTheDynamicType")]
  371. public bool Dynamic {
  372. get { return dynamic; }
  373. set {
  374. if (dynamic != value)
  375. {
  376. dynamic = value;
  377. OnPropertyChanged();
  378. }
  379. }
  380. }
  381. bool asyncAwait = true;
  382. /// <summary>
  383. /// Decompile async methods.
  384. /// </summary>
  385. [Category("C# 5.0 / VS 2012")]
  386. [Description("DecompilerSettings.DecompileAsyncMethods")]
  387. public bool AsyncAwait {
  388. get { return asyncAwait; }
  389. set {
  390. if (asyncAwait != value)
  391. {
  392. asyncAwait = value;
  393. OnPropertyChanged();
  394. }
  395. }
  396. }
  397. bool awaitInCatchFinally = true;
  398. /// <summary>
  399. /// Decompile await in catch/finally blocks.
  400. /// Only has an effect if <see cref="AsyncAwait"/> is enabled.
  401. /// </summary>
  402. [Category("C# 6.0 / VS 2015")]
  403. [Description("DecompilerSettings.DecompileAwaitInCatchFinallyBlocks")]
  404. public bool AwaitInCatchFinally {
  405. get { return awaitInCatchFinally; }
  406. set {
  407. if (awaitInCatchFinally != value)
  408. {
  409. awaitInCatchFinally = value;
  410. OnPropertyChanged();
  411. }
  412. }
  413. }
  414. bool asyncEnumerator = true;
  415. /// <summary>
  416. /// Decompile IAsyncEnumerator/IAsyncEnumerable.
  417. /// Only has an effect if <see cref="AsyncAwait"/> is enabled.
  418. /// </summary>
  419. [Category("C# 8.0 / VS 2019")]
  420. [Description("DecompilerSettings.AsyncEnumerator")]
  421. public bool AsyncEnumerator {
  422. get { return asyncEnumerator; }
  423. set {
  424. if (asyncEnumerator != value)
  425. {
  426. asyncEnumerator = value;
  427. OnPropertyChanged();
  428. }
  429. }
  430. }
  431. bool decimalConstants = true;
  432. /// <summary>
  433. /// Decompile [DecimalConstant(...)] as simple literal values.
  434. /// </summary>
  435. [Category("C# 1.0 / VS .NET")]
  436. [Description("DecompilerSettings.DecompileDecimalConstantAsSimpleLiteralValues")]
  437. public bool DecimalConstants {
  438. get { return decimalConstants; }
  439. set {
  440. if (decimalConstants != value)
  441. {
  442. decimalConstants = value;
  443. OnPropertyChanged();
  444. }
  445. }
  446. }
  447. bool fixedBuffers = true;
  448. /// <summary>
  449. /// Decompile C# 1.0 'public unsafe fixed int arr[10];' members.
  450. /// </summary>
  451. [Category("C# 1.0 / VS .NET")]
  452. [Description("DecompilerSettings.DecompileC10PublicUnsafeFixedIntArr10Members")]
  453. public bool FixedBuffers {
  454. get { return fixedBuffers; }
  455. set {
  456. if (fixedBuffers != value)
  457. {
  458. fixedBuffers = value;
  459. OnPropertyChanged();
  460. }
  461. }
  462. }
  463. bool stringConcat = true;
  464. /// <summary>
  465. /// Decompile 'string.Concat(a, b)' calls into 'a + b'.
  466. /// </summary>
  467. [Category("C# 1.0 / VS .NET")]
  468. [Description("DecompilerSettings.StringConcat")]
  469. public bool StringConcat {
  470. get { return stringConcat; }
  471. set {
  472. if (stringConcat != value)
  473. {
  474. stringConcat = value;
  475. OnPropertyChanged();
  476. }
  477. }
  478. }
  479. bool liftNullables = true;
  480. /// <summary>
  481. /// Use lifted operators for nullables.
  482. /// </summary>
  483. [Category("C# 2.0 / VS 2005")]
  484. [Description("DecompilerSettings.UseLiftedOperatorsForNullables")]
  485. public bool LiftNullables {
  486. get { return liftNullables; }
  487. set {
  488. if (liftNullables != value)
  489. {
  490. liftNullables = value;
  491. OnPropertyChanged();
  492. }
  493. }
  494. }
  495. bool nullPropagation = true;
  496. /// <summary>
  497. /// Decompile C# 6 ?. and ?[] operators.
  498. /// </summary>
  499. [Category("C# 6.0 / VS 2015")]
  500. [Description("DecompilerSettings.NullPropagation")]
  501. public bool NullPropagation {
  502. get { return nullPropagation; }
  503. set {
  504. if (nullPropagation != value)
  505. {
  506. nullPropagation = value;
  507. OnPropertyChanged();
  508. }
  509. }
  510. }
  511. bool automaticProperties = true;
  512. /// <summary>
  513. /// Decompile automatic properties
  514. /// </summary>
  515. [Category("C# 3.0 / VS 2008")]
  516. [Description("DecompilerSettings.DecompileAutomaticProperties")]
  517. public bool AutomaticProperties {
  518. get { return automaticProperties; }
  519. set {
  520. if (automaticProperties != value)
  521. {
  522. automaticProperties = value;
  523. OnPropertyChanged();
  524. }
  525. }
  526. }
  527. bool getterOnlyAutomaticProperties = true;
  528. /// <summary>
  529. /// Decompile getter-only automatic properties
  530. /// </summary>
  531. [Category("C# 6.0 / VS 2015")]
  532. [Description("DecompilerSettings.GetterOnlyAutomaticProperties")]
  533. public bool GetterOnlyAutomaticProperties {
  534. get { return getterOnlyAutomaticProperties; }
  535. set {
  536. if (getterOnlyAutomaticProperties != value)
  537. {
  538. getterOnlyAutomaticProperties = value;
  539. OnPropertyChanged();
  540. }
  541. }
  542. }
  543. bool automaticEvents = true;
  544. /// <summary>
  545. /// Decompile automatic events
  546. /// </summary>
  547. [Category("C# 1.0 / VS .NET")]
  548. [Description("DecompilerSettings.DecompileAutomaticEvents")]
  549. public bool AutomaticEvents {
  550. get { return automaticEvents; }
  551. set {
  552. if (automaticEvents != value)
  553. {
  554. automaticEvents = value;
  555. OnPropertyChanged();
  556. }
  557. }
  558. }
  559. bool usingStatement = true;
  560. /// <summary>
  561. /// Decompile using statements.
  562. /// </summary>
  563. [Category("C# 1.0 / VS .NET")]
  564. [Description("DecompilerSettings.DetectUsingStatements")]
  565. public bool UsingStatement {
  566. get { return usingStatement; }
  567. set {
  568. if (usingStatement != value)
  569. {
  570. usingStatement = value;
  571. OnPropertyChanged();
  572. }
  573. }
  574. }
  575. bool useEnhancedUsing = true;
  576. /// <summary>
  577. /// Use enhanced using statements.
  578. /// </summary>
  579. [Category("C# 8.0 / VS 2019")]
  580. [Description("DecompilerSettings.UseEnhancedUsing")]
  581. public bool UseEnhancedUsing {
  582. get { return useEnhancedUsing; }
  583. set {
  584. if (useEnhancedUsing != value)
  585. {
  586. useEnhancedUsing = value;
  587. OnPropertyChanged();
  588. }
  589. }
  590. }
  591. bool alwaysUseBraces = true;
  592. /// <summary>
  593. /// Gets/Sets whether to use braces for single-statement-blocks.
  594. /// </summary>
  595. [Category("DecompilerSettings.Other")]
  596. [Description("DecompilerSettings.AlwaysUseBraces")]
  597. public bool AlwaysUseBraces {
  598. get { return alwaysUseBraces; }
  599. set {
  600. if (alwaysUseBraces != value)
  601. {
  602. alwaysUseBraces = value;
  603. OnPropertyChanged();
  604. }
  605. }
  606. }
  607. bool forEachStatement = true;
  608. /// <summary>
  609. /// Decompile foreach statements.
  610. /// </summary>
  611. [Category("C# 1.0 / VS .NET")]
  612. [Description("DecompilerSettings.DetectForeachStatements")]
  613. public bool ForEachStatement {
  614. get { return forEachStatement; }
  615. set {
  616. if (forEachStatement != value)
  617. {
  618. forEachStatement = value;
  619. OnPropertyChanged();
  620. }
  621. }
  622. }
  623. bool forEachWithGetEnumeratorExtension = true;
  624. /// <summary>
  625. /// Support GetEnumerator extension methods in foreach.
  626. /// </summary>
  627. [Category("C# 9.0 / VS 2019.8")]
  628. [Description("DecompilerSettings.DecompileForEachWithGetEnumeratorExtension")]
  629. public bool ForEachWithGetEnumeratorExtension {
  630. get { return forEachWithGetEnumeratorExtension; }
  631. set {
  632. if (forEachWithGetEnumeratorExtension != value)
  633. {
  634. forEachWithGetEnumeratorExtension = value;
  635. OnPropertyChanged();
  636. }
  637. }
  638. }
  639. bool lockStatement = true;
  640. /// <summary>
  641. /// Decompile lock statements.
  642. /// </summary>
  643. [Category("C# 1.0 / VS .NET")]
  644. [Description("DecompilerSettings.DetectLockStatements")]
  645. public bool LockStatement {
  646. get { return lockStatement; }
  647. set {
  648. if (lockStatement != value)
  649. {
  650. lockStatement = value;
  651. OnPropertyChanged();
  652. }
  653. }
  654. }
  655. bool switchStatementOnString = true;
  656. [Category("C# 1.0 / VS .NET")]
  657. [Description("DecompilerSettings.DetectSwitchOnString")]
  658. public bool SwitchStatementOnString {
  659. get { return switchStatementOnString; }
  660. set {
  661. if (switchStatementOnString != value)
  662. {
  663. switchStatementOnString = value;
  664. OnPropertyChanged();
  665. }
  666. }
  667. }
  668. bool sparseIntegerSwitch = true;
  669. [Category("C# 1.0 / VS .NET")]
  670. [Description("DecompilerSettings.SparseIntegerSwitch")]
  671. public bool SparseIntegerSwitch {
  672. get { return sparseIntegerSwitch; }
  673. set {
  674. if (sparseIntegerSwitch != value)
  675. {
  676. sparseIntegerSwitch = value;
  677. OnPropertyChanged();
  678. }
  679. }
  680. }
  681. bool usingDeclarations = true;
  682. [Category("C# 1.0 / VS .NET")]
  683. [Description("DecompilerSettings.InsertUsingDeclarations")]
  684. public bool UsingDeclarations {
  685. get { return usingDeclarations; }
  686. set {
  687. if (usingDeclarations != value)
  688. {
  689. usingDeclarations = value;
  690. OnPropertyChanged();
  691. }
  692. }
  693. }
  694. bool extensionMethods = true;
  695. [Category("C# 3.0 / VS 2008")]
  696. [Description("DecompilerSettings.UseExtensionMethodSyntax")]
  697. public bool ExtensionMethods {
  698. get { return extensionMethods; }
  699. set {
  700. if (extensionMethods != value)
  701. {
  702. extensionMethods = value;
  703. OnPropertyChanged();
  704. }
  705. }
  706. }
  707. bool queryExpressions = true;
  708. [Category("C# 3.0 / VS 2008")]
  709. [Description("DecompilerSettings.UseLINQExpressionSyntax")]
  710. public bool QueryExpressions {
  711. get { return queryExpressions; }
  712. set {
  713. if (queryExpressions != value)
  714. {
  715. queryExpressions = value;
  716. OnPropertyChanged();
  717. }
  718. }
  719. }
  720. bool useImplicitMethodGroupConversion = true;
  721. /// <summary>
  722. /// Gets/Sets whether to use C# 2.0 method group conversions.
  723. /// true: <c>EventHandler h = this.OnClick;</c>
  724. /// false: <c>EventHandler h = new EventHandler(this.OnClick);</c>
  725. /// </summary>
  726. [Category("C# 2.0 / VS 2005")]
  727. [Description("DecompilerSettings.UseImplicitMethodGroupConversions")]
  728. public bool UseImplicitMethodGroupConversion {
  729. get { return useImplicitMethodGroupConversion; }
  730. set {
  731. if (useImplicitMethodGroupConversion != value)
  732. {
  733. useImplicitMethodGroupConversion = value;
  734. OnPropertyChanged();
  735. }
  736. }
  737. }
  738. bool alwaysCastTargetsOfExplicitInterfaceImplementationCalls = false;
  739. /// <summary>
  740. /// Gets/Sets whether to always cast targets to explicitly implemented methods.
  741. /// true: <c>((ISupportInitialize)pictureBox1).BeginInit();</c>
  742. /// false: <c>pictureBox1.BeginInit();</c>
  743. /// default: false
  744. /// </summary>
  745. [Category("Other")]
  746. [Description("DecompilerSettings.AlwaysCastTargetsOfExplicitInterfaceImplementationCalls")]
  747. public bool AlwaysCastTargetsOfExplicitInterfaceImplementationCalls {
  748. get { return alwaysCastTargetsOfExplicitInterfaceImplementationCalls; }
  749. set {
  750. if (alwaysCastTargetsOfExplicitInterfaceImplementationCalls != value)
  751. {
  752. alwaysCastTargetsOfExplicitInterfaceImplementationCalls = value;
  753. OnPropertyChanged();
  754. }
  755. }
  756. }
  757. bool alwaysQualifyMemberReferences = false;
  758. /// <summary>
  759. /// Gets/Sets whether to always qualify member references.
  760. /// true: <c>this.DoSomething();</c>
  761. /// false: <c>DoSomething();</c>
  762. /// default: false
  763. /// </summary>
  764. [Category("Other")]
  765. [Description("DecompilerSettings.AlwaysQualifyMemberReferences")]
  766. public bool AlwaysQualifyMemberReferences {
  767. get { return alwaysQualifyMemberReferences; }
  768. set {
  769. if (alwaysQualifyMemberReferences != value)
  770. {
  771. alwaysQualifyMemberReferences = value;
  772. OnPropertyChanged();
  773. }
  774. }
  775. }
  776. bool alwaysShowEnumMemberValues = false;
  777. /// <summary>
  778. /// Gets/Sets whether to always show enum member values.
  779. /// true: <c>enum Kind { A = 0, B = 1, C = 5 }</c>
  780. /// false: <c>enum Kind { A, B, C = 5 }</c>
  781. /// default: false
  782. /// </summary>
  783. [Category("Other")]
  784. [Description("DecompilerSettings.AlwaysShowEnumMemberValues")]
  785. public bool AlwaysShowEnumMemberValues {
  786. get { return alwaysShowEnumMemberValues; }
  787. set {
  788. if (alwaysShowEnumMemberValues != value)
  789. {
  790. alwaysShowEnumMemberValues = value;
  791. OnPropertyChanged();
  792. }
  793. }
  794. }
  795. bool useDebugSymbols = true;
  796. /// <summary>
  797. /// Gets/Sets whether to use variable names from debug symbols, if available.
  798. /// </summary>
  799. [Category("Other")]
  800. [Description("DecompilerSettings.UseVariableNamesFromDebugSymbolsIfAvailable")]
  801. public bool UseDebugSymbols {
  802. get { return useDebugSymbols; }
  803. set {
  804. if (useDebugSymbols != value)
  805. {
  806. useDebugSymbols = value;
  807. OnPropertyChanged();
  808. }
  809. }
  810. }
  811. bool arrayInitializers = true;
  812. /// <summary>
  813. /// Gets/Sets whether to use array initializers.
  814. /// If set to false, might produce non-compilable code.
  815. /// </summary>
  816. [Category("C# 1.0 / VS .NET")]
  817. [Description("DecompilerSettings.ArrayInitializerExpressions")]
  818. public bool ArrayInitializers {
  819. get { return arrayInitializers; }
  820. set {
  821. if (arrayInitializers != value)
  822. {
  823. arrayInitializers = value;
  824. OnPropertyChanged();
  825. }
  826. }
  827. }
  828. bool objectCollectionInitializers = true;
  829. /// <summary>
  830. /// Gets/Sets whether to use C# 3.0 object/collection initializers.
  831. /// </summary>
  832. [Category("C# 3.0 / VS 2008")]
  833. [Description("DecompilerSettings.ObjectCollectionInitializerExpressions")]
  834. public bool ObjectOrCollectionInitializers {
  835. get { return objectCollectionInitializers; }
  836. set {
  837. if (objectCollectionInitializers != value)
  838. {
  839. objectCollectionInitializers = value;
  840. OnPropertyChanged();
  841. }
  842. }
  843. }
  844. bool dictionaryInitializers = true;
  845. /// <summary>
  846. /// Gets/Sets whether to use C# 6.0 dictionary initializers.
  847. /// Only has an effect if ObjectOrCollectionInitializers is enabled.
  848. /// </summary>
  849. [Category("C# 6.0 / VS 2015")]
  850. [Description("DecompilerSettings.DictionaryInitializerExpressions")]
  851. public bool DictionaryInitializers {
  852. get { return dictionaryInitializers; }
  853. set {
  854. if (dictionaryInitializers != value)
  855. {
  856. dictionaryInitializers = value;
  857. OnPropertyChanged();
  858. }
  859. }
  860. }
  861. bool extensionMethodsInCollectionInitializers = true;
  862. /// <summary>
  863. /// Gets/Sets whether to use C# 6.0 Extension Add methods in collection initializers.
  864. /// Only has an effect if ObjectOrCollectionInitializers is enabled.
  865. /// </summary>
  866. [Category("C# 6.0 / VS 2015")]
  867. [Description("DecompilerSettings.AllowExtensionAddMethodsInCollectionInitializerExpressions")]
  868. public bool ExtensionMethodsInCollectionInitializers {
  869. get { return extensionMethodsInCollectionInitializers; }
  870. set {
  871. if (extensionMethodsInCollectionInitializers != value)
  872. {
  873. extensionMethodsInCollectionInitializers = value;
  874. OnPropertyChanged();
  875. }
  876. }
  877. }
  878. bool useRefLocalsForAccurateOrderOfEvaluation = true;
  879. /// <summary>
  880. /// Gets/Sets whether to use C# 6.0 Extension Add methods in collection initializers.
  881. /// Only has an effect if ObjectOrCollectionInitializers is enabled.
  882. /// </summary>
  883. [Category("C# 6.0 / VS 2015")]
  884. [Description("DecompilerSettings.UseRefLocalsForAccurateOrderOfEvaluation")]
  885. public bool UseRefLocalsForAccurateOrderOfEvaluation {
  886. get { return useRefLocalsForAccurateOrderOfEvaluation; }
  887. set {
  888. if (useRefLocalsForAccurateOrderOfEvaluation != value)
  889. {
  890. useRefLocalsForAccurateOrderOfEvaluation = value;
  891. OnPropertyChanged();
  892. }
  893. }
  894. }
  895. bool refExtensionMethods = true;
  896. /// <summary>
  897. /// Gets/Sets whether to use C# 7.2 'ref' extension methods.
  898. /// </summary>
  899. [Category("C# 7.2 / VS 2017.4")]
  900. [Description("DecompilerSettings.AllowExtensionMethodSyntaxOnRef")]
  901. public bool RefExtensionMethods {
  902. get { return refExtensionMethods; }
  903. set {
  904. if (refExtensionMethods != value)
  905. {
  906. refExtensionMethods = value;
  907. OnPropertyChanged();
  908. }
  909. }
  910. }
  911. bool stringInterpolation = true;
  912. /// <summary>
  913. /// Gets/Sets whether to use C# 6.0 string interpolation
  914. /// </summary>
  915. [Category("C# 6.0 / VS 2015")]
  916. [Description("DecompilerSettings.UseStringInterpolation")]
  917. public bool StringInterpolation {
  918. get { return stringInterpolation; }
  919. set {
  920. if (stringInterpolation != value)
  921. {
  922. stringInterpolation = value;
  923. OnPropertyChanged();
  924. }
  925. }
  926. }
  927. bool showXmlDocumentation = true;
  928. /// <summary>
  929. /// Gets/Sets whether to include XML documentation comments in the decompiled code.
  930. /// </summary>
  931. [Category("DecompilerSettings.Other")]
  932. [Description("DecompilerSettings.IncludeXMLDocumentationCommentsInTheDecompiledCode")]
  933. public bool ShowXmlDocumentation {
  934. get { return showXmlDocumentation; }
  935. set {
  936. if (showXmlDocumentation != value)
  937. {
  938. showXmlDocumentation = value;
  939. OnPropertyChanged();
  940. }
  941. }
  942. }
  943. bool foldBraces = false;
  944. [Browsable(false)]
  945. public bool FoldBraces {
  946. get { return foldBraces; }
  947. set {
  948. if (foldBraces != value)
  949. {
  950. foldBraces = value;
  951. OnPropertyChanged();
  952. }
  953. }
  954. }
  955. bool expandMemberDefinitions = false;
  956. [Browsable(false)]
  957. public bool ExpandMemberDefinitions {
  958. get { return expandMemberDefinitions; }
  959. set {
  960. if (expandMemberDefinitions != value)
  961. {
  962. expandMemberDefinitions = value;
  963. OnPropertyChanged();
  964. }
  965. }
  966. }
  967. bool expandUsingDeclarations = false;
  968. [Browsable(false)]
  969. public bool ExpandUsingDeclarations {
  970. get { return expandUsingDeclarations; }
  971. set {
  972. if (expandUsingDeclarations != value)
  973. {
  974. expandUsingDeclarations = value;
  975. OnPropertyChanged();
  976. }
  977. }
  978. }
  979. bool decompileMemberBodies = true;
  980. /// <summary>
  981. /// Gets/Sets whether member bodies should be decompiled.
  982. /// </summary>
  983. [Category("DecompilerSettings.Other")]
  984. [Browsable(false)]
  985. public bool DecompileMemberBodies {
  986. get { return decompileMemberBodies; }
  987. set {
  988. if (decompileMemberBodies != value)
  989. {
  990. decompileMemberBodies = value;
  991. OnPropertyChanged();
  992. }
  993. }
  994. }
  995. bool useExpressionBodyForCalculatedGetterOnlyProperties = true;
  996. /// <summary>
  997. /// Gets/Sets whether simple calculated getter-only property declarations
  998. /// should use expression body syntax.
  999. /// </summary>
  1000. [Category("C# 6.0 / VS 2015")]
  1001. [Description("DecompilerSettings.UseExpressionBodiedMemberSyntaxForGetOnlyProperties")]
  1002. public bool UseExpressionBodyForCalculatedGetterOnlyProperties {
  1003. get { return useExpressionBodyForCalculatedGetterOnlyProperties; }
  1004. set {
  1005. if (useExpressionBodyForCalculatedGetterOnlyProperties != value)
  1006. {
  1007. useExpressionBodyForCalculatedGetterOnlyProperties = value;
  1008. OnPropertyChanged();
  1009. }
  1010. }
  1011. }
  1012. bool outVariables = true;
  1013. /// <summary>
  1014. /// Gets/Sets whether out variable declarations should be used when possible.
  1015. /// </summary>
  1016. [Category("C# 7.0 / VS 2017")]
  1017. [Description("DecompilerSettings.UseOutVariableDeclarations")]
  1018. public bool OutVariables {
  1019. get { return outVariables; }
  1020. set {
  1021. if (outVariables != value)
  1022. {
  1023. outVariables = value;
  1024. OnPropertyChanged();
  1025. }
  1026. }
  1027. }
  1028. bool discards = true;
  1029. /// <summary>
  1030. /// Gets/Sets whether discards should be used when possible.
  1031. /// Only has an effect if <see cref="OutVariables"/> is enabled.
  1032. /// </summary>
  1033. [Category("C# 7.0 / VS 2017")]
  1034. [Description("DecompilerSettings.UseDiscards")]
  1035. public bool Discards {
  1036. get { return discards; }
  1037. set {
  1038. if (discards != value)
  1039. {
  1040. discards = value;
  1041. OnPropertyChanged();
  1042. }
  1043. }
  1044. }
  1045. bool introduceRefModifiersOnStructs = true;
  1046. /// <summary>
  1047. /// Gets/Sets whether IsByRefLikeAttribute should be replaced with 'ref' modifiers on structs.
  1048. /// </summary>
  1049. [Category("C# 7.2 / VS 2017.4")]
  1050. [Description("DecompilerSettings.IsByRefLikeAttributeShouldBeReplacedWithRefModifiersOnStructs")]
  1051. public bool IntroduceRefModifiersOnStructs {
  1052. get { return introduceRefModifiersOnStructs; }
  1053. set {
  1054. if (introduceRefModifiersOnStructs != value)
  1055. {
  1056. introduceRefModifiersOnStructs = value;
  1057. OnPropertyChanged();
  1058. }
  1059. }
  1060. }
  1061. bool introduceReadonlyAndInModifiers = true;
  1062. /// <summary>
  1063. /// Gets/Sets whether IsReadOnlyAttribute should be replaced with 'readonly' modifiers on structs
  1064. /// and with the 'in' modifier on parameters.
  1065. /// </summary>
  1066. [Category("C# 7.2 / VS 2017.4")]
  1067. [Description("DecompilerSettings." +
  1068. "IsReadOnlyAttributeShouldBeReplacedWithReadonlyInModifiersOnStructsParameters")]
  1069. public bool IntroduceReadonlyAndInModifiers {
  1070. get { return introduceReadonlyAndInModifiers; }
  1071. set {
  1072. if (introduceReadonlyAndInModifiers != value)
  1073. {
  1074. introduceReadonlyAndInModifiers = value;
  1075. OnPropertyChanged();
  1076. }
  1077. }
  1078. }
  1079. bool readOnlyMethods = true;
  1080. [Category("C# 8.0 / VS 2019")]
  1081. [Description("DecompilerSettings.ReadOnlyMethods")]
  1082. public bool ReadOnlyMethods {
  1083. get { return readOnlyMethods; }
  1084. set {
  1085. if (readOnlyMethods != value)
  1086. {
  1087. readOnlyMethods = value;
  1088. OnPropertyChanged();
  1089. }
  1090. }
  1091. }
  1092. bool asyncUsingAndForEachStatement = true;
  1093. [Category("C# 8.0 / VS 2019")]
  1094. [Description("DecompilerSettings.DetectAsyncUsingAndForeachStatements")]
  1095. public bool AsyncUsingAndForEachStatement {
  1096. get { return asyncUsingAndForEachStatement; }
  1097. set {
  1098. if (asyncUsingAndForEachStatement != value)
  1099. {
  1100. asyncUsingAndForEachStatement = value;
  1101. OnPropertyChanged();
  1102. }
  1103. }
  1104. }
  1105. bool introduceUnmanagedConstraint = true;
  1106. /// <summary>
  1107. /// If this option is active, [IsUnmanagedAttribute] on type parameters
  1108. /// is replaced with "T : unmanaged" constraints.
  1109. /// </summary>
  1110. [Category("C# 7.3 / VS 2017.7")]
  1111. [Description("DecompilerSettings." +
  1112. "IsUnmanagedAttributeOnTypeParametersShouldBeReplacedWithUnmanagedConstraints")]
  1113. public bool IntroduceUnmanagedConstraint {
  1114. get { return introduceUnmanagedConstraint; }
  1115. set {
  1116. if (introduceUnmanagedConstraint != value)
  1117. {
  1118. introduceUnmanagedConstraint = value;
  1119. OnPropertyChanged();
  1120. }
  1121. }
  1122. }
  1123. bool stackAllocInitializers = true;
  1124. /// <summary>
  1125. /// Gets/Sets whether C# 7.3 stackalloc initializers should be used.
  1126. /// </summary>
  1127. [Category("C# 7.3 / VS 2017.7")]
  1128. [Description("DecompilerSettings.UseStackallocInitializerSyntax")]
  1129. public bool StackAllocInitializers {
  1130. get { return stackAllocInitializers; }
  1131. set {
  1132. if (stackAllocInitializers != value)
  1133. {
  1134. stackAllocInitializers = value;
  1135. OnPropertyChanged();
  1136. }
  1137. }
  1138. }
  1139. bool patternBasedFixedStatement = true;
  1140. /// <summary>
  1141. /// Gets/Sets whether C# 7.3 pattern based fixed statement should be used.
  1142. /// </summary>
  1143. [Category("C# 7.3 / VS 2017.7")]
  1144. [Description("DecompilerSettings.UsePatternBasedFixedStatement")]
  1145. public bool PatternBasedFixedStatement {
  1146. get { return patternBasedFixedStatement; }
  1147. set {
  1148. if (patternBasedFixedStatement != value)
  1149. {
  1150. patternBasedFixedStatement = value;
  1151. OnPropertyChanged();
  1152. }
  1153. }
  1154. }
  1155. bool tupleTypes = true;
  1156. /// <summary>
  1157. /// Gets/Sets whether tuple type syntax <c>(int, string)</c>
  1158. /// should be used for <c>System.ValueTuple</c>.
  1159. /// </summary>
  1160. [Category("C# 7.0 / VS 2017")]
  1161. [Description("DecompilerSettings.UseTupleTypeSyntax")]
  1162. public bool TupleTypes {
  1163. get { return tupleTypes; }
  1164. set {
  1165. if (tupleTypes != value)
  1166. {
  1167. tupleTypes = value;
  1168. OnPropertyChanged();
  1169. }
  1170. }
  1171. }
  1172. bool throwExpressions = true;
  1173. /// <summary>
  1174. /// Gets/Sets whether throw expressions should be used.
  1175. /// </summary>
  1176. [Category("C# 7.0 / VS 2017")]
  1177. [Description("DecompilerSettings.UseThrowExpressions")]
  1178. public bool ThrowExpressions {
  1179. get { return throwExpressions; }
  1180. set {
  1181. if (throwExpressions != value)
  1182. {
  1183. throwExpressions = value;
  1184. OnPropertyChanged();
  1185. }
  1186. }
  1187. }
  1188. bool tupleConversions = true;
  1189. /// <summary>
  1190. /// Gets/Sets whether implicit conversions between tuples
  1191. /// should be used in the decompiled output.
  1192. /// </summary>
  1193. [Category("C# 7.0 / VS 2017")]
  1194. [Description("DecompilerSettings.UseImplicitConversionsBetweenTupleTypes")]
  1195. public bool TupleConversions {
  1196. get { return tupleConversions; }
  1197. set {
  1198. if (tupleConversions != value)
  1199. {
  1200. tupleConversions = value;
  1201. OnPropertyChanged();
  1202. }
  1203. }
  1204. }
  1205. bool tupleComparisons = true;
  1206. /// <summary>
  1207. /// Gets/Sets whether tuple comparisons should be detected.
  1208. /// </summary>
  1209. [Category("C# 7.3 / VS 2017.7")]
  1210. [Description("DecompilerSettings.DetectTupleComparisons")]
  1211. public bool TupleComparisons {
  1212. get { return tupleComparisons; }
  1213. set {
  1214. if (tupleComparisons != value)
  1215. {
  1216. tupleComparisons = value;
  1217. OnPropertyChanged();
  1218. }
  1219. }
  1220. }
  1221. bool namedArguments = true;
  1222. /// <summary>
  1223. /// Gets/Sets whether named arguments should be used.
  1224. /// </summary>
  1225. [Category("C# 4.0 / VS 2010")]
  1226. [Description("DecompilerSettings.UseNamedArguments")]
  1227. public bool NamedArguments {
  1228. get { return namedArguments; }
  1229. set {
  1230. if (namedArguments != value)
  1231. {
  1232. namedArguments = value;
  1233. OnPropertyChanged();
  1234. }
  1235. }
  1236. }
  1237. bool nonTrailingNamedArguments = true;
  1238. /// <summary>
  1239. /// Gets/Sets whether C# 7.2 non-trailing named arguments should be used.
  1240. /// </summary>
  1241. [Category("C# 7.2 / VS 2017.4")]
  1242. [Description("DecompilerSettings.UseNonTrailingNamedArguments")]
  1243. public bool NonTrailingNamedArguments {
  1244. get { return nonTrailingNamedArguments; }
  1245. set {
  1246. if (nonTrailingNamedArguments != value)
  1247. {
  1248. nonTrailingNamedArguments = value;
  1249. OnPropertyChanged();
  1250. }
  1251. }
  1252. }
  1253. bool optionalArguments = true;
  1254. /// <summary>
  1255. /// Gets/Sets whether optional arguments should be removed, if possible.
  1256. /// </summary>
  1257. [Category("C# 4.0 / VS 2010")]
  1258. [Description("DecompilerSettings.RemoveOptionalArgumentsIfPossible")]
  1259. public bool OptionalArguments {
  1260. get { return optionalArguments; }
  1261. set {
  1262. if (optionalArguments != value)
  1263. {
  1264. optionalArguments = value;
  1265. OnPropertyChanged();
  1266. }
  1267. }
  1268. }
  1269. bool localFunctions = true;
  1270. /// <summary>
  1271. /// Gets/Sets whether C# 7.0 local functions should be transformed.
  1272. /// </summary>
  1273. [Category("C# 7.0 / VS 2017")]
  1274. [Description("DecompilerSettings.IntroduceLocalFunctions")]
  1275. public bool LocalFunctions {
  1276. get { return localFunctions; }
  1277. set {
  1278. if (localFunctions != value)
  1279. {
  1280. localFunctions = value;
  1281. OnPropertyChanged();
  1282. }
  1283. }
  1284. }
  1285. bool deconstruction = true;
  1286. /// <summary>
  1287. /// Gets/Sets whether C# 7.0 deconstruction should be detected.
  1288. /// </summary>
  1289. [Category("C# 7.0 / VS 2017")]
  1290. [Description("DecompilerSettings.Deconstruction")]
  1291. public bool Deconstruction {
  1292. get { return deconstruction; }
  1293. set {
  1294. if (deconstruction != value)
  1295. {
  1296. deconstruction = value;
  1297. OnPropertyChanged();
  1298. }
  1299. }
  1300. }
  1301. bool patternMatching = true;
  1302. /// <summary>
  1303. /// Gets/Sets whether C# 7.0 pattern matching should be detected.
  1304. /// </summary>
  1305. [Category("C# 7.0 / VS 2017")]
  1306. [Description("DecompilerSettings.PatternMatching")]
  1307. public bool PatternMatching {
  1308. get { return patternMatching; }
  1309. set {
  1310. if (patternMatching != value)
  1311. {
  1312. patternMatching = value;
  1313. OnPropertyChanged();
  1314. }
  1315. }
  1316. }
  1317. bool staticLocalFunctions = true;
  1318. /// <summary>
  1319. /// Gets/Sets whether C# 8.0 static local functions should be transformed.
  1320. /// </summary>
  1321. [Category("C# 8.0 / VS 2019")]
  1322. [Description("DecompilerSettings.IntroduceStaticLocalFunctions")]
  1323. public bool StaticLocalFunctions {
  1324. get { return staticLocalFunctions; }
  1325. set {
  1326. if (staticLocalFunctions != value)
  1327. {
  1328. staticLocalFunctions = value;
  1329. OnPropertyChanged();
  1330. }
  1331. }
  1332. }
  1333. bool ranges = true;
  1334. /// <summary>
  1335. /// Gets/Sets whether C# 8.0 index and range syntax should be used.
  1336. /// </summary>
  1337. [Category("C# 8.0 / VS 2019")]
  1338. [Description("DecompilerSettings.Ranges")]
  1339. public bool Ranges {
  1340. get { return ranges; }
  1341. set {
  1342. if (ranges != value)
  1343. {
  1344. ranges = value;
  1345. OnPropertyChanged();
  1346. }
  1347. }
  1348. }
  1349. bool nullableReferenceTypes = true;
  1350. /// <summary>
  1351. /// Gets/Sets whether C# 8.0 nullable reference types are enabled.
  1352. /// </summary>
  1353. [Category("C# 8.0 / VS 2019")]
  1354. [Description("DecompilerSettings.NullableReferenceTypes")]
  1355. public bool NullableReferenceTypes {
  1356. get { return nullableReferenceTypes; }
  1357. set {
  1358. if (nullableReferenceTypes != value)
  1359. {
  1360. nullableReferenceTypes = value;
  1361. OnPropertyChanged();
  1362. }
  1363. }
  1364. }
  1365. bool showDebugInfo;
  1366. [Category("DecompilerSettings.Other")]
  1367. [Description("DecompilerSettings.ShowInfoFromDebugSymbolsIfAvailable")]
  1368. [Browsable(false)]
  1369. public bool ShowDebugInfo {
  1370. get { return showDebugInfo; }
  1371. set {
  1372. if (showDebugInfo != value)
  1373. {
  1374. showDebugInfo = value;
  1375. OnPropertyChanged();
  1376. }
  1377. }
  1378. }
  1379. #region Options to aid VB decompilation
  1380. bool assumeArrayLengthFitsIntoInt32 = true;
  1381. /// <summary>
  1382. /// Gets/Sets whether the decompiler can assume that 'ldlen; conv.i4.ovf'
  1383. /// does not throw an overflow exception.
  1384. /// </summary>
  1385. [Category("DecompilerSettings.VBSpecificOptions")]
  1386. [Browsable(false)]
  1387. public bool AssumeArrayLengthFitsIntoInt32 {
  1388. get { return assumeArrayLengthFitsIntoInt32; }
  1389. set {
  1390. if (assumeArrayLengthFitsIntoInt32 != value)
  1391. {
  1392. assumeArrayLengthFitsIntoInt32 = value;
  1393. OnPropertyChanged();
  1394. }
  1395. }
  1396. }
  1397. bool introduceIncrementAndDecrement = true;
  1398. /// <summary>
  1399. /// Gets/Sets whether to use increment and decrement operators
  1400. /// </summary>
  1401. [Category("DecompilerSettings.VBSpecificOptions")]
  1402. [Browsable(false)]
  1403. public bool IntroduceIncrementAndDecrement {
  1404. get { return introduceIncrementAndDecrement; }
  1405. set {
  1406. if (introduceIncrementAndDecrement != value)
  1407. {
  1408. introduceIncrementAndDecrement = value;
  1409. OnPropertyChanged();
  1410. }
  1411. }
  1412. }
  1413. bool makeAssignmentExpressions = true;
  1414. /// <summary>
  1415. /// Gets/Sets whether to use assignment expressions such as in while ((count = Do()) != 0) ;
  1416. /// </summary>
  1417. [Category("DecompilerSettings.VBSpecificOptions")]
  1418. [Browsable(false)]
  1419. public bool MakeAssignmentExpressions {
  1420. get { return makeAssignmentExpressions; }
  1421. set {
  1422. if (makeAssignmentExpressions != value)
  1423. {
  1424. makeAssignmentExpressions = value;
  1425. OnPropertyChanged();
  1426. }
  1427. }
  1428. }
  1429. #endregion
  1430. #region Options to aid F# decompilation
  1431. bool removeDeadCode = false;
  1432. [Category("DecompilerSettings.FSpecificOptions")]
  1433. [Description("DecompilerSettings.RemoveDeadAndSideEffectFreeCodeUseWithCaution")]
  1434. public bool RemoveDeadCode {
  1435. get { return removeDeadCode; }
  1436. set {
  1437. if (removeDeadCode != value)
  1438. {
  1439. removeDeadCode = value;
  1440. OnPropertyChanged();
  1441. }
  1442. }
  1443. }
  1444. bool removeDeadStores = false;
  1445. [Category("DecompilerSettings.FSpecificOptions")]
  1446. [Description("DecompilerSettings.RemoveDeadStores")]
  1447. public bool RemoveDeadStores {
  1448. get { return removeDeadStores; }
  1449. set {
  1450. if (removeDeadStores != value)
  1451. {
  1452. removeDeadStores = value;
  1453. OnPropertyChanged();
  1454. }
  1455. }
  1456. }
  1457. #endregion
  1458. #region Assembly Load and Resolve options
  1459. bool loadInMemory = false;
  1460. [Browsable(false)]
  1461. public bool LoadInMemory {
  1462. get { return loadInMemory; }
  1463. set {
  1464. if (loadInMemory != value)
  1465. {
  1466. loadInMemory = value;
  1467. OnPropertyChanged();
  1468. }
  1469. }
  1470. }
  1471. bool throwOnAssemblyResolveErrors = true;
  1472. [Browsable(false)]
  1473. public bool ThrowOnAssemblyResolveErrors {
  1474. get { return throwOnAssemblyResolveErrors; }
  1475. set {
  1476. if (throwOnAssemblyResolveErrors != value)
  1477. {
  1478. throwOnAssemblyResolveErrors = value;
  1479. OnPropertyChanged();
  1480. }
  1481. }
  1482. }
  1483. bool applyWindowsRuntimeProjections = true;
  1484. [Category("DecompilerSettings.Other")]
  1485. [Description("DecompilerSettings.ApplyWindowsRuntimeProjectionsOnLoadedAssemblies")]
  1486. public bool ApplyWindowsRuntimeProjections {
  1487. get { return applyWindowsRuntimeProjections; }
  1488. set {
  1489. if (applyWindowsRuntimeProjections != value)
  1490. {
  1491. applyWindowsRuntimeProjections = value;
  1492. OnPropertyChanged();
  1493. }
  1494. }
  1495. }
  1496. #endregion
  1497. bool forStatement = true;
  1498. /// <summary>
  1499. /// Gets/sets whether the decompiler should produce for loops.
  1500. /// </summary>
  1501. [Category("C# 1.0 / VS .NET")]
  1502. [Description("DecompilerSettings.ForStatement")]
  1503. public bool ForStatement {
  1504. get { return forStatement; }
  1505. set {
  1506. if (forStatement != value)
  1507. {
  1508. forStatement = value;
  1509. OnPropertyChanged();
  1510. }
  1511. }
  1512. }
  1513. bool doWhileStatement = true;
  1514. /// <summary>
  1515. /// Gets/sets whether the decompiler should produce do-while loops.
  1516. /// </summary>
  1517. [Category("C# 1.0 / VS .NET")]
  1518. [Description("DecompilerSettings.DoWhileStatement")]
  1519. public bool DoWhileStatement {
  1520. get { return doWhileStatement; }
  1521. set {
  1522. if (doWhileStatement != value)
  1523. {
  1524. doWhileStatement = value;
  1525. OnPropertyChanged();
  1526. }
  1527. }
  1528. }
  1529. bool separateLocalVariableDeclarations = false;
  1530. /// <summary>
  1531. /// Gets/sets whether the decompiler should separate local variable declarations
  1532. /// from their initialization.
  1533. /// </summary>
  1534. [Category("DecompilerSettings.Other")]
  1535. [Description("DecompilerSettings.SeparateLocalVariableDeclarations")]
  1536. public bool SeparateLocalVariableDeclarations {
  1537. get { return separateLocalVariableDeclarations; }
  1538. set {
  1539. if (separateLocalVariableDeclarations != value)
  1540. {
  1541. separateLocalVariableDeclarations = value;
  1542. OnPropertyChanged();
  1543. }
  1544. }
  1545. }
  1546. bool useSdkStyleProjectFormat = true;
  1547. /// <summary>
  1548. /// Gets or sets a value indicating whether the new SDK style format
  1549. /// shall be used for the generated project files.
  1550. /// </summary>
  1551. [Category("DecompilerSettings.Other")]
  1552. [Description("DecompilerSettings.UseSdkStyleProjectFormat")]
  1553. public bool UseSdkStyleProjectFormat {
  1554. get { return useSdkStyleProjectFormat; }
  1555. set {
  1556. if (useSdkStyleProjectFormat != value)
  1557. {
  1558. useSdkStyleProjectFormat = value;
  1559. OnPropertyChanged();
  1560. }
  1561. }
  1562. }
  1563. bool aggressiveScalarReplacementOfAggregates = false;
  1564. [Category("DecompilerSettings.Other")]
  1565. [Description("DecompilerSettings.AggressiveScalarReplacementOfAggregates")]
  1566. // TODO : Remove once https://github.com/icsharpcode/ILSpy/issues/2032 is fixed.
  1567. #if !DEBUG
  1568. [Browsable(false)]
  1569. #endif
  1570. public bool AggressiveScalarReplacementOfAggregates {
  1571. get { return aggressiveScalarReplacementOfAggregates; }
  1572. set {
  1573. if (aggressiveScalarReplacementOfAggregates != value)
  1574. {
  1575. aggressiveScalarReplacementOfAggregates = value;
  1576. OnPropertyChanged();
  1577. }
  1578. }
  1579. }
  1580. bool aggressiveInlining = false;
  1581. /// <summary>
  1582. /// If set to false (the default), the decompiler will inline local variables only when they occur
  1583. /// in a context where the C# compiler is known to emit compiler-generated locals.
  1584. /// If set to true, the decompiler will inline local variables whenever possible.
  1585. /// </summary>
  1586. [Category("DecompilerSettings.Other")]
  1587. [Description("DecompilerSettings.AggressiveInlining")]
  1588. public bool AggressiveInlining {
  1589. get { return aggressiveInlining; }
  1590. set {
  1591. if (aggressiveInlining != value)
  1592. {
  1593. aggressiveInlining = value;
  1594. OnPropertyChanged();
  1595. }
  1596. }
  1597. }
  1598. CSharpFormattingOptions csharpFormattingOptions;
  1599. [Browsable(false)]
  1600. public CSharpFormattingOptions CSharpFormattingOptions {
  1601. get {
  1602. if (csharpFormattingOptions == null)
  1603. {
  1604. csharpFormattingOptions = FormattingOptionsFactory.CreateAllman();
  1605. csharpFormattingOptions.IndentSwitchBody = false;
  1606. csharpFormattingOptions.ArrayInitializerWrapping = Wrapping.WrapIfTooLong;
  1607. csharpFormattingOptions.AutoPropertyFormatting = PropertyFormatting.SingleLine;
  1608. }
  1609. return csharpFormattingOptions;
  1610. }
  1611. set {
  1612. if (value == null)
  1613. throw new ArgumentNullException();
  1614. if (csharpFormattingOptions != value)
  1615. {
  1616. csharpFormattingOptions = value;
  1617. OnPropertyChanged();
  1618. }
  1619. }
  1620. }
  1621. public event PropertyChangedEventHandler PropertyChanged;
  1622. protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
  1623. {
  1624. if (PropertyChanged != null)
  1625. {
  1626. PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
  1627. }
  1628. }
  1629. public DecompilerSettings Clone()
  1630. {
  1631. DecompilerSettings settings = (DecompilerSettings)MemberwiseClone();
  1632. if (csharpFormattingOptions != null)
  1633. settings.csharpFormattingOptions = csharpFormattingOptions.Clone();
  1634. settings.PropertyChanged = null;
  1635. return settings;
  1636. }
  1637. }
  1638. }