I have an attribute I'm generating that contains a couple of constructor arguments, a string and a Type, and I'd really like to get the namespace of the Type, because I need to include that in the generated source when using the actual Type.
The attribute is like:
public MyCustomAttribute : Attribute
{
public MyCustomAttribute(string info, Type type)
{
//...
}
}
My Roslyn code where I'm struggling is:
private void Foo(SemanticModel model, SyntaxNode node)
{
if(model.GtDeclaredSymbol(node) is not INamedTypeSymbol symbol)
{
return null;
}
var attributeData = symbol.GetAttributes().First(x => AttributeClass.Name == "MyCustomAttribute");
var stringdata = (string)attributeData.ConstructorArguments[0].Value; //this works fine
var typedata = (INamedTypeSymbol)attributeData.ConstructorArguments[1].Value;
var typeName = typedata.MetadataName; // works to get the actual type name
var typeNamespace = typedata.ContainingNamespace.Name; // This is an empty string?
//...
}