我在我的 asp.net Web 应用程序中使用详细信息视图。
当它触发其更新和插入的事件时,我想以同样的方式处理它们。因为他们拥有的事件参数是两个没有共同继承的独立类,所以我必须有两个具有基本相同代码的独立方法。
有没有办法解决?
例如。
protected void DetailsViewItemInserted(object sender, DetailsViewInsertedEventArgs e)
{
if (e == null)
return;
if (e.Exception != null)
{
e.ExceptionHandled = HandleException(e.Exception);
e.KeepInInsertMode = e.ExceptionHandled;
}
}
protected void DetailsViewItemUpdated(object sender, DetailsViewUpdatedEventArgs e)
{
if (e == null)
return;
if (e.Exception != null)
{
e.ExceptionHandled = HandleException(e.Exception);
e.KeepInEditMode = e.ExceptionHandled;
}
}
我想提取 if (e == null) return;
if (e.Exception != null)
{
e.ExceptionHandled = HandleException(e.Exception);
e.KeepInEditMode = e.ExceptionHandled;
}
如果可能的话,进入某种常见的方法。