Reputation: 115
I have a big problem with Roslyn.NET CTP and semantic analysis my code.
My task is: get classdeclaration and his inherited type.
For example:
Class: Change : ChangePassword
I must write in console: "ChangePassword" type name.
How can I do this? In reflection is very simple: (this is a generic type):
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);
}
}
}
But I my problem requires the use roslyn. My idea is use semanticModel.GetTypeInfo or GetSymbolInfo but none of them accepts a parameter SyntaxNode!
My reality class declaration is:
public partial class Example : System.Web.Mvc.WebViewPage<ExampleModel>
for this example I must add to List<string>
"ExampleModel".
Upvotes: 1
Views: 1030
Reputation: 11615
Take a look at using SemanticModel.GetDeclaredSymbol(ClassDeclarationSyntax)
to determine the Symbol
for your type, then inspect the BaseType
property.
Upvotes: 2