I'm working on a visual studio 2008 add-in that will generate data-access code by looking at the method signature combined with a set of options the user enters in a dialog.
For analyzing the method signature I use the ITypeResolutionService of visual studio to lookup a type that either exists in the current project, in the referenced projects or in the referenced assemblies.
For this I created the following functionality:
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);
}
It does resolve non-generic types, but sadly doesn't work on generic types. Does anybody have an idea on how to get the above snippet working for generic types too?