gpt4 book ai didi

c# - 在静态方法中调用非静态 GetType()?

转载 作者:太空宇宙 更新时间:2023-11-03 20:26:56 24 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
.NET: Determine the type of “this” class in its static method

你好,有什么方法可以在非静态类中调用非静态 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;
}

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com