Skip to content

Commit

Permalink
Fix icsharpcode#3159: CSharpAmbience.ConvertSymbol output incorrect f…
Browse files Browse the repository at this point in the history
…or record structs and init properties.
  • Loading branch information
siegfriedpammer committed Aug 24, 2024
1 parent dd04564 commit 43f6022
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpAmbience.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public void ConvertSymbol(ISymbol symbol, TokenWriter writer, CSharpFormattingOp
break;
case ClassType.RecordStruct:
writer.WriteKeyword(Roles.RecordKeyword, "record");
writer.Space();
writer.WriteKeyword(Roles.StructKeyword, "struct");
break;
default:
Expand Down Expand Up @@ -181,8 +182,7 @@ public void ConvertSymbol(ISymbol symbol, TokenWriter writer, CSharpFormattingOp

if ((ConversionFlags & ConversionFlags.ShowBody) == ConversionFlags.ShowBody && !(node is TypeDeclaration))
{
IProperty property = symbol as IProperty;
if (property != null)
if (symbol is IProperty property)
{
writer.Space();
writer.WriteToken(Roles.LBrace, "{");
Expand All @@ -195,7 +195,10 @@ public void ConvertSymbol(ISymbol symbol, TokenWriter writer, CSharpFormattingOp
}
if (property.CanSet)
{
writer.WriteKeyword(PropertyDeclaration.SetKeywordRole, "set");
if ((ConversionFlags & ConversionFlags.SupportInitAccessors) != 0 && property.Setter.IsInitOnly)
writer.WriteKeyword(PropertyDeclaration.InitKeywordRole, "init");
else
writer.WriteKeyword(PropertyDeclaration.SetKeywordRole, "set");
writer.WriteToken(Roles.Semicolon, ";");
writer.Space();
}
Expand Down

0 comments on commit 43f6022

Please sign in to comment.