我正在将.net 4.7项目移植到.net标准,它使用T4生成一些代码。我遍历类,属性和方法。这种用法可以很好地工作,但是现在DTE的返回类型是'System .__ ComObject'类型,我无法投射它们。
Error: Unable to cast COM object of type 'System.__ComObject' to interface type 'EnvDTE.CodeClass'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{B1F42514-91CD-4D3A-8B25-A317D8032B24}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
任何想法如何解决这个问题?
示例:
public static bool CheckBase(CodeClass codeClass, string baseName)
{
var bases = codeClass.Bases;
if (bases != null)
{
foreach (CodeClass baseClass in bases)
{
if(baseClass.Name == baseName) return true;
}
}
return false;
}