Rolsyn无法获取baseType

时间:2018-11-12 08:49:28

标签: c# roslyn

如果扩展自己创建的类,则无法获取基类描述。 如果直接扩展Controller,则可以获得基类描述。 Roslyn版本2.9.0。 我将Roslyn版本从1.1.0升级到了2.9.0。

namespace BrnMall.Web.MallAdmin.Controllers
{
    class ModelOptionalRequiredPropertiesAnalyzer_R1 : BaseTest
    {
        [HttpPost]
        public void Ac() {
        }
    }
}

namespace BrnMall.Web.MallAdmin.Controllers
{
    class BaseTest : Controller 

    {

    }
}

 var methodSymbol = semanticModel.GetDeclaredSymbol(methodDeclarationSyntax) as IMethodSymbol;
                    if (methodSymbol == null)
                        continue;
//Cannot get to base class
                    IEnumerable<ITypeSymbol> iTypes = methodSymbol.ContainingType.GetAllTypes();

 public static IEnumerable<ITypeSymbol> GetAllTypes(this ITypeSymbol typeSymbol)
        {
            while (typeSymbol.BaseType != null)
            {
                yield return typeSymbol;
                typeSymbol = typeSymbol.BaseType;
            }
        }

0 个答案:

没有答案