-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOptionsManager.cs
More file actions
62 lines (52 loc) · 1.6 KB
/
Copy pathOptionsManager.cs
File metadata and controls
62 lines (52 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplicationBuilder
{
class OptionsManager
{
public List<Option> Options { get; set; }
public OptionsManager()
{
Options = new List<Option>();
}
public Option GetSelectedOption()
{
var option = Options.FirstOrDefault(r => r.IsSelected == true);
return option;
}
public Option GetOption(int index)
{
if (index < 0 || index >= Options.Count)
return null;
var option = Options[index];
return option;
}
public void SetOptionSelection(int index, bool selection)
{
if(Options.Count > 0)
{
var option = GetOption(index);
if (option is not null)
option.IsSelected = selection;
}
}
public void SelectOption(int index) => SetOptionSelection(index, true);
public void UnSelectOption(int index) => SetOptionSelection(index, false);
public void AddOption(Option option)
{
if (option is not null)
Options.Add(option);
else
throw new Exception("Can't add option to the menu because the option is empty");
}
public void DeleteOption(string name)
{
var option = Options.FirstOrDefault(x => x.Name == name);
if (option is not null)
Options.Remove(option);
}
}
}