SyntaxFactory generates constructor with calling base class constructor

I wrote some code that generates a new class according to the initial state. Roslyn provides a class SyntaxFactory

for it, but I don't understand how to generate a constructor by calling the base class, like this:

public TestClientApi(String entryPoint) : **base(entryPoint)**
{
    _entryPoint = entryPoint;
}

      

https://github.com/ddydeveloper/Roslyn.ApiClient.Codegen

Any idea?

+3


source to share


1 answer


You need to create a constructor declaration using an initializer.



ConstructorDeclaration("TestClientApi")
    .WithInitializer(
        ConstructorInitializer(SyntaxKind.BaseConstructorInitializer)
                // could be BaseConstructorInitializer or ThisConstructorInitializer
            .AddArgumentListArguments(
                Argument(IdentifierName("entryPoint"))
            )
    )
    ...

      

+1


source







All Articles