Browse Source

Fix #3617: Order of XML comments in types with primary constructors

pull/3013/head
Siegfried Pammer 3 weeks ago
parent
commit
3a27cbef06
  1. 18
      ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/TypeDeclaration.cs
  2. 14
      ICSharpCode.Decompiler/CSharp/Transforms/TransformFieldAndConstructorInitializers.cs

18
ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/TypeDeclaration.cs

@ -100,24 +100,30 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -100,24 +100,30 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
get { return GetChildByRole(Roles.RChevron); }
}
public CSharpTokenNode ColonToken {
get {
return GetChildByRole(Roles.Colon);
}
}
public AstNodeCollection<AstType> BaseTypes {
get { return GetChildrenByRole(Roles.BaseType); }
}
public bool HasPrimaryConstructor { get; set; }
public CSharpTokenNode LParToken {
get { return GetChildByRole(Roles.LPar); }
}
public AstNodeCollection<ParameterDeclaration> PrimaryConstructorParameters {
get { return GetChildrenByRole(Roles.Parameter); }
}
public CSharpTokenNode RParToken {
get { return GetChildByRole(Roles.RPar); }
}
public AstNodeCollection<AstType> BaseTypes {
get { return GetChildrenByRole(Roles.BaseType); }
}
public AstNodeCollection<Constraint> Constraints {
get { return GetChildrenByRole(Roles.Constraint); }
}

14
ICSharpCode.Decompiler/CSharp/Transforms/TransformFieldAndConstructorInitializers.cs

@ -598,7 +598,19 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms @@ -598,7 +598,19 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
|| !PrimaryConstructorDecl.Initializer.IsNull
|| TypeDefinition.Kind == TypeKind.Struct;
PrimaryConstructorDecl.Parameters.MoveTo(this.TypeDeclaration.PrimaryConstructorParameters);
// HACK: because our current AST model doesn't allow specifying an explicit order of roles,
// we have to explicitly insert the primary constructor parameters,
// MoveTo would just append the parameters to the list of children
if (PrimaryConstructorDecl.Parameters.Count > 0)
{
var insertionPoint = (AstNode?)this.TypeDeclaration.TypeParameters.LastOrDefault() ?? this.TypeDeclaration.NameToken;
foreach (var param in PrimaryConstructorDecl.Parameters)
{
param.Remove();
this.TypeDeclaration.InsertChildAfter(insertionPoint, param, Roles.Parameter);
insertionPoint = param;
}
}
Debug.Assert(PrimaryConstructorParameterToBackingStoreMap != null);

Loading…
Cancel
Save