protected void Run(IScWidget widget) { IHandler handler = null; try { if (s_Handler.TryGetValue(widget.GetType(), out handler)) { handler.Run(Context, widget); } else { FallbackRun(Context, widget); } foreach (var child in widget.GetChildren()) { Run(child); } } finally { if (handler != null) { handler.Finish(Context, widget); } else { FallbackFinish(Context, widget); } } }
protected void Prepare(IScWidget widget) { IHandler handler; if (s_Handler.TryGetValue(widget.GetType(), out handler)) { handler.Prepare(Context, widget); } else { FallbackPrepare(Context, widget); } foreach (var child in widget.GetChildren()) { Prepare(child); } }
void Run <T>(IScWidget widget, Func <TContext, IScWidget, T, IDisposable> func) where T : class { IHandler _handler; s_Handler.TryGetValue(widget.GetType(), out _handler); IDisposable disposable = null; try { if (_handler is T hander) { disposable = func?.Invoke(Context, widget, hander); } foreach (var child in widget.GetChildren()) { Run(child, func); } } finally { disposable?.Dispose(); } }