Using Roslyn, how would I find the value of the constructor of an attribute? So given the following class with an attribute:
[Example(typeof(ClassFromAnotherDll))]
public class ExampleClass
{
public int JustANumber { get; set; }
}
And the ExampleAttribute would look like so (though the source would not be in the same solution as the one above):
public class ExampleAttribute : Attribute
{
private readonly Type _type;
public ExampleAttribute(Type type)
{
_type = type;
}
}
How would I get information (e.g. properties, constructors) about the ClassFromAnotherDll type?
Call GetAttributes() on any symbol (from the semantic model) to get a list of all applied attributes.
Then look at the ConstructorArguments of the attribute you want.
If the argument is a typeof expression, its Value will be an INamedTypeSymbol.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With