Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用Roslyn查找属性构造函数参数的值?_C#_Roslyn - Fatal编程技术网

C# 如何使用Roslyn查找属性构造函数参数的值?

C# 如何使用Roslyn查找属性构造函数参数的值?,c#,roslyn,C#,Roslyn,使用Roslyn,如何找到属性构造函数的值?因此,给定以下具有属性的类: [Example(typeof(ClassFromAnotherDll))] public class ExampleClass { public int JustANumber { get; set; } } 而ExampleAttribute看起来是这样的(尽管源代码与上面的解决方案不同): 如何从另一个DLL类型中获取有关类的信息(例如属性、构造函数)?调用任何符号(从语义模型)上的GetAttribute

使用Roslyn,如何找到属性构造函数的值?因此,给定以下具有属性的类:

[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;
    }
}