Roslyn Check Type of an Attribute

后端 未结 1 869
天命终不由人
天命终不由人 2021-01-26 21:45

I\'m trying to figure out there proper way to compare attribute data in Roslyn.

static bool ResolveAttributes(IMethodSymbol methodSymbol)
{
    var attributes =          


        
相关标签:
1条回答
  • 2021-01-26 22:18

    AttributeData.AttributeClass gives you the Roslyn symbol for the attribute. But you've got a CLR runtime Type you are trying to compare against. You can either just compare the type names, etc, to see if they are the probably the same type, or get a Roslyn type symbol for MyAttributeType, which is more correct. This is typically done via

    var desiredSymbol = sematicModel.Compilation.GetTypeByMetadataName(typeof(MyAttributeType).FullName)
    
    0 讨论(0)
提交回复
热议问题