가능한 중복 :
.NET: Determine the type of “this” class in its static method정적 메서드에서 비 정적 GetType()을 호출합니까?
안녕하세요 typeof()
를 사용하지 않고 비 정적 클래스의 비 정적 GetType()
를 호출 할 수있는 방법이있다?
다음은 내가 작업중인 코드의 예입니다.
private static ISession GetOrCreate(ISessionFactory factory)
{
if (HttpContext.Current!=null)
{
ISession session = GetExistingWebSession();
if (session == null)
{
session = OpenSessionAndAddToContext(factory);
}
else if (!session.IsOpen)
{
session = OpenSessionAndAddToContext(factory);
} return session;
}
}
private ISession GetExistingWebSession()
{
return HttpContext.Current.Items[GetType().FullName] as ISession;
}
유형을 모르고 유형을 기준으로 객체를 검색하려고합니다. 그게 어떻게 작동할까요? – hvd
왜'typeof'를 사용하지 않으시겠습니까? – Jodrell
왜 처음에는 유형 이름을 키로 사용합니까? – Jodrell