在某些情况下,当我试图为我的语法节点获取ISymbol时,我在使用SemanticModel.GetSymbolInfo时失败(变为null)但在使用SemanticModel.GetDeclaredSymbol时成功.
我附上了一个例子.
所以我的问题是何时使用每种方法来获取语义模型?
public class Class1
{
public System.String MyString { get; set; }
public static void Main()
{
var str =
@"
namespace ClassLibrary31
{
public class Class1
{
public System.String MyString { get; set; }
}
}";
var syntaxTree = SyntaxFactory.ParseSyntaxTree(str);
MetadataReference[] metadataReferenceReferences = new MetadataReference[]
{
MetadataReference.CreateFromFile(typeof(object).Assembly.Location),
};
var compilation =
CSharpCompilation
.Create("TraceFluent",
new[] {syntaxTree},
options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, warningLevel:1),
references: metadataReferenceReferences
);
var temp = compilation.Emit("temp");
var semanticModel = compilation.GetSemanticModel(syntaxTree, true);
PropertyDeclarationSyntax propertySyntaxNode =
syntaxTree.GetRoot()
.DescendantNodes()
.OfType<PropertyDeclarationSyntax>() …Run Code Online (Sandbox Code Playgroud) 我正在寻找一个wpf控件(免费或商业).树应支持所有常规树视图特性(样式,数据模板,控件模板......),并支持使用Columns布局(类似于Visual Studio中的Watch窗口).
但是也:
我不想自己构建树,我正在寻找现有的实现,至少支持虚拟化和数据虚拟化.