2009-06-22 3 views
1

저는 사용자가 대화 상자에 입력하는 옵션 세트와 결합 된 메서드 서명을보고 데이터 액세스 코드를 생성하는 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); 
} 

그것은 제네릭이 아닌 형식을 해결 않지만, 슬프게도 일반적인 유형에서 작동하지 않습니다이 들어

나는 다음과 같은 기능을 만들었습니다. 누구나 위의 코드 조각을 일반 형식에서도 사용할 수있는 방법에 대한 아이디어가 있습니까?

답변

2

제네릭 형식의 형식은 런타임시 형식 매개 변수의 형식입니다. 디자인 타임에 매개 변수가 지정되지 않았기 때문에 제네릭 형식에는 형식이 없습니다. GetType이 호출 될 때 클래스 인스턴스가 없으므로 아마 작동하지 않을 것입니다.

제네릭 형식이 인수로 사용되는 것을 방지하는 것과 같은 이유입니다. 당신은 그러나 내가 해결하기 위해 다음과 같은 유형을 지정하고있어, 올바른 년대 T.

+0

의 실제 유형을 지정하지 않고 일반적인 유형을 지정할 수 없습니다 : "System.Collections.ObjectModel.Collection에게 " 이것은 '아무튼 올바르게 해결되지 않습니다. 방금 설명한 논리를 적용하면 다음을 시도해 보았습니다. "System.Collections.ObjectModel.Collection'1 [[MyNamespace.Client]]" 그러나 이것은 작동하지 않습니다. –

+0

GetType 메서드를 올바르게 이해하면 실행중인 인스턴스를 매개 변수로 사용하지 않고 형식 이름을 사용할 수 있습니다. 어떻게 실행되는 인스턴스로 변환되는지는 알 수 없습니다. GetType 메서드는 클래스 정의를 통해 해당 형식 정보를 얻을 가능성이 높습니다. –

+0

처음에 Resolve ("MyNamespace.Client")를 호출하고 System.Collections.ObjectModel.Collection'1 [[MyNamespace.Client]]를 해결하면 작동하고 올바른 유형을 얻었습니다. generic 인수에 대한 어셈블리가로드되지 않은 것처럼 보입니다. –

관련 문제