-
-
Notifications
You must be signed in to change notification settings - Fork 234
/
Copy pathBaseSettingViewModel.cs
41 lines (35 loc) · 1.29 KB
/
BaseSettingViewModel.cs
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
using System;
namespace Nodify.Playground
{
public class BaseSettingViewModel<T> : ObservableObject, ISettingViewModel
{
public string Name { get; }
public string? Description { get; }
private object? _value;
object? ISettingViewModel.Value
{
get => _value;
set => SetProperty(ref _value, value);
}
public SettingsType Type { get;}
public T Value
{
get => (T)((ISettingViewModel)this).Value!;
set => ((ISettingViewModel)this).Value = value;
}
public BaseSettingViewModel(string name, string? description = default)
{
Name = name;
Description = description;
Type = typeof(T) switch
{
{ } t when t == typeof(string) => SettingsType.Text,
{ } t when t == typeof(bool) => SettingsType.Boolean,
{ } t when t == typeof(uint) || t == typeof(double) => SettingsType.Number,
{ } t when t == typeof(PointEditor) => SettingsType.Point,
{ IsEnum: true } => SettingsType.Option,
_ => throw new InvalidOperationException($"Type {typeof(T).Name} does not have a matching {nameof(SettingsType)}.")
};
}
}
}