44
55namespace ICSharpCode . CodeConverter . CSharp ;
66
7+ internal record struct Assignment ( ExpressionSyntax Field , SyntaxKind AssignmentKind , ExpressionSyntax Initializer , bool PostAssignment = false ) ;
8+
79internal class AdditionalInitializers
810{
911 private readonly bool _shouldAddInstanceConstructor ;
@@ -36,7 +38,8 @@ public IReadOnlyCollection<MemberDeclarationSyntax> WithAdditionalInitializers(L
3638 . Where ( cds => ! cds . Initializer . IsKind ( SyntaxKind . ThisConstructorInitializer ) )
3739 . SplitOn ( cds => cds . IsInStaticCsContext ( ) ) ;
3840
39- convertedMembers = WithAdditionalInitializers ( convertedMembers , parentTypeName , AdditionalInstanceInitializers , SyntaxFactory . TokenList ( SyntaxFactory . Token ( SyntaxKind . PublicKeyword ) ) , rootInstanceConstructors , _shouldAddInstanceConstructor , DesignerGeneratedInitializeComponentOrNull != null ) ;
41+ convertedMembers = WithAdditionalInitializers ( convertedMembers , parentTypeName , AdditionalInstanceInitializers , SyntaxFactory . TokenList ( SyntaxFactory . Token ( SyntaxKind . PublicKeyword ) ) ,
42+ rootInstanceConstructors , _shouldAddInstanceConstructor , DesignerGeneratedInitializeComponentOrNull != null ) ;
4043
4144 convertedMembers = WithAdditionalInitializers ( convertedMembers , parentTypeName ,
4245 AdditionalStaticInitializers , SyntaxFactory . TokenList ( SyntaxFactory . Token ( SyntaxKind . StaticKeyword ) ) , rootStaticConstructors , _shouldAddStaticConstructor , false ) ;
@@ -56,10 +59,12 @@ private List<MemberDeclarationSyntax> WithAdditionalInitializers(List<MemberDecl
5659 if ( addedConstructorRequiresInitializeComponent ) {
5760 statements . Add ( SyntaxFactory . ExpressionStatement ( SyntaxFactory . InvocationExpression ( SyntaxFactory . IdentifierName ( "InitializeComponent" ) ) ) ) ;
5861 }
62+
5963 constructors . Add ( SyntaxFactory . ConstructorDeclaration ( convertIdentifier )
6064 . WithBody ( SyntaxFactory . Block ( statements . ToArray ( ) ) )
6165 . WithModifiers ( modifiers ) ) ;
6266 }
67+
6368 foreach ( var constructor in constructors ) {
6469 var newConstructor = WithAdditionalInitializers ( constructor , additionalInitializers ) ;
6570 ReplaceOrInsertBeforeFirstConstructor ( convertedMembers , constructor , newConstructor ) ;
@@ -71,12 +76,9 @@ private List<MemberDeclarationSyntax> WithAdditionalInitializers(List<MemberDecl
7176 private static void ReplaceOrInsertBeforeFirstConstructor ( List < MemberDeclarationSyntax > convertedMembers , ConstructorDeclarationSyntax constructor , ConstructorDeclarationSyntax newConstructor )
7277 {
7378 int existingIndex = convertedMembers . IndexOf ( constructor ) ;
74- if ( existingIndex > - 1 )
75- {
79+ if ( existingIndex > - 1 ) {
7680 convertedMembers [ existingIndex ] = newConstructor ;
77- }
78- else
79- {
81+ } else {
8082 int constructorIndex = convertedMembers . FindIndex ( c => c is ConstructorDeclarationSyntax or MethodDeclarationSyntax ) ;
8183 convertedMembers . Insert ( constructorIndex > - 1 ? constructorIndex : convertedMembers . Count , newConstructor ) ;
8284 }
0 commit comments