2010-06-13 14 views
0

나는 런타임시 추상 클래스의 파생 클래스를 동적으로 생성하는 라이브러리를 작성 중이다. 파생 클래스의 생성자는 기본 클래스 생성자 중 MethodInfo이 필요하므로 호출 할 수 있습니다. 그러나 어떤 이유로 Type.GetConstructor()null을 반환합니다. 내가 명시 적으로 Test에서 생성자를 선언 할 경우에도리플렉션을 사용하여 기본 생성자를 얻는 방법은 무엇입니까?

abstract class Test 
{ 
    public abstract void F(); 
} 

public static void Main(string[] args) 
{ 
    ConstructorInfo constructor = typeof(Test).GetConstructor(
     BindingFlags.NonPublic | BindingFlags.Public, 
     null, System.Type.EmptyTypes, null); // returns null! 
} 

null 반환 GetConstructor 것을, 그리고 테스트 추상적없는 경우에도 예를 들면 다음과 같습니다.

답변

0

알아 냈어. BindingFlags.Instance 플래그를 잊어 버렸습니다.

이상한 것은

ConstructorInfo constructor = typeof(Test).GetConstructor(System.Type.EmptyTypes); 

반환 널 (null)이다. 결함이 있습니까?

관련 문제