可能重复:
.NET:在其静态方法中确定“this”类的类型
您好,有什么方法可以GetType()
在非静态类中调用非静态而不使用typeof()
?
这是我正在处理的代码示例。
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;
}