이것이 잘못 표현되었거나 이전에 질문을 받았지만 관련이없는 것으로 보이는 경우 미안합니다. 매우 피곤합니다.하위 클래스의 형질을 얻으십시오
좋아요, 그래서 내가하고자하는 일은 하위 클래스의 인스턴스를 참조해야하는 상황에 대한 서브 클래스에서 내 특성의 가치를 얻는 것이지만 어떤 특성에 대한 정보가없는 것입니다. 사용하고있다. 이것은 내가 코드에서 설명하기가 더 쉽기 때문에 여기에 내가하려고하는 것이있다.
public class TraitUser<T>
{
public void DoThingWithT(T thing)
{
thing.ToString();
}
}
public class TraitInspector
{
public void DoThing()
{
// This is where I run into my issue,
// I need to be able to get the trait that
// an instance of the TraitUser class is using to continue.
TraitUser<> tUser = GetRandomTraitUser()/*Imagine this returns an instance of TraitUser with a random trait, this is where my issue comes in.*/;
}
}
편집 : 일부 부분의 수정이 이제 더 쉽게 이해할 수 있어야합니다.
두 개의 다른 클래스를 썼습니다. 하위 클래스는 무엇입니까? – LPs
제목을 편집했습니다. "[제목에"태그 "가 포함되어 있어야합니까?] (http://meta.stackexchange.com/questions/19190/)"합의가 "아니오, 그렇지 않아야한다"는 것을 참조하십시오. –