2013-07-09 114 views
1

我对Roslyn.NET CTP和语义分析我的代码有一个很大的问题。
我的任务是:获得classdeclaration和他的继承类型。
例如:
类别:更改:ChangePassword
我必须在控制台中写入:“ChangePassword”类型名称。
我该怎么做?反射非常简单:(这是一个通用类型):Roslyn语义分析

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”。

回答

2

看看使用SemanticModel.GetDeclaredSymbol(ClassDeclarationSyntax)确定Symbol你的类型,然后检查BaseType财产。