1

我对 Roslyn.NET CTP 和我的代码进行语义分析有一个大问题。
我的任务是:获取类声明和他继承的类型。
例如:
Class: Change : ChangePassword
我必须在控制台中写入:“ChangePassword”类型名称。
我怎样才能做到这一点?在反射中很简单:(这是一个泛型类型):

foreach (Type t in types)
        {
            if (t.BaseType.IsGenericType)
            {
                Type[] typeArguments = t.BaseType.GetGenericArguments();

                foreach (Type tParam in typeArguments)
                {
                    typesList.Add(tParam.Name);
                    typesListProperties = tParam.GetProperties();

                    foreach (var p in typesListProperties)
                        typesListPropertiesList.Add(p.Name);                     
                }

            }

        }

但我的问题需要使用 roslyn。我的想法是使用 semanticModel.GetTypeInfo 或 GetSymbolInfo 但它们都不接受参数 SyntaxNode!

我的现实课声明是:

public partial class Example : System.Web.Mvc.WebViewPage<ExampleModel>

对于这个例子,我必须添加到List<string>“ExampleModel”。

4

1 回答 1

2

查看 usingSemanticModel.GetDeclaredSymbol(ClassDeclarationSyntax)以确定Symbol您的类型,然后检查BaseType属性。

于 2013-07-09T14:55:42.250 回答