SemanticModel.GetSymbolInfoを使用しているときに失敗してしまいますが、使用すると失敗します。 SemanticModel.GetDeclaredSymbol。SemanticModel.GetSymbolInfoと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>()
.First();
//var qu = propertySyntaxNode.q
//var symbolInfo = semanticModel.GetDeclaredSymbol(propertySyntaxNode);
var symbol = semanticModel.GetDeclaredSymbol(propertySyntaxNode) as IPropertySymbol;
var typeInfo = semanticModel.GetTypeInfo(propertySyntaxNode).Type;
}
}
ちょうど展開します。 (これは100%正確ではありませんが、かなり近いです) – JoshVarty