diff --git a/ICSharpCode.Decompiler/Ast/Transforms/ReplaceMethodCallsWithOperators.cs b/ICSharpCode.Decompiler/Ast/Transforms/ReplaceMethodCallsWithOperators.cs index 7a9eaa365..f630cdc25 100644 --- a/ICSharpCode.Decompiler/Ast/Transforms/ReplaceMethodCallsWithOperators.cs +++ b/ICSharpCode.Decompiler/Ast/Transforms/ReplaceMethodCallsWithOperators.cs @@ -40,6 +40,13 @@ namespace ICSharpCode.Decompiler.Ast.Transforms MemberName = "TypeHandle" }; + DecompilerContext context; + + public ReplaceMethodCallsWithOperators(DecompilerContext context) + { + this.context = context; + } + public override object VisitInvocationExpression(InvocationExpression invocationExpression, object data) { base.VisitInvocationExpression(invocationExpression, data); @@ -211,7 +218,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms } } } - if (assignment.Operator == AssignmentOperatorType.Add || assignment.Operator == AssignmentOperatorType.Subtract) { + if (context.Settings.IntroduceIncrementAndDecrement && (assignment.Operator == AssignmentOperatorType.Add || assignment.Operator == AssignmentOperatorType.Subtract)) { // detect increment/decrement if (assignment.Right.IsMatch(new PrimitiveExpression(1))) { // only if it's not a custom operator diff --git a/ICSharpCode.Decompiler/Ast/Transforms/TransformationPipeline.cs b/ICSharpCode.Decompiler/Ast/Transforms/TransformationPipeline.cs index 686a73a61..334e366b9 100644 --- a/ICSharpCode.Decompiler/Ast/Transforms/TransformationPipeline.cs +++ b/ICSharpCode.Decompiler/Ast/Transforms/TransformationPipeline.cs @@ -35,7 +35,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms new PushNegation(), new DelegateConstruction(context), new PatternStatementTransform(context), - new ReplaceMethodCallsWithOperators(), + new ReplaceMethodCallsWithOperators(context), new IntroduceUnsafeModifier(), new AddCheckedBlocks(), new DeclareVariables(context), // should run after most transforms that modify statements diff --git a/ICSharpCode.Decompiler/DecompilerSettings.cs b/ICSharpCode.Decompiler/DecompilerSettings.cs index 4d5d62d76..e783e9d52 100644 --- a/ICSharpCode.Decompiler/DecompilerSettings.cs +++ b/ICSharpCode.Decompiler/DecompilerSettings.cs @@ -224,6 +224,23 @@ namespace ICSharpCode.Decompiler } } + #region Options to aid VB decompilation + bool introduceIncrementAndDecrement = true; + + /// + /// Gets/Sets whether to use increment and decrement operators + /// + public bool IntroduceIncrementAndDecrement { + get { return introduceIncrementAndDecrement; } + set { + if (introduceIncrementAndDecrement != value) { + introduceIncrementAndDecrement = value; + OnPropertyChanged("IntroduceIncrementAndDecrement"); + } + } + } + #endregion + public event PropertyChangedEventHandler PropertyChanged; protected virtual void OnPropertyChanged(string propertyName) diff --git a/ILSpy/VB/VBLanguage.cs b/ILSpy/VB/VBLanguage.cs index 0b6a2b1cc..19fc178bf 100644 --- a/ILSpy/VB/VBLanguage.cs +++ b/ILSpy/VB/VBLanguage.cs @@ -122,10 +122,10 @@ namespace ICSharpCode.ILSpy.VB if (currentModule == null) currentModule = currentType.Module; DecompilerSettings settings = options.DecompilerSettings; - if (isSingleMember) { - settings = settings.Clone(); + settings = settings.Clone(); + if (isSingleMember) settings.UsingDeclarations = false; - } + settings.IntroduceIncrementAndDecrement = false; return new AstBuilder( new DecompilerContext(currentModule) { CancellationToken = options.CancellationToken,