Browse Source

Fix NullReferenceException in AstMethodBodyBuilder introduced by the bugfix for #282.

Improvement coding style of generated switch statements.
pull/348/head
Daniel Grunwald 13 years ago
parent
commit
5d3a812ac0
  1. 2
      ICSharpCode.Decompiler/Ast/AstBuilder.cs
  2. 2
      ICSharpCode.Decompiler/Ast/AstMethodBodyBuilder.cs
  3. 22
      ICSharpCode.Decompiler/DecompilerSettings.cs
  4. 9
      NRefactory/ICSharpCode.NRefactory.CSharp/OutputVisitor/CSharpOutputVisitor.cs

2
ICSharpCode.Decompiler/Ast/AstBuilder.cs

@ -159,7 +159,7 @@ namespace ICSharpCode.Decompiler.Ast @@ -159,7 +159,7 @@ namespace ICSharpCode.Decompiler.Ast
astCompileUnit.AcceptVisitor(new InsertParenthesesVisitor { InsertParenthesesForReadability = true });
var outputFormatter = new TextOutputFormatter(output);
var formattingPolicy = FormattingOptionsFactory.CreateAllman();
var formattingPolicy = context.Settings.CSharpFormattingOptions;
astCompileUnit.AcceptVisitor(new CSharpOutputVisitor(outputFormatter, formattingPolicy));
}

2
ICSharpCode.Decompiler/Ast/AstMethodBodyBuilder.cs

@ -550,7 +550,7 @@ namespace ICSharpCode.Decompiler.Ast @@ -550,7 +550,7 @@ namespace ICSharpCode.Decompiler.Ast
else
goto case ILCode.Castclass;
case ILCode.Castclass:
if (byteCode.Arguments[0].InferredType.IsGenericParameter || ((Cecil.TypeReference)operand).IsGenericParameter)
if ((byteCode.Arguments[0].InferredType != null && byteCode.Arguments[0].InferredType.IsGenericParameter) || ((Cecil.TypeReference)operand).IsGenericParameter)
return arg1.CastTo(new PrimitiveType("object")).CastTo(operandAsTypeRef);
else
return arg1.CastTo(operandAsTypeRef);

22
ICSharpCode.Decompiler/DecompilerSettings.cs

@ -18,6 +18,7 @@ @@ -18,6 +18,7 @@
using System;
using System.ComponentModel;
using ICSharpCode.NRefactory.CSharp;
namespace ICSharpCode.Decompiler
{
@ -271,6 +272,26 @@ namespace ICSharpCode.Decompiler @@ -271,6 +272,26 @@ namespace ICSharpCode.Decompiler
}
#endregion
CSharpFormattingOptions csharpFormattingOptions;
public CSharpFormattingOptions CSharpFormattingOptions {
get {
if (csharpFormattingOptions == null) {
csharpFormattingOptions = FormattingOptionsFactory.CreateAllman();
csharpFormattingOptions.IndentSwitchBody = false;
}
return csharpFormattingOptions;
}
set {
if (value == null)
throw new ArgumentNullException();
if (csharpFormattingOptions != value) {
csharpFormattingOptions = value;
OnPropertyChanged("CSharpFormattingOptions");
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
@ -283,6 +304,7 @@ namespace ICSharpCode.Decompiler @@ -283,6 +304,7 @@ namespace ICSharpCode.Decompiler
public DecompilerSettings Clone()
{
DecompilerSettings settings = (DecompilerSettings)MemberwiseClone();
settings.csharpFormattingOptions = csharpFormattingOptions.Clone();
settings.PropertyChanged = null;
return settings;
}

9
NRefactory/ICSharpCode.NRefactory.CSharp/OutputVisitor/CSharpOutputVisitor.cs

@ -1837,16 +1837,19 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1837,16 +1837,19 @@ namespace ICSharpCode.NRefactory.CSharp
label.AcceptVisitor(this);
first = false;
}
if (policy.IndentCaseBody) {
bool isBlock = switchSection.Statements.Count == 1 && switchSection.Statements.Single() is BlockStatement;
if (policy.IndentCaseBody && !isBlock) {
formatter.Indent();
}
foreach (var statement in switchSection.Statements) {
if (!isBlock)
NewLine();
foreach (var statement in switchSection.Statements) {
statement.AcceptVisitor(this);
}
if (policy.IndentCaseBody) {
if (policy.IndentCaseBody && !isBlock) {
formatter.Unindent();
}

Loading…
Cancel
Save