public override void SetTypeCode() { var name = Name; var commentlessCode = String.Join(Environment.NewLine, Declaration.GetText().Lines.Select(l => l.ToString())); var usings = Root.DescendantNodes() .OfType <UsingDirectiveSyntax> () .Select(u => u.GetText().ToString()) .ToList(); var deps = Root.DescendantNodes() .OfType <IdentifierNameSyntax>() .Select(n => Model.GetSymbolInfo(n)) .Where(s => s.Symbol != null && s.Symbol.Kind == SymbolKind.NamedType) .Select(n => n.Symbol.Name) .Distinct() .ToList(); var ns = Declaration.Ancestors() .OfType <NamespaceDeclarationSyntax>() .Select(n => n.Name.GetText().ToString().Trim()) .FirstOrDefault() ?? ""; // create an 'instrumented' instance of the document with watch calls var rewriter = new WatchExpressionRewriter(Document.FullPath); var instrumented = rewriter.Visit(Declaration); var instrumentedCode = instrumented.ToString(); // the rewriter collects the WatchVariable definitions as it walks the tree var watches = rewriter.WatchVariables; TypeCode.Set(name, usings, commentlessCode, instrumentedCode, deps, ns, watches); }