ITypeResolutionService不解析任何类型
问题描述:
我正在研究一个visual studio 2008加载项,它将通过查看方法签名以及用户在对话框中输入的一组选项,生成数据访问代码。ITypeResolutionService不解析任何类型
为了分析方法签名,我使用visual studio的ITypeResolutionService来查找当前项目中,引用项目或引用程序集中存在的类型。
为此,我创建了以下功能:
private ITypeResolutionService _typeResolutionService;
private ITypeDiscoveryService _typeDiscoveryService;
/// <summary>
/// Initializes a new instance of the TypeResolver class.
/// </summary>
public TypeResolver(VisualStudioServiceProvider serviceProvider, Project project)
{
IVsSolution solution = serviceProvider.GetService<IVsSolution>();
DynamicTypeService typeResolver = serviceProvider.GetService<DynamicTypeService>();
IVsHierarchy hierarchy = null;
solution.GetProjectOfUniqueName(project.UniqueName, out hierarchy);
_typeResolutionService = typeResolver.GetTypeResolutionService(hierarchy);
_typeDiscoveryService = typeResolver.GetTypeDiscoveryService(hierarchy);
}
/// <summary>
/// Resolves a type in the current solution
/// </summary>
/// <param name="name">Name of the type to resolve</param>
/// <returns>Returns the resolved type; otherwise null</returns>
public Type Resolve(string name)
{
return _typeResolutionService.GetType(name, true);
}
它解决非泛型类型,但遗憾的是并没有泛型类型的工作。 有没有人有关于如何获得上述片段工作的泛型类型的想法呢?
答
泛型类型是运行时类型参数的类型。在设计时,泛型类型没有类型,因为尚未指定参数化类型。这可能不起作用,因为在调用GetType时不存在类实例。
这与阻止泛型被用作参数的原因是一样的。没有指定实际类型的T.
这是正确的,你不能指定一个泛型类型,但是我指定要解决以下类型: “System.Collections.ObjectModel.Collection” 这没有按” t正确解析。应用刚刚描述的逻辑我也试过以下内容: “System.Collections.ObjectModel.Collection`1 [[MyNamespace.Client]]” 但是这也行不通。 –
2009-06-23 06:33:17