【发布时间】:2012-04-24 15:03:40
【问题描述】:
可能重复:
.NET: Determine the type of “this” class in its static method
您好,有什么方法可以在不使用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;
}
【问题讨论】:
-
您试图通过对象的类型来查找对象,但不知道它的类型。这应该如何工作?
-
你为什么不想使用
typeof? -
为什么首先使用类型名称作为您的键?
-
你想得到什么
Type?
标签: c# .net types typeof gettype