gpt4 book ai didi

c# - Asp.net的AutoEventWireup和反射?

转载 作者:太空狗 更新时间:2023-10-30 01:22:29 24 4
gpt4 key购买 nike

AutoEventWireup 使用 反射 通过 page_eventName 搜索页面方法

msdn

When AutoEventWireup is true, handlers are automatically bound to events at run time based on their name and signature. For each event, ASP.NET searches for a method that is named according to the pattern Page_eventname, such as Page_Load or Page_Init.

问题:

他是否对每个 请求都这样做?

我查看了 Internet 临时文件(在 Microsoft.net 文件夹...)看他是否保存了另一个包含显式处理程序附件的文件 - 和 无法找到任何 .

最佳答案

正如@Marc 所说,ASP.NET 似乎为此使用了缓存。请参阅内部 TemplateControl.HookUpAutomaticHandlers

此方法的一部分使用 dotPeek :

internal void HookUpAutomaticHandlers()
{
...
object obj = TemplateControl._eventListCache[(object) this.GetType()];
if (obj == null)
{
lock (TemplateControl._lockObject)
{
obj = TemplateControl._eventListCache[(object) this.GetType()];
if (obj == null)
{
IDictionary local_1_1 = (IDictionary) new ListDictionary();
this.GetDelegateInformation(local_1_1);
obj = local_1_1.Count != 0 ? (object) local_1_1 : TemplateControl._emptyEventSingleton;
TemplateControl._eventListCache[(object) this.GetType()] = obj;
}
}
}
...

私有(private) GetDelegateInformation 方法负责为控件创建委托(delegate)。TemplateControl._eventListCache 是一个 Hashtable,它包含每个模板控件的委托(delegate)。

那么,回答你的问题:

Does he do it for every request ?

答案是否定的。 ASP.NET 执行一次以填充此 Hashtable,然后使用缓存的值。

关于c# - Asp.net的AutoEventWireup和反射?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13379177/

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