Visual Studio プロジェクト タイプ - Stand-Alone Code Analysis Tool を使用しています。次のコードを使用していますが、ToString() が予期しない結果を示しています。
static void Main(string[] args)
{
var classDoc = @"public class SomeClass{
private SomeOtherClass someOtherClass;
}";
SyntaxTree classTree=SyntaxFactory.ParseSyntaxTree(classDoc);
var classDecl = (ClassDeclarationSyntax)classTree.GetRoot().DescendantNodes()
.First(d => d is ClassDeclarationSyntax);
var field = classDecl.Members.OfType<FieldDeclarationSyntax>().First();
var fieldType = field.Declaration.Type;
var newFieldType = SyntaxFactory.ParseName("System.Windows.Forms.UserControl");
var newField=field.ReplaceNode(fieldType, newFieldType);
var newFieldStr = newField.ToString();
}
の値newFieldStr
は
private System.Windows.Forms.UserControlsomeOtherClass;
期待される結果を得る方法を教えてください。