C# 如何使用Roslyn查找属性构造函数参数的值?
使用Roslyn,如何找到属性构造函数的值?因此,给定以下具有属性的类:C# 如何使用Roslyn查找属性构造函数参数的值?,c#,roslyn,C#,Roslyn,使用Roslyn,如何找到属性构造函数的值?因此,给定以下具有属性的类: [Example(typeof(ClassFromAnotherDll))] public class ExampleClass { public int JustANumber { get; set; } } 而ExampleAttribute看起来是这样的(尽管源代码与上面的解决方案不同): 如何从另一个DLL类型中获取有关类的信息(例如属性、构造函数)?调用任何符号(从语义模型)上的GetAttribute
[Example(typeof(ClassFromAnotherDll))]
public class ExampleClass
{
public int JustANumber { get; set; }
}
而ExampleAttribute
看起来是这样的(尽管源代码与上面的解决方案不同):
如何从另一个DLL类型中获取有关类的信息(例如属性、构造函数)?调用任何符号(从语义模型)上的GetAttributes()
,以获取所有应用属性的列表
然后查看您想要的属性的名称
如果参数是typeof
表达式,则其值将是INamedTypeSymbol
public class ExampleAttribute : Attribute
{
private readonly Type _type;
public ExampleAttribute(Type type)
{
_type = type;
}
}