문제

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 );
    }
}
도움이 되었습니까?

해결책

Turns out the correct property of CodeInterface to use is .Members (which is still an enumerable set of CodeElements)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top