我正在开发一个 Visual Studio 2008 插件,该插件将通过查看方法签名以及用户在对话框中输入的一组选项来生成数据访问代码。
为了分析方法签名,我使用 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);
}
它确实解析了非泛型类型,但遗憾的是不适用于泛型类型。有人知道如何使上述代码段也适用于泛型类型吗?