Identify if class is abstract with Roslyn

南笙酒味 提交于 2019-12-14 03:49:47

问题


I've searched here I didn't find the answer here.

How can I know if class is a abstract class from a ClassDeclarationSyntax.

Here is my code:

public override void VisitClassDeclaration(ClassDeclarationSyntax node)
{
    var className = node.Identifier.Text;
    var namespaceName = (node.Parent as NamespaceDeclarationSyntax)?.Name.ToString();
    var isAbastract = ??????
}

回答1:


I've found the answer. here is the code:

public override void VisitClassDeclaration(ClassDeclarationSyntax node)
{
    var className = node.Identifier.Text;
    var namespaceName = (node.Parent as NamespaceDeclarationSyntax)?.Name.ToString();

    var isAbstract = node.Modifiers.Any(x => x.IsKind(SyntaxKind.AbstractKeyword));
}


来源:https://stackoverflow.com/questions/48833833/identify-if-class-is-abstract-with-roslyn

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!