ui: Add theme picker ui and stock dark theme

This commit is contained in:
John Colvin committed 2022-07-08 23:42:22 -04:00
1 parent 2b94a29963
commit a3968bd35b
20 files changed
+390 -18

No files matched your search

@@ -34,6 +34,7 @@ namespace mbts.persist {
_instance_settings = instance_settings;
_get = get;
_set = set;
hub.request_clear_instance_settings += () => instance_settings = null;
}
public T instance_settings {
@@ -6,6 +6,7 @@ namespace mbts.spark {
using bts.shell.orderbook;
using bts.shell.pnl;
using bts.shell.time_and_sales;
using bts.utils;
using Google.Protobuf.WellKnownTypes;
@@ -75,6 +76,11 @@ namespace mbts.spark {
[ProtoMember(13)]
GlobalAlertSettings? _alerts;
/// Actual settings may deviate from those of the theme <see cref="_last_picked_theme"/>, as
/// the user is free to change specific properties after selecting a theme.
[ProtoMember(15)]
string? _last_picked_theme;
public UserSettings() { }
public LadderSettings ladder =>
@@ -116,6 +122,8 @@ namespace mbts.spark {
public GlobalAlertSettings alerts =>
_alerts ??= new GlobalAlertSettings();
public string? last_picked_theme => _last_picked_theme;
public UserSettings with(
LadderSettings? ladder = null,
LadderSettingsProfile[]? ladder_profiles = null,
@@ -127,7 +135,8 @@ namespace mbts.spark {
GridSettings? reconcile_report = null,
PNLSettings? pnl = null,
OrderBookGridSettings? order_book_grid = null,
GlobalAlertSettings? alerts = null) {
GlobalAlertSettings? alerts = null,
Optional<string?> last_picked_theme = default) {
var us = new UserSettings() {
_ladder_profiles = ladder_profiles ?? _ladder_profiles,
_ladder = ladder ?? _ladder,
@@ -139,7 +148,8 @@ namespace mbts.spark {
_reconcile_report = reconcile_report ?? _reconcile_report,
_pnl = pnl ?? _pnl,
_order_book = order_book_grid ?? _order_book,
_alerts = alerts ?? _alerts
_alerts = alerts ?? _alerts,
_last_picked_theme = last_picked_theme.or(_last_picked_theme)
};
us._last_ladder_profile_id = Math.Max(_last_ladder_profile_id, us.ladder_profiles.Select(p => p.id).MaxOrDefault());
return us;
@@ -6,12 +6,15 @@ using bts.utils;
using mbts.spark;
using mbts.ui.settings;
using Spark.Settings;
using System;
using System.Collections.Generic;
using System.Composition;
using System.Linq;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using System.Threading;
using System.Threading.Tasks;
namespace mbts.persist {
@@ -35,14 +38,18 @@ namespace mbts.persist {
readonly object _default_settings_lock = new object();
readonly BehaviorSubject<UserSettings> _default_settings_subject = new BehaviorSubject<UserSettings>(UserSettings.factory_defaults);
// A 'settings theme' is activated by updating the default settings object, and clearing all
// 'instance' settings so existing windows adopt the new theme (i.e., the new defaults).
readonly IEnumerable<IFillsGridSettingsMigrationRule> _fills_migration_rules;
readonly IEnumerable<IMarketViewGridSettingsMigrationRule> _mview_migration_rules;
readonly IEnumerable<IPNLSettingsMigrationRule> _pnl_migration_rules;
readonly IEnumerable<ISyntheticManagementMigrationRule> _synth_migration_rules;
readonly IEnumerable<IReconcileReportMigrationRule> _reconcile_report_migration_rules;
readonly IUserPersist _persist;
readonly Dictionary<string, UserSettingsTheme> _themes;
UserSettings _default_settings;
IDisposable _theme_op = null;
[ImportingConstructor]
public UserSettingsHub(
@@ -52,7 +59,8 @@ namespace mbts.persist {
[ImportMany] IEnumerable<IPAndLGridSettingsMigrationRule> pandl_migration_rules,
[ImportMany] IEnumerable<IPNLSettingsMigrationRule> pnl_migration_rules,
[ImportMany] IEnumerable<ISyntheticManagementMigrationRule> synth_migration_rules,
[ImportMany] IEnumerable<IReconcileReportMigrationRule> reconcile_report_migration_rules) {
[ImportMany] IEnumerable<IReconcileReportMigrationRule> reconcile_report_migration_rules,
[ImportMany] IEnumerable<UserSettingsTheme> themes) {
//
_persist = persist;
_fills_migration_rules = fills_migration_rules ?? Enumerable.Empty<IFillsGridSettingsMigrationRule>();
@@ -60,6 +68,7 @@ namespace mbts.persist {
_pnl_migration_rules = pnl_migration_rules ?? Enumerable.Empty<IPNLSettingsMigrationRule>();
_synth_migration_rules = synth_migration_rules ?? Enumerable.Empty<ISyntheticManagementMigrationRule>();
_reconcile_report_migration_rules = reconcile_report_migration_rules.empty_if_null();
_themes = themes.ToDictionaryCrushed(t => t.name);
init();
async void init() {
UserSettings s;
@@ -107,9 +116,26 @@ namespace mbts.persist {
}
}
public event Action request_clear_instance_settings {
add {
lock (_default_settings_lock) {
_request_clear_instance_settings += value;
}
}
remove {
lock (_default_settings_lock) {
_request_clear_instance_settings -= value;
}
}
}
event Action _request_clear_instance_settings;
// indicates whether or not the settings have been loaded from the server (this happens once, on startup - see the constructor for details)
public bool initialized { get; private set; }
public IEnumerable<UserSettingsTheme> themes =>
_themes.Values;
internal UserSettings current {
get {
lock (_default_settings_lock)
@@ -152,18 +178,41 @@ namespace mbts.persist {
_reconcile_report_migration_rules,
_reconcile_report_propi);
public async Task save_default(UserSettings value) {
// notify observers before persisting so the changes are reflected immediately in the ui
public async Task save_default(UserSettings value, bool clear_instance_settings = false) {
// * Notify observers before persisting so the changes are reflected immediately in the ui.
// * If instance settings are to be cleared, don't clear them until the new defaults are
// ready. We want to avoid the case where windows w/ instance settings consume cpu
// loading the original defaults, just to load the new defaults immediately after that.
lock (_default_settings_lock) {
Disposable.dispose(ref _theme_op);
if (clear_instance_settings) {
clear_instance_async().ignore();
}
_default_settings_subject.OnNext(_default_settings = value);
}
await _persist_async();
async Task clear_instance_async() {
var cts = new CancellationTokenSource();
_theme_op = Disposable.Create(() => cts.Cancel());
var next = await _default_settings_subject.Skip(1).FirstOrDefaultAsync();
if (!cts.IsCancellationRequested) {
_request_clear_instance_settings?.Invoke();
}
}
}
IWindowSettingsManager<T> _create_settings_manager<T>(T instance_settings, IEnumerable<ISettingsMigrationRule<T>> migration_rules, IImmutableProperty<UserSettings, T> propi) where T : class {
if (instance_settings != null && migration_rules.merge().apply(instance_settings, out var new_settings))
instance_settings = new_settings;
return new WindowSettingsManager<T>(this, instance_settings, propi.get, propi.set);
var wsm = new WindowSettingsManager<T>(this, instance_settings, propi.get, propi.set);
lock (_default_settings_lock) {
request_clear_instance_settings += clear_instance_settings;
}
return wsm;
void clear_instance_settings() {
wsm.instance_settings = null;
}
}
async Task _persist_async() {
@@ -0,0 +1,36 @@
#nullable enable
namespace Spark.Settings {
using mbts.spark;
using System.Composition;
class UserSettingsTheme {
public UserSettingsTheme() {
name = string.Empty;
value = new();
}
public UserSettingsTheme(string name, UserSettings value) {
this.name = name;
this.value = value;
}
public string name { get; }
public UserSettings value { get; }
}
class ExportedThemes {
[Export]
public UserSettingsTheme light_theme =>
new("Light", UserSettings.factory_defaults);
[Export]
public UserSettingsTheme dark_theme =>
new("Dark", UserSettings.factory_defaults.with(
market_view: bts.shell.market_view.MarketViewSettings.dark_theme_grid_settings,
time_and_sales: bts.shell.time_and_sales.TimeAndSalesSettings.dark_theme_grid_settings,
fills: bts.shell.fills.FillsSettings.dark_theme_grid_settings,
synthetic_management: bts.shell.SyntheticManagementSettings.dark_theme_grid_settings,
ladder: LadderSettings.dark_theme));
}
}
@@ -38,6 +38,26 @@ namespace bts.shell.market_view {
public static GridSettings DefaultGridSettings =>
GridSettings.Default.with(DefaultColumns.all, DefaultColumns.default_sorting_criteria, enable_background_color: true);
public static GridSettings dark_theme_grid_settings =>
DefaultGridSettings.with(
selection_highlight: BTSDarkColors.selection_highlight.argb_color(),
background: BTSDarkColors.background.argb_color(),
font_color: BTSDarkColors.foreground.argb_color(),
columns: DefaultColumns.all.Select(c => {
Color? fg = c.strong_id<Columns>() switch {
Columns.Ask or Columns.AskDirectQty or Columns.AskMergedQty or Columns.AskImpliedQty or Columns.WorkingAsks => BTSDarkColors.ask_foreground,
Columns.Bid or Columns.BidDirectQty or Columns.BidMergedQty or Columns.BidImpliedQty or Columns.WorkingBids => BTSDarkColors.bid_foreground,
_ => null,
};
Color? bg = c.strong_id<Columns>() switch {
Columns.Ask or Columns.Bid => BTSDarkColors.dark_background,
_ => null
};
return c.with(
background_color_override: new(bg),
font_color_override: new(fg));
}));
public static fills.FillsSettings DefaultAuxiliaryFills {
get {
var grid = fills.FillsSettings.MiniGridSettings;
@@ -41,6 +41,12 @@ namespace bts.shell.time_and_sales {
public static GridSettings DefaultGridSettings =>
GridSettings.Default.with(DefaultColumns.all, DefaultColumns.default_sorting_criteria);
public static GridSettings dark_theme_grid_settings =>
DefaultGridSettings.with(
selection_highlight: BTSDarkColors.selection_highlight.argb_color(),
background: BTSDarkColors.background.argb_color(),
font_color: BTSDarkColors.foreground.argb_color());
[ProtoMember(1)]
public SecurityCriteria? security_criteria { get; }
@@ -8,12 +8,17 @@ using mbts.spark;
using mbts.ui;
using mbts.ui.shell;
using mbts.ui.spark;
using mbts.ui.utility;
using Spark.Settings;
using Spark.View;
using System;
using System.Collections.Generic;
using System.Composition;
using System.IO;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
namespace bts.ui {
@@ -30,7 +35,9 @@ namespace bts.ui {
ws_model = ws;
var actions_list = new List<SparkCommand>(2) {
SparkCommands.ShowGlobalAlerts,
SparkCommands.ShowWorkspaces
SparkCommands.ShowWorkspaces,
new SparkCommandCommand(
"Choose Theme", Icons.ViewSettings, new DialogCommand(mk_theme_picker_dialog, -60, -40))
};
if (Configuration.get<bts.config.toggles.ToastNotifications>().enabled) {
actions_list.Add(SparkCommands.ShowSettings);
@@ -46,6 +53,21 @@ namespace bts.ui {
}));
_bus = bus;
Window mk_theme_picker_dialog() {
var model = new ThemePickerModel(settings_hub);
var vm = new ThemePickerVM(model);
var view = new ThemePickerView() { };
var win = new Window() {
DataContext = vm,
Content = view,
Title = "Choose Theme",
SizeToContent = SizeToContent.WidthAndHeight,
Style = Application.Current.FindResource("BTSDialog") as Style
};
vm.RequestClose += (s, e) => WindowUtilities.force_close(win);
return win;
}
}
public ImageSource icon => Icons.Admin;
@@ -0,0 +1,38 @@
#nullable enable
namespace Spark.Settings {
using bts;
using mbts.persist;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Linq;
using System.Threading.Tasks;
class ThemePickerModel {
readonly UserSettingsHub _settings_hub;
public ThemePickerModel(UserSettingsHub settings_hub) =>
_settings_hub = settings_hub;
public IObservable<UserSettingsTheme?> selected_theme =>
_settings_hub.subscribe_default_settings()
.Select(us => _settings_hub.themes.FirstOrDefault(t => t.name == us.last_picked_theme))
.DistinctUntilChanged();
public IEnumerable<UserSettingsTheme> themes =>
_settings_hub.themes;
public async Task<bool> set_theme(UserSettingsTheme theme) {
try {
Log.Gen.info($"Applying settings theme '{theme.name}'");
await _settings_hub.save_default(theme.value, true);
return true;
} catch (Exception ex) {
Log.Gen.error($"Error applying theme '{theme.name}': {ex}");
}
return false;
}
}
}
@@ -0,0 +1,52 @@
#nullable enable
namespace Spark.Settings {
using bts;
using bts.collections;
using mbts;
using mbts.ui;
using mbts.ui.shell;
using System;
using System.Collections.ObjectModel;
using System.Reactive.Linq;
using System.Threading.Tasks;
using System.Windows.Input;
class ThemePickerVM : DisposableViewModelBase, IRequestViewClose {
readonly ThemePickerModel _model;
readonly Property<UserSettingsTheme?> _selected_theme;
public ThemePickerVM(ThemePickerModel model) {
_model = model;
themes.AddRange(model.themes);
_selected_theme = backing(nameof(selected_theme), model.selected_theme.OnDispatcher());
commit_cmd = observant_cmd(
commit, t => t is not null, _selected_theme.observe_current(true).OnDispatcher());
cancel_cmd = new Command(close);
async Task commit(UserSettingsTheme? theme) {
if (theme is null) {
Log.Ui.warn($"Unable to apply theme: {nameof(theme)} arg is null");
return;
}
await _model.set_theme(theme);
close();
}
void close() =>
RequestClose?.Invoke(this, EventArgs.Empty);
}
public event EventHandler? RequestClose;
public ObservableCollection<UserSettingsTheme> themes { get; } = new();
public UserSettingsTheme? selected_theme {
get => _selected_theme.Value;
set => _selected_theme.set(value);
}
public ICommand commit_cmd { get; }
public ICommand cancel_cmd { get; }
}
}
@@ -0,0 +1,45 @@
<UserControl
x:Class="Spark.View.ThemePickerView"
x:ClassModifier="internal"
x:Name="me"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:analytics="clr-namespace:mbts.analytics"
xmlns:u="clr-namespace:mbts.ui"
xmlns:c="clr-namespace:mbts.ui.controls"
xmlns:cv="clr-namespace:mbts.ui.converters"
xmlns:view="clr-namespace:Spark.View">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/view/Resources/CursorsEx.xaml"/>
<ResourceDictionary Source="/view/Resources/DataTemplates.xaml"/>
<ResourceDictionary Source="/view/Controls/ExpandedContentSelector.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<ComboBox
Margin="12"
ItemsSource="{Binding themes}"
SelectedItem="{Binding selected_theme}"
DisplayMemberPath="name" />
<c:DialogSkirtOKCancel
Grid.Row="1"
Grid.ColumnSpan="2"
VerticalAlignment="Bottom"
CloseOnOK="False"
CloseOnCancel="False"
OKCommand="{Binding commit_cmd}"
OKCommandParameter="{Binding selected_theme}"
CancelCommand="{Binding cancel_cmd}" />
</Grid>
</UserControl>
@@ -0,0 +1,9 @@
#nullable enable
namespace Spark.View {
using System.Windows.Controls;
partial class ThemePickerView : UserControl {
public ThemePickerView() =>
InitializeComponent();
}
}
@@ -57,6 +57,12 @@ namespace bts.shell {
public static GridSettings default_grid_settings =>
GridSettings.Default.with(DefaultColumns.all, DefaultColumns.default_sorting_criteria);
public static GridSettings dark_theme_grid_settings =>
default_grid_settings.with(
selection_highlight: BTSDarkColors.selection_highlight.argb_color(),
background: BTSDarkColors.background.argb_color(),
font_color: BTSDarkColors.foreground.argb_color());
public static string col_id(Columns col) =>
col.ToString();
@@ -39,6 +39,13 @@ namespace bts.shell.fills {
}
public static GridSettings DefaultGridSettings => GridSettings.Default.with(DefaultColumns.all, DefaultColumns.default_sorting_criteria);
public static GridSettings dark_theme_grid_settings =>
DefaultGridSettings.with(
selection_highlight: BTSDarkColors.selection_highlight.argb_color(),
background: BTSDarkColors.background.argb_color(),
font_color: BTSDarkColors.foreground.argb_color());
public static GridSettings MiniGridSettings => GridSettings.Default.with(DefaultColumns.Mini.all, DefaultColumns.Mini.sorting_criteria);
public IReadOnlyList<SortingCriteria> sorting_criteria => _sorting_criteria ?? (_sorting_criteria = DefaultColumns.default_sorting_criteria.ToList());
public static FillsSettings Default() =>
@@ -646,6 +646,24 @@ namespace mbts.spark {
public static LadderSettings Default => mimic_tt ?
tt_default : historic_default;
public static LadderSettings dark_theme {
get {
var rv = Default;
rv.orders_column.background = BTSDarkColors.background.argb_color();
rv.orders_column.foreground = BTSDarkColors.foreground.argb_color();
rv.bid_column.background = BTSDarkColors.dark_background.argb_color();
rv.bid_column.foreground = BTSDarkColors.bid_foreground.argb_color();
rv.price_column.background = BTSDarkColors.background.argb_color();
rv.price_column.foreground = BTSDarkColors.foreground.argb_color();
rv.ask_column.background = BTSDarkColors.dark_background.argb_color();
rv.ask_column.foreground = BTSDarkColors.ask_foreground.argb_color();
return rv;
}
}
public enum BadgeStyle { Normal, Alternate }
// TODO: rename to PriceDisplayFormat (today is merge monday, since this isn't a functional change, it is not worth the potential merge headaches right now)
@@ -36,10 +36,13 @@ namespace Spark.Trading {
rv.sorting_criteria.AddRange(
new(nameof(ColKey.Security), true),
new(nameof(ColKey.Account), true));
rv.grid = GridSettings.Default.with(columns: DefaultColumns.all);
rv.grid = default_grid_settings;
return rv;
}
public static GridSettings default_grid_settings =>
GridSettings.Default.with(columns: DefaultColumns.all);
public IList<SortingCriteria> sorting_criteria =>
_sorting_criteria ??= new(1);
+35 -7
View File
@@ -4,6 +4,7 @@ using mbts.ui.utility;
using mbts.utils;
using Spark.Core.Reactive;
using Spark.ViewModel.Commands;
using System;
using System.Collections.Generic;
@@ -633,8 +634,9 @@ namespace mbts.ui.shell {
public abstract class DisposableViewModelBase : ViewModelBaseWithValidation, IPropertyChangedDemuxer, IDisposable, IWillLetYouKnowWhenIDispose {
protected IDisposable _dispose = null;
List<IDisposable> _observable_properties_backing;
List<IDisposable> _observable_properties => _observable_properties_backing ?? (_observable_properties_backing = new List<IDisposable>());
readonly List<IDisposable> _internal_resources = new(0);
PropertyChangedDemuxer _property_changed_demuxer_backing;
IPropertyChangedDemuxer _property_changed_demuxer =>
@@ -650,7 +652,7 @@ namespace mbts.ui.shell {
protected Property<T> backing<T>(string name, IObservable<T> source, T default_value = default(T)) {
var prop = new ObservablePropertySink<T>(this, name, default_value);
_observable_properties.Add(source.Subscribe(prop));
_internal_resources.Add(source.Subscribe(prop));
return prop;
}
@@ -660,7 +662,7 @@ namespace mbts.ui.shell {
/// </summary>
protected Property<T> backing<T, TData>(string name, IObservable<TData> source, Func<TData, T> select, T default_value = default) {
var prop = new ObservablePropertySink<T>(this, name, default_value);
_observable_properties.Add(source.OnDispatcher().Subscribe(d => prop.set(select(d))));
_internal_resources.Add(source.OnDispatcher().Subscribe(d => prop.set(select(d))));
return prop;
}
@@ -724,9 +726,35 @@ namespace mbts.ui.shell {
return prop;
}
/// <summary>
/// Creates an <see cref="ICommand"/> that automatically invokes the CanExecuteChanged event
/// in response to notifications from <paramref name="source"/>
/// </summary>
protected ICommand observant_cmd<T>(
Action<T> execute, Func<T, bool> can_execute, IObservable<T> source) {
var cmd = ObservantCommand.create(execute, can_execute, out var obs);
_internal_resources.Add(source.Subscribe(obs));
return cmd;
}
/// <summary>
/// Creates an <see cref="ICommand"/> that automatically invokes the CanExecuteChanged event
/// in response to notifications from <paramref name="source"/>
/// </summary>
protected ICommand observant_cmd<T>(
Func<T, Task> execute,
Func<T, bool> can_execute,
IObservable<T> source,
bool allow_concurrent_executions = false) {
var cmd = ObservantAsyncCommand.create(
execute, can_execute, out var obs, allow_concurrent_executions);
_internal_resources.Add(source.Subscribe(obs));
return cmd;
}
protected void attach<T, V>(SelectorProperty<T, V> selector_property, IObservable<IEnumerable<T>> items, IObservable<InlineUserProperty<T>> desired_item) {
_observable_properties.Add(items.OnDispatcher().Subscribe(selector_property));
_observable_properties.Add(desired_item.OnDispatcher().Subscribe(selector_property));
_internal_resources.Add(items.OnDispatcher().Subscribe(selector_property));
_internal_resources.Add(desired_item.OnDispatcher().Subscribe(selector_property));
}
protected void set_dispose(IDisposable disposable) {
@@ -761,7 +789,7 @@ namespace mbts.ui.shell {
protected virtual void Dispose(bool disposing) { }
public void Dispose() {
Disposable.dispose(ref _dispose);
Disposable.dispose(_observable_properties_backing);
Disposable.dispose(_internal_resources);
Disposable.dispose(ref _property_changed_demuxer_backing);
Dispose(true);
OnDisposed?.Invoke(true);
@@ -0,0 +1,14 @@
#nullable enable
namespace mbts.ui {
using System.Windows.Media;
static class BTSDarkColors {
public static Color light_background => Color.FromArgb(194, 40, 40, 40);
public static Color background => Color.FromArgb(194, 20, 20, 20);
public static Color dark_background => Color.FromArgb(210, 0, 0, 0);
public static Color foreground => Color.FromRgb(236, 246, 255);
public static Color bid_foreground => Color.FromRgb(118, 183, 250);
public static Color ask_foreground => Color.FromRgb(255, 102, 102);
public static Color selection_highlight => Color.FromArgb(96, 0, 0, 0);
}
}
@@ -159,12 +159,13 @@
double font_size = double.NaN,
uint? background = null,
bool? enable_background_color = null,
uint? selection_highlight = null) =>
uint? selection_highlight = null,
uint? font_color = null) =>
new GridSettings(
font_family ?? _font_family,
DoubleHelper.IsNaNOrInfinityOr(font_size, 0) ? _font_size : font_size,
font_weight,
_font_color,
font_color ?? _font_color,
selection_highlight ?? _selection_highlight,
columns ?? _columns,
sorting_criteria ?? _sorting_criteria,
@@ -11,6 +11,7 @@ using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Threading;
@@ -89,7 +90,7 @@ namespace mbts.ui.shell {
public Dispatcher get_dispatcher(ISharedWindow window) {
if (window.thread_id == null) {
window.thread_init();
return Dispatcher.CurrentDispatcher;
return Application.Current.Dispatcher;
}
var uid = get(window.thread_id);
return attach_window(uid, window);
@@ -101,6 +102,9 @@ namespace mbts.ui.shell {
}
public Dispatcher get_dispatcher(string id) {
if (id is null) {
return Application.Current.Dispatcher;
}
return get(id).dispatcher;
}
}
+3
View File
@@ -15,6 +15,9 @@ namespace bts.utils {
public T value => has_value ?
_value : throw new InvalidOperationException($"value uninitialized");
public T or(T fallback) =>
has_value ? _value : fallback;
public bool Equals(Optional<T> other) =>
has_value == other.has_value &&
(!has_value || EqualityComparer<T>.Default.Equals(value, other.value));