저는 사용자가 대화 상자에 입력하는 옵션 세트와 결합 된 메서드 서명을보고 데이터 액세스 코드를 생성하는 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);
}
그것은 제네릭이 아닌 형식을 해결 않지만, 슬프게도 일반적인 유형에서 작동하지 않습니다이 들어
나는 다음과 같은 기능을 만들었습니다. 누구나 위의 코드 조각을 일반 형식에서도 사용할 수있는 방법에 대한 아이디어가 있습니까?
의 실제 유형을 지정하지 않고 일반적인 유형을 지정할 수 없습니다 : "System.Collections.ObjectModel.Collection에게" 이것은 '아무튼 올바르게 해결되지 않습니다. 방금 설명한 논리를 적용하면 다음을 시도해 보았습니다. "System.Collections.ObjectModel.Collection'1 [[MyNamespace.Client]]" 그러나 이것은 작동하지 않습니다. –
GetType 메서드를 올바르게 이해하면 실행중인 인스턴스를 매개 변수로 사용하지 않고 형식 이름을 사용할 수 있습니다. 어떻게 실행되는 인스턴스로 변환되는지는 알 수 없습니다. GetType 메서드는 클래스 정의를 통해 해당 형식 정보를 얻을 가능성이 높습니다. –
처음에 Resolve ("MyNamespace.Client")를 호출하고 System.Collections.ObjectModel.Collection'1 [[MyNamespace.Client]]를 해결하면 작동하고 올바른 유형을 얻었습니다. generic 인수에 대한 어셈블리가로드되지 않은 것처럼 보입니다. –