使用 Roslyn,我如何找到属性构造函数的值?因此给定以下具有属性的类:
[Example(typeof(ClassFromAnotherDll))]
public class ExampleClass
{
public int JustANumber { get; set; }
}
ExampleAttribute
看起来像这样(尽管源代码与上面的解决方案不同):
public class ExampleAttribute : Attribute
{
private readonly Type _type;
public ExampleAttribute(Type type)
{
_type = type;
}
}
我如何获取有关 ClassFromAnotherDll
类型的信息(例如属性、构造函数)?
最佳答案
对任何符号(来自语义模型)调用 GetAttributes()
以获取所有应用属性的列表。
然后看ConstructorArguments
您想要的属性。
如果参数是一个 typeof
表达式,它的 Value
将是一个 INamedTypeSymbol
。
关于c# - 如何使用 Roslyn 查找属性构造函数参数的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41018052/