-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMdiTabModel.cs
More file actions
50 lines (48 loc) · 1.84 KB
/
MdiTabModel.cs
File metadata and controls
50 lines (48 loc) · 1.84 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
using System.Text.Json;
using System.Text.Json.Serialization;
namespace blazor_multi_tab_ui.Models
{
public class MdiTabModel
{
public MdiTabModel() => Id = Guid.NewGuid().ToString();
public string Id { get; }
public int VisibleIndex { get; set; }
public bool Visible { get; set; }
public string? Text { get; set; }
public string? TabTypeName { get; set; }
public Dictionary<string, JsonElement>? UntypedParameters { get; set; }
private Dictionary<string, object>? _cachedParameters;
[JsonIgnore]
public Dictionary<string, object>? Parameters
{
get
{
if (_cachedParameters == null && UntypedParameters != null)
{
_cachedParameters = UntypedParameters.ToDictionary(
p => p.Key,
p => (object)(p.Value.ValueKind switch
{
JsonValueKind.Number when p.Value.TryGetInt32(out var i) => i,
JsonValueKind.Number when p.Value.TryGetInt64(out var l) => l,
JsonValueKind.Number when p.Value.TryGetDouble(out var d) => d,
JsonValueKind.True => true,
JsonValueKind.False => false,
JsonValueKind.String => p.Value.GetString()!,
_ => p.Value.ToString()!
})
);
}
return _cachedParameters;
}
set
{
UntypedParameters = value?.ToDictionary(
p => p.Key,
p => JsonSerializer.SerializeToElement(p.Value)
);
_cachedParameters = value;
}
}
}
}