Treeview与深层嵌套的对象?

时间:2016-12-01 12:58:01

标签: c# wpf nested treeview roslyn

所以,我正在尝试更多地了解Roslyn,因此编写了一个帮助我分析解决方案的应用程序。

应该说,我对C#和WPF来说还是比较新的,所以我可能会错过一些重要或明显的东西。

我想在Treeview中显示我的解决方案的结构。 我已经能够将我的解决方案的结构导出到具有如下输出的文本文件:

+ Analysing the following project: Testtool  
|+ Analysing the following document: Converters.cs  
||+ The following namespaces are referenced for the analysed file:  
|||- System  
|||- System.Collections.Generic  
|||- System.Linq  
|||- System.Text  
|||- System.Threading.Tasks  
|||- System.Windows.Data  
||- The file lives in the following namespace: Testtool  
||+ Analysing the following class of the current file: BooleanInverter  
|||+ The following modifiers are used for the class:  
||||- public  
||||- partial  
|||+ The following methods are defined in the currently analysed class:  
||||+ Convert  
|||||+ The following modifiers are used for the method:  
||||||- public  
||||+ ConvertBack  
|||||+ The following modifiers are used for the method:  
||||||- public  
|+ Analysing the following document: LoadingControl.xaml.cs  
||+ The following namespaces are referenced for the analysed file:  
|||- System  
|||- System.Collections.Generic  
|||- System.Linq  
|||- System.Text  
|||- System.Threading.Tasks  
|||- System.Windows  
|||- System.Windows.Controls  
|||- System.Windows.Data  
|||- System.Windows.Documents  
|||- System.Windows.Input  
|||- System.Windows.Media  
|||- System.Windows.Media.Imaging  
|||- System.Windows.Navigation  
|||- System.Windows.Shapes  
|||- System.ComponentModel  
||- The file lives in the following namespace: Testtool  
||+ Analysing the following class of the current file: LoadingControl  
|||+ The following modifiers are used for the class:  
||||- public  
||||- partial  
|||+ The following methods are defined in the currently analysed class:  
||||+ OnPropertyChanged  
|||||+ The following modifiers are used for the method:  
||||||- public  
|||+ The following properties are defined in the currently analysed class:  
||||+ SpinnerText  
|||||+ The following modifiers are used for the Property:  
||||||- public  

现在我不确定在对象中显示这个结构有什么好方法。我的意思是,如果没有更好的可能性,我会创建一个相应的对象模型,但我觉得这种深层嵌套对象的需要感觉不对。 那么,也许有人对此有更好的想法?

1 个答案:

答案 0 :(得分:0)

正如Dudi已经指出的那样,语法Visualizer还提供了一个包含整个语法树的树视图,但是,查看您的控制台输出,似乎您想要显示"裸语法树的摘要" 。实际上,我会选择相应的对象模型,因为您的分析非常总结了语法树,因此您不需要那么多的视图模型。

我没有使用WPF使用树视图的任何经验,但可能只能绑定到顶级视图模型,它代表Solution,并且它的子项返回Project查看模型。使用隐式数据模板将完成剩下的工作。

如果您需要一些示例代码,我很乐意添加。