简体   繁体   English

SyntaxFactory使用调用基类构造函数生成构造函数

[英]SyntaxFactory generate constructor with calling base class constructor

I wrote code which generates a new class in accordance with an initial state. 我编写的代码根据初始状态生成一个新类。 Roslyn provides the class SyntaxFactory for it, but I don't understand how to generate a constructor by calling the base class, like this: Roslyn为它提供了类SyntaxFactory ,但是我不知道如何通过调用基类来生成构造函数,如下所示:

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

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

Any idea? 任何的想法?

You need to create your constructor declaration with an initializer. 您需要使用初始化程序创建构造函数声明。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM