How do I: Get a IClassDeclaration from a string

Hi

If I have a string containing the fully qualified name of the a class, e.g.
"MyNamespace.MyClass", how do I get the corresponding IClassDeclaration?


Something like:

IClassDeclaration classDeclaration = MySolution.GetClassDeclaration("MyNamespace.MyClass");


Thanks
--Jakob


1 comment
Comment actions Permalink

Jakob,

This is actually somewhat complicated process.
First, you have to obtain a declarations cache:

IDeclarationsCache cache =
PsiManager.GetInstance(solution).GetDeclarationsCache(DeclarationsCacheScope.SolutionScope(solution,
true), true);

DeclarationsCache gives you types by their qualified names:

ITypeElement typeElement = cache.GetTypeElementByCLRName("MyNamespace.MyClass");

Now, you can get decarations from type element:

IList]]> decls = typeElement.GetDeclarations();

Hope this helps,
Friendly,
Dmitry

Hi

If I have a string containing the fully qualified name of the a class,
e.g. "MyNamespace.MyClass", how do I get the corresponding
IClassDeclaration?

Something like:

IClassDeclaration classDeclaration =
MySolution.GetClassDeclaration("MyNamespace.MyClass");

Thanks
--Jakob

--
Dmitry Lomov
Technical Lead/Software Architect
JetBrains, Inc.
"Develop With Pleasure!"


0

Please sign in to leave a comment.