public static void AddOrSelectTool <T>(this IPerspective me, Func <T> factory) where T : IToolViewModel { var currentTool = me.Tools.FirstOrDefault(t => t is T); if (currentTool != default) { me.SelectedTool = currentTool; } else { me.AddTool(factory()); } }
public static void AddOrSelectTool <T>(this IPerspective me, T tool) where T : IToolViewModel { var currentTool = me.Tools.FirstOrDefault(t => t.Equals(tool)); if (currentTool != null) { me.SelectedTool = currentTool; } else { me.AddTool(tool); } }