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

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

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