ダミーの名前空間、クラス、サブを作成し、For/Nextループの解析済みステートメントを追加すると、NormalizeWhitespace私の編集単位の方法。ここでコンパイルユニットnormalizewhitespaceが "For"/"Next"ステートメントを解析するとクラッシュする
IndexOutOfRangeException
Index was outside the bounds of the array.
at System.Collections.Immutable.ImmutableArray`1.Builder.get_Item(Int32 index)
at Microsoft.CodeAnalysis.VisualBasic.Syntax.SyntaxNormalizer.GetIdentation(Int32 count)
at Microsoft.CodeAnalysis.VisualBasic.Syntax.SyntaxNormalizer.RewriteTrivia(SyntaxTriviaList triviaList, Int32 depth, Boolean isTrailing, Boolean mustBeIndented, Boolean mustHaveSeparator, Int32 lineBreaksAfter, Int32 lineBreaksBefore)
at Microsoft.CodeAnalysis.VisualBasic.Syntax.SyntaxNormalizer.VisitToken(SyntaxToken token)
at Microsoft.CodeAnalysis.VisualBasic.VisualBasicSyntaxRewriter.VisitEndBlockStatement(EndBlockStatementSyntax node)
at Microsoft.CodeAnalysis.VisualBasic.Syntax.SyntaxNormalizer.VisitEndBlockStatement(EndBlockStatementSyntax node)
at Microsoft.CodeAnalysis.VisualBasic.Syntax.EndBlockStatementSyntax.Accept[TResult](VisualBasicSyntaxVisitor`1 visitor)
at Microsoft.CodeAnalysis.VisualBasic.VisualBasicSyntaxRewriter.Visit(SyntaxNode node)
at Microsoft.CodeAnalysis.VisualBasic.VisualBasicSyntaxRewriter.VisitNamespaceBlock(NamespaceBlockSyntax node)
at Microsoft.CodeAnalysis.VisualBasic.Syntax.SyntaxNormalizer.VisitNamespaceBlock(NamespaceBlockSyntax node)
at Microsoft.CodeAnalysis.VisualBasic.Syntax.NamespaceBlockSyntax.Accept[TResult](VisualBasicSyntaxVisitor`1 visitor)
at Microsoft.CodeAnalysis.VisualBasic.VisualBasicSyntaxRewriter.Visit(SyntaxNode node)
at Microsoft.CodeAnalysis.VisualBasic.VisualBasicSyntaxRewriter.VisitListElement[TNode](TNode node)
at Microsoft.CodeAnalysis.VisualBasic.VisualBasicSyntaxRewriter.VisitList[TNode](SyntaxList`1 list)
at Microsoft.CodeAnalysis.VisualBasic.VisualBasicSyntaxRewriter.VisitCompilationUnit(CompilationUnitSyntax node)
at Microsoft.CodeAnalysis.VisualBasic.Syntax.SyntaxNormalizer.VisitCompilationUnit(CompilationUnitSyntax node)
at Microsoft.CodeAnalysis.VisualBasic.Syntax.CompilationUnitSyntax.Accept[TResult](VisualBasicSyntaxVisitor`1 visitor)
at Microsoft.CodeAnalysis.VisualBasic.VisualBasicSyntaxRewriter.Visit(SyntaxNode node)
at Microsoft.CodeAnalysis.VisualBasic.Syntax.SyntaxNormalizer.Normalize[TNode](TNode node, String indentWhitespace, String eolWhitespace, Boolean useElasticTrivia, Boolean useDefaultCasing)
at Microsoft.CodeAnalysis.VisualBasic.SyntaxExtensions.NormalizeWhitespace[TNode](TNode node, Boolean useDefaultCasing, String indentation, Boolean elasticTrivia)
at UserQuery.Main()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
は再現するコードです:
public void Main()
{
var compilationUnit = SyntaxFactory.CompilationUnit();
compilationUnit = compilationUnit.AddMembers(this.CreateNamespaceDeclaration());
compilationUnit = compilationUnit.NormalizeWhitespace(true, "\r\n", false);
compilationUnit.ToFullString().Dump();
}
public string[] StatementList = { "For i As Integer = 0 To 10", "Dim v = 0", "Next" };
// Define other methods and classes here
private NamespaceBlockSyntax CreateNamespaceDeclaration()
{
return SyntaxFactory.NamespaceBlock(
SyntaxFactory.NamespaceStatement(
SyntaxFactory.IdentifierName("Test")))
.WithMembers(
SyntaxFactory.SingletonList<StatementSyntax>(
SyntaxFactory.ClassBlock(
SyntaxFactory.ClassStatement("VBCrash")
.WithModifiers(
SyntaxFactory.TokenList(
SyntaxFactory.Token(SyntaxKind.PublicKeyword))))
.WithImplements(SyntaxFactory.List<ImplementsStatementSyntax>())
.WithMembers(SyntaxFactory.List<StatementSyntax>(
SyntaxFactory.List<StatementSyntax>()
.Add(SyntaxFactory.SubBlock(
SyntaxFactory.SubStatement("Main"))
.AddStatements(this.AddStatements()))))));
}
private StatementSyntax[] AddStatements()
{
var result = default(SyntaxList<StatementSyntax>);
foreach (var statement in StatementList)
{
result = result.Add(SyntaxFactory.ParseExecutableStatement(statement));
}
return result.ToArray();
}
私が何か間違ったことをやっていますか?文のforeachループにコメントするたびに動作します。
ありがとうございました:)
VB Cal-ciumを生成します。 – stongef