更新时间:2022-12-13 21:42:42
好吧,我会使用语义而不是语法来解决这个问题.像(从我的头顶):
Well, I would go about this using Semantics, not Syntax. Something like (off the top of my head):
var attributeSymbol = compilation.GetTypeByMetadataName("ConsoleApplication1.OneToOneAttribute");
var propertySymbol = compilation.GetTypeByMetadataName("ConsoleApplication1.Program")
.GetMembers()
.Where(m =>
m.Kind == CommonSymbolKind.Property &&
m.GetAttributes().Any(a => a.AttributeClass.MetadataName == attributeSymbol.MetadataName));