简体   繁体   English

从Roslyn CTP创建的显示方法不正确

[英]Not correct display method created from Roslyn CTP

I want to create new Method using Roslyn CTP. 我想使用Roslyn CTP创建新方法。 I create a new instance type of MethodDeclarationSyntax. 我创建了一个新的实例类型的MethodDeclarationSyntax。

 MethodDeclarationSyntax lMethodDeclarationSyntax = Syntax.MethodDeclaration(
            Syntax.List<AttributeListSyntax>(),
            Syntax.TokenList(
                Syntax.Token(SyntaxKind.PublicKeyword)),
            Syntax.IdentifierName("MemoryStream"),
            null,
            Syntax.Identifier("Serialize"),
            null,
            Syntax.ParameterList(),
            Syntax.List<TypeParameterConstraintClauseSyntax>(),
            Syntax.Block(lList));

But in response i get something like this: 但作为回应我得到这样的东西:

publicMemoryStreamSerialize(){MemoryStream lMemoryStream = new MemoryStream();StreamWriter lStreamWriter = new StreamWriter(lMemoryStream);lStreamWriter.Write(IntVariable);lStreamWriter.Write(ExVariable.ToStream());return lMemoryStream;}  

What i missed? 我错过了什么?

Add NormalizeWhitespace at the end to add normalized whitespace trivia into your tree. 在末尾添加NormalizeWhitespace以将标准化的空白琐事添加到树中。

MethodDeclarationSyntax lMethodDeclarationSyntax =
    Syntax.MethodDeclaration(
        Syntax.List<AttributeListSyntax>(),
        Syntax.TokenList(Syntax.Token(SyntaxKind.PublicKeyword)),
        Syntax.IdentifierName("MemoryStream"),
        null,
        Syntax.Identifier("Serialize"),
        null,
        Syntax.ParameterList(),
        Syntax.List<TypeParameterConstraintClauseSyntax>(),
        Syntax.Block(lList))
    .NormalizeWhitespace();

You can do this to any syntax node and it will return a node with all the whitespace trivia normalized throughout the tree. 您可以对任何语法节点执行此操作,它将返回一个节点,其中所有空白琐事都在整个树中规范化。 Remember that node trees are immutable so it will not have any effect on the already existing tree but will create a new one. 请记住,节点树是不可变的,因此它不会对现有树产生任何影响,但会创建一个新树。

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

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