diff --git a/Src/Controls/AddtoList/ListControl.cs b/Src/Controls/AddtoList/ListControl.cs index e8a63e0..3ff2093 100644 --- a/Src/Controls/AddtoList/ListControl.cs +++ b/Src/Controls/AddtoList/ListControl.cs @@ -69,7 +69,7 @@ public override string InitControl(CancellationToken cancellationToken) FilterMode.StartsWith, _options.Items, _options.PageSize, - Optional.s_empty, + Optional.Empty(), (item1,item2) => item1.UniqueId == item2.UniqueId, (item) => item.Text, (item) => !item.Immutable); @@ -376,7 +376,7 @@ public override ResultPrompt> TryResult(CancellationToken ca FilterMode.StartsWith, _options.Items, _options.PageSize, - Optional.s_empty, + Optional.Empty(), (item1, item2) => item1.UniqueId == item2.UniqueId, (item) => item.Text, (item) => !item.Immutable); @@ -393,7 +393,7 @@ public override ResultPrompt> TryResult(CancellationToken ca FilterMode.StartsWith, _options.Items, _options.PageSize, - Optional.Create(item), + Optional.Set(item), (item1, item2) => item1.UniqueId == item2.UniqueId, (item) => item.Text, (item) => !item.Immutable); @@ -441,7 +441,7 @@ public override ResultPrompt> TryResult(CancellationToken ca FilterMode.StartsWith, _options.Items, _options.PageSize, - Optional.Create(new ItemListControl(_inputBuffer.ToString())), + Optional.Set(new ItemListControl(_inputBuffer.ToString())), (item1, item2) => item1.UniqueId == item2.UniqueId, (item) => item.Text, (item) => !item.Immutable); @@ -477,7 +477,7 @@ public override ResultPrompt> TryResult(CancellationToken ca FilterMode.StartsWith, _options.Items, _options.PageSize, - Optional.Create(new ItemListControl(_inputBuffer.ToString())), + Optional.Set(new ItemListControl(_inputBuffer.ToString())), (item1, item2) => item1.UniqueId == item2.UniqueId, (item) => item.Text, (item) => !item.Immutable); diff --git a/Src/Controls/AddtoList/MaskEditListControl.cs b/Src/Controls/AddtoList/MaskEditListControl.cs index 8453e4e..80d2b5a 100644 --- a/Src/Controls/AddtoList/MaskEditListControl.cs +++ b/Src/Controls/AddtoList/MaskEditListControl.cs @@ -77,7 +77,7 @@ public override string InitControl(CancellationToken cancellationToken) FilterMode.StartsWith, _options.Items, _options.PageSize, - Optional.s_empty, + Optional.Empty(), (item1,item2) => item1.UniqueId == item2.UniqueId, (item) => item.Text, (item) => !item.Immutable); @@ -516,7 +516,7 @@ public override ResultPrompt> TryResult(CancellationTo FilterMode.StartsWith, _options.Items, _options.PageSize, - Optional.s_empty, + Optional.Empty(), (item1, item2) => item1.UniqueId == item2.UniqueId, (item) => item.Text, (item) => !item.Immutable); @@ -533,7 +533,7 @@ public override ResultPrompt> TryResult(CancellationTo FilterMode.StartsWith, _options.Items, _options.PageSize, - Optional.Create(item), + Optional.Set(item), (item1, item2) => item1.UniqueId == item2.UniqueId, (item) => item.Text, (item) => !item.Immutable); @@ -580,7 +580,7 @@ public override ResultPrompt> TryResult(CancellationTo FilterMode.StartsWith, _options.Items, _options.PageSize, - Optional.Create(new ItemListControl(_inputBuffer.ToMasked())), + Optional.Set(new ItemListControl(_inputBuffer.ToMasked())), (item1, item2) => item1.UniqueId == item2.UniqueId, (item) => item.Text, (item) => !item.Immutable); @@ -638,7 +638,7 @@ public override ResultPrompt> TryResult(CancellationTo FilterMode.StartsWith, _options.Items, _options.PageSize, - Optional.Create(new ItemListControl(_inputBuffer.ToMasked())), + Optional.Set(new ItemListControl(_inputBuffer.ToMasked())), (item1, item2) => item1.UniqueId == item2.UniqueId, (item) => item.Text, (item) => !item.Immutable); diff --git a/Src/Controls/Calendar/CalendarControl.cs b/Src/Controls/Calendar/CalendarControl.cs index d5f9202..4c229e7 100644 --- a/Src/Controls/Calendar/CalendarControl.cs +++ b/Src/Controls/Calendar/CalendarControl.cs @@ -663,7 +663,7 @@ public override ResultPrompt TryResult(CancellationToken cancellationT _localpaginator = new Paginator( FilterMode.StartsWith, GetNotes(_currentdate), - _options.PageSize, Optional.s_empty, + _options.PageSize, Optional.Empty(), (item1, item2) => item1 == item2, (item) => item); diff --git a/Src/Controls/Input/AutoCompleteControl.cs b/Src/Controls/Input/AutoCompleteControl.cs index 32aef16..a90eabd 100644 --- a/Src/Controls/Input/AutoCompleteControl.cs +++ b/Src/Controls/Input/AutoCompleteControl.cs @@ -47,7 +47,7 @@ public override string InitControl(CancellationToken cancellationToken) FilterMode.Contains, _inputItems, Math.Min(_options.PageSize, _options.CompletionMaxCount), - Optional.s_empty, + Optional.Empty(), (item1, item2) => item1 == item2, (item) => item); @@ -456,7 +456,7 @@ public override ResultPrompt TryResult(CancellationToken cancellationTok FilterMode.Contains, _inputItems, Math.Min(_options.PageSize, _options.CompletionMaxCount), - Optional.s_empty, + Optional.Empty(), (item1, item2) => item1 == item2, (item) => item); _localpaginator.UnSelected(); @@ -531,7 +531,7 @@ private Task ObserverAutoComplete(CancellationToken cancellationToken) FilterMode.Contains, _inputItems, Math.Min(_options.PageSize, _options.CompletionMaxCount), - Optional.s_empty, + Optional.Empty(), (item1, item2) => item1 == item2, (item) => item); _localpaginator.UnSelected(); diff --git a/Src/Controls/Input/InputControl.cs b/Src/Controls/Input/InputControl.cs index 64a7f4b..5bac045 100644 --- a/Src/Controls/Input/InputControl.cs +++ b/Src/Controls/Input/InputControl.cs @@ -437,7 +437,7 @@ public override ResultPrompt TryResult(CancellationToken cancellationTok _localpaginator = new Paginator( FilterMode.StartsWith, GetItemHistory(FilterMode.StartsWith), - _options.HistoryPageSize, Optional.s_empty, + _options.HistoryPageSize, Optional.Empty(), (item1,item2) => item1.History == item2.History, (item) => item.History); diff --git a/Src/Controls/Input/MaskEditControl.cs b/Src/Controls/Input/MaskEditControl.cs index 64e607d..450c82a 100644 --- a/Src/Controls/Input/MaskEditControl.cs +++ b/Src/Controls/Input/MaskEditControl.cs @@ -472,7 +472,7 @@ public override ResultPrompt TryResult(CancellationToken cancellat _localpaginator = new Paginator( FilterMode.StartsWith, GetItemHistory(FilterMode.StartsWith), - _options.HistoryPageSize, Optional.s_empty, + _options.HistoryPageSize, Optional.Empty(), (item1,item2) => item1.History == item2.History, (item) => item.History); diff --git a/Src/Controls/Objects/Optional.cs b/Src/Controls/Objects/Optional.cs index f230256..6491503 100644 --- a/Src/Controls/Objects/Optional.cs +++ b/Src/Controls/Objects/Optional.cs @@ -2,14 +2,17 @@ // MIT LICENCE // The maintenance and evolution is maintained by the PromptPlus project under MIT license // *************************************************************************************** +// Scenario usage: +// https://stackoverflow.com/questions/65787544/nullable-enum-type-cannot-be-assigned-to-null-when-used-as-a-generic +// *************************************************************************************** namespace PPlus.Controls.Objects { internal readonly struct Optional { - private Optional(T value) + private Optional(T value, bool hasValue = true) { - HasValue = true; + HasValue = hasValue; Value = value; } @@ -17,18 +20,17 @@ private Optional(T value) public T Value { get; } - public static implicit operator T(Optional optional) => optional.Value; - - internal static readonly Optional s_empty = new(); - - public static Optional Create(T value) + public static Optional Set(T value) { - return value == null ? s_empty : new Optional(value); + return new Optional(value, true); } - public static Optional Create(object value) + public static Optional Empty() { - return value == null ? s_empty : new Optional((T)value); + return new(default, false); } + + public static implicit operator T(Optional optional) => optional.Value; + } } diff --git a/Src/Controls/SelectColletion/MultiSelectControl.cs b/Src/Controls/SelectColletion/MultiSelectControl.cs index d221fb9..328e4f6 100644 --- a/Src/Controls/SelectColletion/MultiSelectControl.cs +++ b/Src/Controls/SelectColletion/MultiSelectControl.cs @@ -21,7 +21,7 @@ internal class MultiSelectControl : BaseControl>, IControlMult private readonly List> _selectedItems = new(); private Paginator> _localpaginator; private readonly EmacsBuffer _filterBuffer = new(CaseOptions.Uppercase, modefilter: true); - private Optional> _defaultHistoric = Optional>.Create(null); + private Optional> _defaultHistoric = Optional>.Empty(); private bool ShowingFilter => _filterBuffer.Length > 0; @@ -90,7 +90,7 @@ public override string InitControl(CancellationToken cancellationToken) { if (!defvalue.HasValue) { - defvalue = Optional>.Create(null); + defvalue = Optional>.Empty(); } } @@ -159,7 +159,7 @@ public override string InitControl(CancellationToken cancellationToken) _options.FilterType, _options.Items, _options.PageSize, - Optional>.s_empty, + Optional>.Empty(), (item1,item2) => item1.UniqueId == item2.UniqueId, (item) => item.Text??string.Empty, (item) => !item.Disabled, @@ -266,9 +266,9 @@ public IControlMultiSelect AddDefault(IEnumerable value) { if (_options.DefaultValues.Value == null) { - _options.DefaultValues = Optional>.Create(new List()); + _options.DefaultValues = Optional>.Set(new List()); } - _options.DefaultValues.Value.Add(Optional.Create(item)); + _options.DefaultValues.Value.Add(item); } return this; } @@ -279,9 +279,9 @@ public IControlMultiSelect AddDefault(params T[] value) { if (_options.DefaultValues.Value == null) { - _options.DefaultValues = Optional>.Create(new List()); + _options.DefaultValues = Optional>.Set(new List()); } - _options.DefaultValues.Value.Add(Optional.Create(item)); + _options.DefaultValues.Value.Add(item); } return this; } @@ -715,7 +715,7 @@ public override ResultPrompt> TryResult(CancellationToken cancell { _localpaginator.TryGetSelected(out var currentItem); _filterBuffer.Clear(); - _localpaginator.UpdateFilter(_filterBuffer.ToString(), Optional>.Create(currentItem)); + _localpaginator.UpdateFilter(_filterBuffer.ToString(), Optional>.Set(currentItem)); if (currentItem != null) { if (currentItem.IsGroupHeader) @@ -896,7 +896,7 @@ private string EnumDisplay(T value) private void LoadHistory() { - _defaultHistoric = Optional>.Create(null); + _defaultHistoric = Optional>.Empty(); if (!string.IsNullOrEmpty(_options.OverwriteDefaultFrom)) { var aux = FileHistory.LoadHistory(_options.OverwriteDefaultFrom, 1); @@ -904,7 +904,7 @@ private void LoadHistory() { try { - _defaultHistoric = Optional>.Create(JsonSerializer.Deserialize>(aux[0].History)); + _defaultHistoric = Optional>.Set(JsonSerializer.Deserialize>(aux[0].History)); } catch { diff --git a/Src/Controls/SelectColletion/MultiSelectOptions.cs b/Src/Controls/SelectColletion/MultiSelectOptions.cs index 6ca1d24..787161a 100644 --- a/Src/Controls/SelectColletion/MultiSelectOptions.cs +++ b/Src/Controls/SelectColletion/MultiSelectOptions.cs @@ -34,7 +34,7 @@ internal MultiSelectOptions(StyleSchema styleSchema, ConfigControls config, ICon public List DisableItems { get; set; } = new List(); - public Optional> DefaultValues { get; set; } = Optional>.Create(null); + public Optional> DefaultValues { get; set; } = Optional>.Empty(); public Func EqualItems { get; set; } diff --git a/Src/Controls/SelectColletion/SelectControl.cs b/Src/Controls/SelectColletion/SelectControl.cs index 7f90e0d..839ebd4 100644 --- a/Src/Controls/SelectColletion/SelectControl.cs +++ b/Src/Controls/SelectColletion/SelectControl.cs @@ -20,7 +20,7 @@ internal class SelectControl : BaseControl, IControlSelect private readonly SelectOptions _options; private Paginator> _localpaginator; private readonly EmacsBuffer _filterBuffer = new(CaseOptions.Uppercase,modefilter:true); - private Optional _defaultHistoric = Optional.Create(null); + private Optional _defaultHistoric = Optional.Empty(); private bool ShowingFilter => _filterBuffer.Length > 0; private int _lengthSeparationline; @@ -242,7 +242,7 @@ public IControlSelect Config(Action context) public IControlSelect Default(T value) { - _options.DefaultValue = Optional.Create(value); + _options.DefaultValue = Optional.Set(value); return this; } @@ -347,17 +347,17 @@ public override string InitControl(CancellationToken cancellationToken) } _lengthSeparationline = maxlensep; - Optional defvalue = Optional.s_empty; + Optional defvalue = Optional.Empty(); - Optional> defvaluepage = Optional>.s_empty; + Optional> defvaluepage = Optional>.Empty(); if (_options.DefaultValue.HasValue) { - defvalue = Optional.Create(_options.DefaultValue.Value); + defvalue = Optional.Set(_options.DefaultValue.Value); } if (_defaultHistoric.HasValue) { - defvalue = Optional.Create(_defaultHistoric.Value); + defvalue = Optional.Set(_defaultHistoric.Value); } if (defvalue.HasValue) @@ -365,7 +365,7 @@ public override string InitControl(CancellationToken cancellationToken) var found = _options.Items.FirstOrDefault(x => !x.IsGroupHeader && _options.EqualItems(x.Value, defvalue.Value)); if (found != null && !found.Disabled) { - defvaluepage = Optional>.Create(found); + defvaluepage = Optional>.Set(found); } } @@ -666,7 +666,7 @@ private void SaveHistory(T value) private void LoadHistory() { - _defaultHistoric = Optional.Create(null); + _defaultHistoric = Optional.Empty(); if (!string.IsNullOrEmpty(_options.OverwriteDefaultFrom)) { var aux = FileHistory.LoadHistory(_options.OverwriteDefaultFrom, 1); @@ -674,7 +674,7 @@ private void LoadHistory() { try { - _defaultHistoric = Optional.Create(JsonSerializer.Deserialize(aux[0].History)); + _defaultHistoric = Optional.Set(JsonSerializer.Deserialize(aux[0].History)); } catch { diff --git a/Src/Controls/SelectColletion/SelectOptions.cs b/Src/Controls/SelectColletion/SelectOptions.cs index 0b2004c..710e8bf 100644 --- a/Src/Controls/SelectColletion/SelectOptions.cs +++ b/Src/Controls/SelectColletion/SelectOptions.cs @@ -40,7 +40,7 @@ internal SelectOptions(StyleSchema styleSchema, ConfigControls config, IConsoleC public Func EqualItems { get; set; } - public Optional DefaultValue { get; set; } = Optional.Create(null); + public Optional DefaultValue { get; set; } = Optional.Empty(); public Func TextSelector { get; set; } diff --git a/Src/Controls/Table/TableMultiSelectControl.cs b/Src/Controls/Table/TableMultiSelectControl.cs index 991da1f..b3b2b7b 100644 --- a/Src/Controls/Table/TableMultiSelectControl.cs +++ b/Src/Controls/Table/TableMultiSelectControl.cs @@ -20,7 +20,7 @@ internal class TableMultiSelectControl : BaseControl>, IContro { private readonly TableOptions _options; private readonly List> _selectedItems = new(); - private Optional> _defaultHistoric = Optional>.Create(null); + private Optional> _defaultHistoric = Optional>.Empty(); private Paginator> _localpaginator; private readonly EmacsBuffer _filterBuffer = new(CaseOptions.Uppercase, modefilter: true); private bool ShowingFilter => _filterBuffer.Length > 0; @@ -184,7 +184,7 @@ public override string InitControl(CancellationToken cancellationToken) } } - Optional> defvaluepage = Optional>.s_empty; + Optional> defvaluepage = Optional>.Empty(); Optional> defvalue = _options.DefaultValues; if (_defaultHistoric.HasValue) { @@ -194,7 +194,7 @@ public override string InitControl(CancellationToken cancellationToken) { if (!defvalue.HasValue) { - defvalue = Optional>.Create(null); + defvalue = Optional>.Empty(); } } @@ -628,7 +628,7 @@ public override ResultPrompt> TryResult(CancellationToken cancell { _localpaginator.TryGetSelected(out var currentItem); _filterBuffer.Clear(); - _localpaginator.UpdateFilter(_filterBuffer.ToString(), Optional>.Create(currentItem)); + _localpaginator.UpdateFilter(_filterBuffer.ToString(), Optional>.Set(currentItem)); if (currentItem != null) { var index = _selectedItems.FindIndex(x => x.Value.Equals(currentItem.Value)); @@ -769,9 +769,9 @@ public IControlTableMultiSelect AddDefault(IEnumerable value) { if (_options.DefaultValues.Value == null) { - _options.DefaultValues = Optional>.Create(new List()); + _options.DefaultValues = Optional>.Set(new List()); } - _options.DefaultValues.Value.Add(Optional.Create(item)); + _options.DefaultValues.Value.Add(item); } return this; } @@ -782,9 +782,9 @@ public IControlTableMultiSelect AddDefault(params T[] value) { if (_options.DefaultValues.Value == null) { - _options.DefaultValues = Optional>.Create(new List()); + _options.DefaultValues = Optional>.Set(new List()); } - _options.DefaultValues.Value.Add(Optional.Create(item)); + _options.DefaultValues.Value.Add(item); } return this; } @@ -2287,7 +2287,7 @@ private bool IsDisabled(ItemTableRow item) private void LoadHistory() { - _defaultHistoric = Optional>.Create(null); + _defaultHistoric = Optional>.Empty(); if (!string.IsNullOrEmpty(_options.OverwriteDefaultFrom)) { var aux = FileHistory.LoadHistory(_options.OverwriteDefaultFrom, 1); @@ -2295,7 +2295,7 @@ private void LoadHistory() { try { - _defaultHistoric = Optional>.Create(JsonSerializer.Deserialize>(aux[0].History)); + _defaultHistoric = Optional>.Set(JsonSerializer.Deserialize>(aux[0].History)); } catch { diff --git a/Src/Controls/Table/TableOptions.cs b/Src/Controls/Table/TableOptions.cs index 28df6d7..9f236b8 100644 --- a/Src/Controls/Table/TableOptions.cs +++ b/Src/Controls/Table/TableOptions.cs @@ -44,9 +44,9 @@ internal TableOptions(StyleSchema styleSchema, ConfigControls config, IConsoleCo public Func EqualItems { get; set; } - public Optional DefaultValue { get; set; } = Optional.Create(null); + public Optional DefaultValue { get; set; } = Optional.Empty(); - public Optional> DefaultValues { get; set; } = Optional>.Create(null); + public Optional> DefaultValues { get; set; } = Optional>.Empty(); public int PageSize { get; set; } diff --git a/Src/Controls/Table/TableSelectControl.cs b/Src/Controls/Table/TableSelectControl.cs index 2b06fcc..3c9449b 100644 --- a/Src/Controls/Table/TableSelectControl.cs +++ b/Src/Controls/Table/TableSelectControl.cs @@ -19,7 +19,7 @@ namespace PPlus.Controls.Table internal class TableSelectControl : BaseControl>, IControlTableSelect where T : class { private readonly TableOptions _options; - private Optional _defaultHistoric = Optional.Create(null); + private Optional _defaultHistoric = Optional.Empty(); private Paginator> _localpaginator; private readonly EmacsBuffer _filterBuffer = new(CaseOptions.Uppercase, modefilter: true); private bool ShowingFilter => _filterBuffer.Length > 0; @@ -203,16 +203,16 @@ public override string InitControl(CancellationToken cancellationToken) } } - Optional defvalue = Optional.s_empty; - Optional> defvaluepage = Optional>.s_empty; + Optional defvalue = Optional.Empty(); + Optional> defvaluepage = Optional>.Empty(); if (_options.DefaultValue.HasValue) { - defvalue = Optional.Create(_options.DefaultValue.Value); + defvalue = Optional.Set(_options.DefaultValue.Value); } if (_defaultHistoric.HasValue) { - defvalue = Optional.Create(_defaultHistoric.Value); + defvalue = Optional.Set(_defaultHistoric.Value); } if (defvalue.HasValue) @@ -220,7 +220,7 @@ public override string InitControl(CancellationToken cancellationToken) var found = _options.Items.FirstOrDefault(x => _options.EqualItems(x.Value, defvalue.Value)); if (found != null && !found.Disabled) { - defvaluepage = Optional>.Create(found); + defvaluepage = Optional>.Set(found); } } @@ -868,7 +868,7 @@ public IControlTableSelect HideHeaders(bool value = true) public IControlTableSelect Default(T value) { - _options.DefaultValue = Optional.Create(value); + _options.DefaultValue = Optional.Set(value); return this; } @@ -2142,7 +2142,7 @@ private bool IsDisabled(ItemTableRow item) private void LoadHistory() { - _defaultHistoric = Optional.Create(null); + _defaultHistoric = Optional.Empty(); if (!string.IsNullOrEmpty(_options.OverwriteDefaultFrom)) { var aux = FileHistory.LoadHistory(_options.OverwriteDefaultFrom, 1); @@ -2150,7 +2150,7 @@ private void LoadHistory() { try { - _defaultHistoric = Optional.Create(JsonSerializer.Deserialize(aux[0].History)); + _defaultHistoric = Optional.Set(JsonSerializer.Deserialize(aux[0].History)); } catch { diff --git a/Src/Controls/TreeDiagram/BrowserMultiSelectControl.cs b/Src/Controls/TreeDiagram/BrowserMultiSelectControl.cs index 02a4b25..22ac27b 100644 --- a/Src/Controls/TreeDiagram/BrowserMultiSelectControl.cs +++ b/Src/Controls/TreeDiagram/BrowserMultiSelectControl.cs @@ -914,7 +914,7 @@ private void LoadFlatNodes(TreeNode defaultnodeselected, bool updat _options.FilterType, _flatnodes, _options.PageSize, - Optional>.Create(new ItemTreeViewFlatNode { UniqueId = defaultnodeselected.UniqueId, IsDisabled = defaultnodeselected.IsDisabled, IsRoot = defaultnodeselected.IsRoot, Value = defaultnodeselected.Value, MessagesNodes = ShowItem(defaultnodeselected) }), + Optional>.Set(new ItemTreeViewFlatNode { UniqueId = defaultnodeselected.UniqueId, IsDisabled = defaultnodeselected.IsDisabled, IsRoot = defaultnodeselected.IsRoot, Value = defaultnodeselected.Value, MessagesNodes = ShowItem(defaultnodeselected) }), (item1,item2) => item1.UniqueId == item2.UniqueId, (item) => item.Value.Name); } @@ -1218,7 +1218,7 @@ private bool IsFixedSelect(TreeNode item) private void InitSelectedNodes() { - Optional> defvalue = Optional>.s_empty; + Optional> defvalue = Optional>.Empty(); var nodeselect = _browserTreeView.Root; _selectedItems.Clear(); AddSelectAll(nodeselect); @@ -1230,7 +1230,7 @@ private void InitSelectedNodes() { foreach (var item in _flatnodes.Where(x => x.Value.FullPath.Equals(defopt))) { - defvalue = Optional>.Create(item); + defvalue = Optional>.Set(item); } } else @@ -1238,7 +1238,7 @@ private void InitSelectedNodes() var node = _browserTreeView.Root; if (node != null) { - defvalue = Optional>.Create(new ItemTreeViewFlatNode { UniqueId = node.UniqueId, IsDisabled = node.IsDisabled, IsRoot = node.IsRoot, Value = node.Value, MessagesNodes = ShowItem(node) }); + defvalue = Optional>.Set(new ItemTreeViewFlatNode { UniqueId = node.UniqueId, IsDisabled = node.IsDisabled, IsRoot = node.IsRoot, Value = node.Value, MessagesNodes = ShowItem(node) }); } } diff --git a/Src/Controls/TreeDiagram/BrowserSelectControl.cs b/Src/Controls/TreeDiagram/BrowserSelectControl.cs index 9b457a8..9f4d1f0 100644 --- a/Src/Controls/TreeDiagram/BrowserSelectControl.cs +++ b/Src/Controls/TreeDiagram/BrowserSelectControl.cs @@ -802,7 +802,7 @@ private void LoadFlatNodes(TreeNode defaultnodeselected, bool updat _options.FilterType, _flatnodes, _options.PageSize, - Optional>.Create(new ItemTreeViewFlatNode { UniqueId = defaultnodeselected.UniqueId, IsDisabled = defaultnodeselected.IsDisabled, IsRoot = defaultnodeselected.IsRoot, Value = defaultnodeselected.Value, MessagesNodes = ShowItem(defaultnodeselected) }), + Optional>.Set(new ItemTreeViewFlatNode { UniqueId = defaultnodeselected.UniqueId, IsDisabled = defaultnodeselected.IsDisabled, IsRoot = defaultnodeselected.IsRoot, Value = defaultnodeselected.Value, MessagesNodes = ShowItem(defaultnodeselected) }), (item1, item2) => item1.UniqueId == item2.UniqueId, (item) => item.Value.Name); } @@ -811,7 +811,7 @@ private void LoadFlatNodes(TreeNode defaultnodeselected, bool updat private void FistLoadRoot(CancellationToken cancellationToken) { - Optional> defvalue = Optional>.s_empty; + Optional> defvalue = Optional>.Empty(); TryLoadFolder(true, null, _options.RootFolder, _options.ExpandAll, cancellationToken); _browserTreeView.SetCurrentNode(_browserTreeView.Root); if (_options.ExpandAll) @@ -831,13 +831,13 @@ private void FistLoadRoot(CancellationToken cancellationToken) { foreach (var item in _flatnodes.Where(x => x.Value.FullPath.Equals(defopt))) { - defvalue = Optional>.Create(item); + defvalue = Optional>.Set(item); } } else { var node = _browserTreeView.Root; - defvalue = Optional>.Create(new ItemTreeViewFlatNode { UniqueId = node.UniqueId, IsDisabled = node.IsDisabled, IsRoot = node.IsRoot, Value = node.Value, MessagesNodes = ShowItem(node) }); + defvalue = Optional>.Set(new ItemTreeViewFlatNode { UniqueId = node.UniqueId, IsDisabled = node.IsDisabled, IsRoot = node.IsRoot, Value = node.Value, MessagesNodes = ShowItem(node) }); } _localpaginator = new Paginator>( diff --git a/Src/Controls/TreeDiagram/TreeViewMultiSelectControl.cs b/Src/Controls/TreeDiagram/TreeViewMultiSelectControl.cs index 543fa66..9e88bc5 100644 --- a/Src/Controls/TreeDiagram/TreeViewMultiSelectControl.cs +++ b/Src/Controls/TreeDiagram/TreeViewMultiSelectControl.cs @@ -177,7 +177,7 @@ public IControlTreeViewMultiSelect AddNode(T parent, T value) public IControlTreeViewMultiSelect Default(T value) { - _options.DefautNode = Optional.Create(value); + _options.DefautNode = Optional.Set(value); return this; } @@ -783,7 +783,7 @@ private void LoadFlatNodes(TreeNode defaultnodeselected, bool updatePaginator _options.FilterType, _flatnodes, _options.PageSize, - Optional>.Create(new ItemTreeViewFlatNode { UniqueId = defaultnodeselected.UniqueId, IsDisabled = defaultnodeselected.IsDisabled, IsRoot = defaultnodeselected.IsRoot, Value = defaultnodeselected.Value, MessagesNodes = ShowItem(defaultnodeselected) }), + Optional>.Set(new ItemTreeViewFlatNode { UniqueId = defaultnodeselected.UniqueId, IsDisabled = defaultnodeselected.IsDisabled, IsRoot = defaultnodeselected.IsRoot, Value = defaultnodeselected.Value, MessagesNodes = ShowItem(defaultnodeselected) }), (item1,item2) => item1.UniqueId == item2.UniqueId, (item) => item.MessagesNodes.TextItem); } diff --git a/Src/Controls/TreeDiagram/TreeViewOptions.cs b/Src/Controls/TreeDiagram/TreeViewOptions.cs index 604f102..994b836 100644 --- a/Src/Controls/TreeDiagram/TreeViewOptions.cs +++ b/Src/Controls/TreeDiagram/TreeViewOptions.cs @@ -36,7 +36,7 @@ internal TreeViewOptions(StyleSchema styleSchema, ConfigControls config, IConsol public bool ShowLines { get; set; } = true; public bool ShowExpand { get; set; } = true; public int PageSize { get; set; } - public Optional DefautNode { get; set; } = Optional.s_empty; + public Optional DefautNode { get; set; } = Optional.Empty(); public Func? TextNode { get; set; } public char SeparatePath { get; set; } = '/'; public bool ShowCurrentNode { get; set; } = true; diff --git a/Src/Controls/TreeDiagram/TreeViewSelectControl.cs b/Src/Controls/TreeDiagram/TreeViewSelectControl.cs index c9c7145..55e5e69 100644 --- a/Src/Controls/TreeDiagram/TreeViewSelectControl.cs +++ b/Src/Controls/TreeDiagram/TreeViewSelectControl.cs @@ -127,7 +127,7 @@ public IControlTreeViewSelect AddNode(T parent, T value) public IControlTreeViewSelect Default(T value) { - _options.DefautNode = Optional.Create(value); + _options.DefautNode = Optional.Set(value); return this; } @@ -622,7 +622,7 @@ private void LoadFlatNodes(TreeNode defaultnodeselected, bool updatePaginator _options.FilterType, _flatnodes, _options.PageSize, - Optional>.Create(new ItemTreeViewFlatNode { UniqueId = defaultnodeselected.UniqueId, IsDisabled = defaultnodeselected.IsDisabled, IsRoot = defaultnodeselected.IsRoot, Value = defaultnodeselected.Value, MessagesNodes = ShowItem(defaultnodeselected) }), + Optional>.Set(new ItemTreeViewFlatNode { UniqueId = defaultnodeselected.UniqueId, IsDisabled = defaultnodeselected.IsDisabled, IsRoot = defaultnodeselected.IsRoot, Value = defaultnodeselected.Value, MessagesNodes = ShowItem(defaultnodeselected) }), (item1,item2) => item1.UniqueId == item2.UniqueId, (item) => item.MessagesNodes.TextItem); } diff --git a/Src/Drivers/Color.cs b/Src/Drivers/Color.cs index 0804af0..ecc9752 100644 --- a/Src/Drivers/Color.cs +++ b/Src/Drivers/Color.cs @@ -118,7 +118,7 @@ public static string FromHex(Color value) /// public override readonly int GetHashCode() { - return HashCode.Combine(R, G, B); + return HashCode.Combine(R, G, B); } /// diff --git a/UnitTests/Controls/PaginatorTest.cs b/UnitTests/Controls/PaginatorTest.cs index 6d4aad3..9e2d86f 100644 --- a/UnitTests/Controls/PaginatorTest.cs +++ b/UnitTests/Controls/PaginatorTest.cs @@ -22,7 +22,7 @@ public void Should_have_5_pages() items.Add(i.ToString()); } // When - var pg = new Paginator( PPlus.Controls.FilterMode.Contains, items, 10, Optional.s_empty,null); + var pg = new Paginator( PPlus.Controls.FilterMode.Contains, items, 10, Optional.Empty(),null); // Then Assert.Equal(50, pg.TotalCount); Assert.Equal(5, pg.PageCount); @@ -38,7 +38,7 @@ public void Should_have_1_item_lastpage() items.Add(i.ToString()); } // When - var pg = new Paginator(PPlus.Controls.FilterMode.Contains, items, 3, Optional.s_empty, null); + var pg = new Paginator(PPlus.Controls.FilterMode.Contains, items, 3, Optional.Empty(), null); pg.EnsureVisibleIndex(6); // Then Assert.Equal(2, pg.SelectedPage); @@ -57,7 +57,7 @@ public void Should_have_3_items_CurrentPage() items.Add(i.ToString()); } // When - var pg = new Paginator(PPlus.Controls.FilterMode.Contains, items, 3, Optional.s_empty, null); + var pg = new Paginator(PPlus.Controls.FilterMode.Contains, items, 3, Optional.Empty(), null); pg.GetPageData(); // Then Assert.Equal(0, pg.SelectedPage); @@ -74,7 +74,7 @@ public void Should_have_selectedItem() items.Add(i.ToString()); } // When - var pg = new Paginator(PPlus.Controls.FilterMode.Contains, items, 10, Optional.Create("3"),null); + var pg = new Paginator(PPlus.Controls.FilterMode.Contains, items, 10, Optional.Set("3"),null); // Then Assert.Equal(3, pg.SelectedIndex); Assert.Equal("3", pg.SelectedItem); @@ -89,7 +89,7 @@ public void Should_have_UnSelected() { items.Add(i.ToString()); } - var pg = new Paginator(PPlus.Controls.FilterMode.Contains, items, 10, Optional.Create("3"), null); + var pg = new Paginator(PPlus.Controls.FilterMode.Contains, items, 10, Optional.Set("3"), null); // When pg.UnSelected(); // Then @@ -109,7 +109,7 @@ public void Should_have_selectedItem_with_FistItem() { items.Add(i.ToString()); } - var pg = new Paginator(PPlus.Controls.FilterMode.Contains, items, 10, Optional.Create("3"), null); + var pg = new Paginator(PPlus.Controls.FilterMode.Contains, items, 10, Optional.Set("3"), null); // When pg.FirstItem(); // Then @@ -126,7 +126,7 @@ public void Should_have_selectedItem_with_LastItem() { items.Add(i.ToString()); } - var pg = new Paginator(PPlus.Controls.FilterMode.Contains, items, 10, Optional.Create("0"), null); + var pg = new Paginator(PPlus.Controls.FilterMode.Contains, items, 10, Optional.Set("0"), null); // When pg.LastItem(); // Then @@ -143,7 +143,7 @@ public void Should_have_selectedItem_with_NextPage_unselect() { items.Add(i.ToString()); } - var pg = new Paginator(PPlus.Controls.FilterMode.Contains, items, 5, Optional.s_empty,null); + var pg = new Paginator(PPlus.Controls.FilterMode.Contains, items, 5, Optional.Empty(),null); // When pg.NextPage(IndexOption.None); // Then @@ -162,7 +162,7 @@ internal void Should_have_selectedItem_with_NextPage_FistSelect(IndexOption opc) { items.Add(i.ToString()); } - var pg = new Paginator(PPlus.Controls.FilterMode.Contains, items, 5, Optional.s_empty, null); + var pg = new Paginator(PPlus.Controls.FilterMode.Contains, items, 5, Optional.Empty(), null); // When pg.NextPage(opc); // Then @@ -181,7 +181,7 @@ internal void Should_have_selectedItem_with_NextPage_LastSelect(IndexOption opc) { items.Add(i.ToString()); } - var pg = new Paginator(PPlus.Controls.FilterMode.Contains, items, 5, Optional.s_empty, null); + var pg = new Paginator(PPlus.Controls.FilterMode.Contains, items, 5, Optional.Empty(), null); // When pg.NextPage(opc); // Then @@ -198,7 +198,7 @@ public void Should_have_selectedItem_with_FistItem_and_validator_Select() { items.Add(i.ToString()); } - var pg = new Paginator(PPlus.Controls.FilterMode.Contains, items, 3, Optional.Create("0"), null,null, (x) => x != "0"); + var pg = new Paginator(PPlus.Controls.FilterMode.Contains, items, 3, Optional.Set("0"), null,null, (x) => x != "0"); // When pg.FirstItem(); // Then @@ -214,7 +214,7 @@ public void Should_have_selectedItem_with_LastItem_and_validator_Select() { items.Add(i.ToString()); } - var pg = new Paginator(PPlus.Controls.FilterMode.Contains, items, 10, Optional.Create("0"), null, null, (x) => x != "4"); + var pg = new Paginator(PPlus.Controls.FilterMode.Contains, items, 10, Optional.Set("0"), null, null, (x) => x != "4"); // When pg.LastItem(); // Then @@ -233,7 +233,7 @@ internal void Should_have_selectedItem_with_NextPage_FistSelect_and_validator_Se { items.Add(i.ToString()); } - var pg = new Paginator(PPlus.Controls.FilterMode.Contains, items, 5, Optional.Create("0"), null, null, (x) => x != "5"); + var pg = new Paginator(PPlus.Controls.FilterMode.Contains, items, 5, Optional.Set("0"), null, null, (x) => x != "5"); // When pg.NextPage(opc); // Then @@ -252,7 +252,7 @@ internal void Should_have_selectedItem_with_NextPage_LastSelect_and_validator_Se { items.Add(i.ToString()); } - var pg = new Paginator(PPlus.Controls.FilterMode.Contains, items, 5, Optional.s_empty, null, null, (x) => x != "9"); + var pg = new Paginator(PPlus.Controls.FilterMode.Contains, items, 5, Optional.Empty(), null, null, (x) => x != "9"); // When pg.NextPage(opc); // Then @@ -269,7 +269,7 @@ internal void Should_have_selectedItem_with_UpdateFilter() { items.Add(i.ToString()); } - var pg = new Paginator(PPlus.Controls.FilterMode.Contains, items, 5, Optional.s_empty, null); + var pg = new Paginator(PPlus.Controls.FilterMode.Contains, items, 5, Optional.Empty(), null); // When pg.UpdateFilter("10"); // Then @@ -288,7 +288,7 @@ internal void Should_have_selectedItem_with_UpdateFilter_and_tryget() { items.Add(i.ToString()); } - var pg = new Paginator(PPlus.Controls.FilterMode.Contains, items, 5, Optional.s_empty, null); + var pg = new Paginator(PPlus.Controls.FilterMode.Contains, items, 5, Optional.Empty(), null); // When pg.UpdateFilter("10"); var ok = pg.TryGetSelected(out var result);