public MemberDeclarationSyntax GenerateCode()

in SharpGen/Generator/ShadowGenerator.cs [13:114]


        public MemberDeclarationSyntax GenerateCode(CsInterface csElement)
        {
            var shadowClassName = csElement.ShadowName.Split('.').Last();

            var vtblName = IdentifierName(csElement.VtblName);
            var vtblConstructor = ArgumentList(
                SingletonSeparatedList(
                    Argument(
                        LiteralExpression(
                            SyntaxKind.NumericLiteralExpression,
                            Literal(0)
                        )
                    )
                )
            );

            var vtblProperty = PropertyDeclaration(
                                   GlobalNamespace.GetTypeNameSyntax(WellKnownName.CppObjectVtbl),
                                   Identifier("Vtbl")
                               )
                              .WithModifiers(
                                   TokenList(Token(SyntaxKind.ProtectedKeyword), Token(SyntaxKind.OverrideKeyword))
                               )
                              .WithSemicolonToken(Token(SyntaxKind.SemicolonToken));

            List<MemberDeclarationSyntax> members = new();

            if (csElement.AutoGenerateVtbl)
                members.Add(Generators.Vtbl.GenerateCode(csElement));

            if (csElement.StaticShadowVtbl)
            {
                var vtblInstanceName = Identifier("VtblInstance");

                members.Add(
                    FieldDeclaration(
                            VariableDeclaration(vtblName)
                               .WithVariables(
                                    SingletonSeparatedList(
                                        VariableDeclarator(vtblInstanceName)
                                           .WithInitializer(
                                                EqualsValueClause(
                                                    ImplicitObjectCreationExpression()
                                                       .WithArgumentList(
                                                            vtblConstructor
                                                        )
                                                )
                                            )
                                    )
                                )
                        )
                       .WithModifiers(
                            TokenList(Token(SyntaxKind.PrivateKeyword), Token(SyntaxKind.StaticKeyword),
                                      Token(SyntaxKind.ReadOnlyKeyword))
                        )
                );

                vtblProperty = vtblProperty
                   .WithExpressionBody(
                        ArrowExpressionClause(IdentifierName(vtblInstanceName))
                    );
            }
            else
            {
                vtblProperty = vtblProperty
                              .WithAccessorList(
                                   AccessorList(
                                       SingletonList(
                                           AccessorDeclaration(SyntaxKind.GetAccessorDeclaration)
                                              .WithSemicolonToken(Token(SyntaxKind.SemicolonToken))
                                       )
                                   )
                               )
                              .WithInitializer(
                                   EqualsValueClause(
                                       ObjectCreationExpression(vtblName)
                                          .WithArgumentList(
                                               vtblConstructor
                                           )
                                   )
                               );
            }

            members.Add(vtblProperty);

            return ClassDeclaration(shadowClassName)
                  .WithModifiers(
                       ModelUtilities.VisibilityToTokenList(csElement.ShadowVisibility, SyntaxKind.PartialKeyword)
                   )
                  .WithBaseList(
                       BaseList(
                           SingletonSeparatedList<BaseTypeSyntax>(
                               SimpleBaseType(
                                   csElement.Base != null
                                       ? IdentifierName(csElement.Base.ShadowName)
                                       : GlobalNamespace.GetTypeNameSyntax(WellKnownName.CppObjectShadow)
                               )
                           )
                       )
                   )
                  .WithMembers(new SyntaxList<MemberDeclarationSyntax>(members));
        }