How do I get information on a base element? .Children throws NotImplementedException
-
27-06-2021 - |
Question
I am using Visual Studio's CodeModel to gather information on interfaces in the code.
I am able to successfully gather information about the interface using the type CodeInterface
. This interface exposes a property Bases, which allows me to discover what interfaces my interface inherits from.
However, while I am able to step through the properties or methods of my initial interface using .Children
. I cannot do the same for the parent interfaces ( a NotImplementedException
is thrown).
Initially I believed this problem to be because I was using FileCodeModel, so I switched to Project.CodeModel
:
FileCodeModel fileCM =
_applicationObject.ActiveDocument.ProjectItem.FileCodeModel;
My Code:
CodeModel CM = _applicationObject.ActiveWindow.Project.CodeModel;
CodeInterface myInterface =
(CodeInterface)CM.CodeTypeFromFullName( "ConsoleApplication8.IWrapper" );
foreach( CodeElement cE in myInterface.Bases ) {
if( cE is CodeInterface ) {
string itemName = cE.FullName;
CodeInterface parentInterface =
(CodeInterface)CM.CodeTypeFromFullName( itemName );
}
}
La solution
Turns out the correct property of CodeInterface
to use is .Members
(which is still an enumerable set of CodeElements
)