gpt4 book ai didi

c# - System.Action 作为 EventHandler

转载 作者:行者123 更新时间:2023-11-30 19:31:59 25 4
gpt4 key购买 nike

<分区>

反对使用委托(delegate) System.ActionSystem.Func 作为 EventDelegates 而不是经典的 EventHandler 模式的内容。我会因此遇到问题吗?

private bool disposed;

public event Action<IUnitOfWork, IContext> Disposing;

public void Dispose()
{
if (this.disposed)
{
return;
}

if (null != this.Disposing)
{
this.Disposing(this, this.AttachedContext);
}

this.disposed = true;
}

用法:

unitOfWorkInstance.Disposing += (u, c) => c.Rollback(u); // in my opinion more readable than
unitOfWorkInstance.Disposing += (sender, args) => args.AttachedContext.Rollback(sender as IUnitOfWork);

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