Browse Source

Add support for expression bodies to IndexerDeclaration.

pull/1440/head
Siegfried Pammer 7 years ago
parent
commit
78cf5f0ec0
  1. 9
      ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs
  2. 9
      ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/IndexerDeclaration.cs

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

@ -2096,6 +2096,8 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor @@ -2096,6 +2096,8 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
WriteKeyword(IndexerDeclaration.ThisKeywordRole);
Space(policy.SpaceBeforeMethodDeclarationParentheses);
WriteCommaSeparatedListInBrackets(indexerDeclaration.Parameters, policy.SpaceWithinMethodDeclarationParentheses);
if (indexerDeclaration.ExpressionBody.IsNull) {
OpenBrace(policy.PropertyBraceStyle);
// output get/set in their original order
foreach (AstNode node in indexerDeclaration.Children) {
@ -2105,6 +2107,13 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor @@ -2105,6 +2107,13 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
}
CloseBrace(policy.PropertyBraceStyle);
NewLine();
} else {
Space();
WriteToken(Roles.Arrow);
Space();
indexerDeclaration.ExpressionBody.AcceptVisitor(this);
Semicolon();
}
EndNode(indexerDeclaration);
}

9
ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/IndexerDeclaration.cs

@ -35,6 +35,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -35,6 +35,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
public static readonly TokenRole ThisKeywordRole = new TokenRole ("this");
public static readonly Role<Accessor> GetterRole = PropertyDeclaration.GetterRole;
public static readonly Role<Accessor> SetterRole = PropertyDeclaration.SetterRole;
public static readonly Role<Expression> ExpressionBodyRole = new Role<Expression>("ExpressionBody", Expression.Null);
public override SymbolKind SymbolKind {
get { return SymbolKind.Indexer; }
@ -94,6 +95,11 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -94,6 +95,11 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
get { return GetChildByRole (Roles.RBrace); }
}
public Expression ExpressionBody {
get { return GetChildByRole(ExpressionBodyRole); }
set { SetChildByRole(ExpressionBodyRole, value); }
}
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitIndexerDeclaration (this);
@ -116,7 +122,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -116,7 +122,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
&& this.MatchAttributesAndModifiers(o, match) && this.ReturnType.DoMatch(o.ReturnType, match)
&& this.PrivateImplementationType.DoMatch(o.PrivateImplementationType, match)
&& this.Parameters.DoMatch(o.Parameters, match)
&& this.Getter.DoMatch(o.Getter, match) && this.Setter.DoMatch(o.Setter, match);
&& this.Getter.DoMatch(o.Getter, match) && this.Setter.DoMatch(o.Setter, match)
&& this.ExpressionBody.DoMatch(o.ExpressionBody, match);
}
}
}

Loading…
Cancel
Save