나는의 DependsOn을 implemnts 기본 클래스() 나는이 기본 클래스를 확장 한제네릭 형식을 사용할 때 기본 클래스 대신 상속 된 클래스에서 메서드를 호출하려면 어떻게해야합니까?
public class Entity
{
protected Entity() { }
public virtual List<Type> DependsOn()
{
return new List<Type>();
}
}
있습니다.
public class Waveform : Entity
{
public virtual new List<Type> DependsOn()
{
return new List<Type> {typeof(Scenario)};
}
}
나는 그 대신 상속 클래스의 기본 클래스에서의 DependsOn 메서드를 호출 (대신이 빈리스트가 반환, 다음 코드는 "새 목록 {대해서 typeof (시나리오)}"를 반환 할 것으로 예상합니다. I를 뿐만 아니라 디버거를 사용하여이 문제를 확인했습니다.)
public virtual List<Entity> FindParents<T>(T possibleChild) where T : Entity
{
List<Type> dependsOnTypes = possibleChild.DependsOn();
}
public void DeleteEntity<T>(T entity) where T : Entity
{
List<Entity> parents = FindParents<T>(entity);
}
Waveform waveform = new Waveform();
DeleteEntity<Waveform>(waveform);
어떤 이유로 그것을 : 아래 그림과 같이 유일한 방법은 원래의 형식으로
대신 개체의, 그 다음 올바른 버전을 호출합니다, 당신은 파형 객체를 사용하는 것입니다 원하는 올바른 방법을 호출 "기본 클래스에서 같은 이름을 가진 함수와 관련이없는 것"이라고 말할 때까지 실제로 클릭하지 않았습니다. – Miebster