Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Icon.cs
1using System;
3
5{
9 public class Icon
10 {
14 public Icon()
15 {
16 }
17
21 public Icon(Uri Source, string MimeType)
22 : this(Source, MimeType, null, null)
23 {
24 }
25
29 public Icon(Uri Source, string MimeType, string[]? Sizes)
30 : this(Source, MimeType, Sizes, null)
31 {
32 }
33
37 public Icon(Uri Source, string MimeType, string[]? Sizes, string? Theme)
38 {
39 this.Source = Source;
40 this.MimeType = MimeType;
41 this.Sizes = Sizes;
42 this.Theme = Theme;
43 }
44
55 public Uri? Source { get; internal set; }
56
61 public string? MimeType { get; internal set; }
62
70 public string[]? Sizes { get; internal set; }
71
79 public string? Theme { get; internal set; }
80
87 public static bool TryParse(Dictionary<string, object> Generic,
88 out Icon Typed)
89 {
90 Icon Result = new Icon();
91
92 if (Generic.TryGetValue("src", out object? Obj) &&
93 Obj is string Src &&
94 Uri.TryCreate(Src, UriKind.Absolute, out Uri Source))
95 {
96 Result.Source = Source;
97 }
98
99 if (Generic.TryGetValue("mimeType", out Obj))
100 Result.MimeType = Obj as string;
101
102 if (Generic.TryGetValue("sizes", out Obj) && Obj is Array Sizes)
103 {
104 int i, c = Sizes.Length;
105
106 Result.Sizes = new string[c];
107 for (i = 0; i < c; i++)
108 Result.Sizes[i] = Sizes.GetValue(i)?.ToString() ?? string.Empty;
109 }
110
111 if (Generic.TryGetValue("theme", out Obj))
112 Result.Theme = Obj as string;
113
114 Typed = Result;
115 return true;
116 }
117
122 public Dictionary<string, object> ToJson()
123 {
124 Dictionary<string, object> Result = new Dictionary<string, object>();
125
126 if (!(this.Source is null))
127 Result["src"] = this.Source.ToString();
128
129 if (!string.IsNullOrEmpty(this.MimeType))
130 Result["mimeType"] = this.MimeType;
131
132 if (!(this.Sizes is null))
133 Result["sizes"] = this.Sizes;
134
135 if (!string.IsNullOrEmpty(this.Theme))
136 Result["theme"] = this.Theme;
137
138 return Result;
139 }
140 }
141}
An optionally-sized icon that can be displayed in a user interface.
Definition: Icon.cs:10
static bool TryParse(Dictionary< string, object > Generic, out Icon Typed)
Tries to parse a generic structure into a typed structure.
Definition: Icon.cs:87
string? MimeType
Optional MIME type override if the source MIME type is missing or generic. For example: "image/png",...
Definition: Icon.cs:61
Icon(Uri Source, string MimeType, string[]? Sizes)
An optionally-sized icon that can be displayed in a user interface.
Definition: Icon.cs:29
Dictionary< string, object > ToJson()
Converts object to a generic representation.
Definition: Icon.cs:122
Icon(Uri Source, string MimeType)
An optionally-sized icon that can be displayed in a user interface.
Definition: Icon.cs:21
Icon(Uri Source, string MimeType, string[]? Sizes, string? Theme)
An optionally-sized icon that can be displayed in a user interface.
Definition: Icon.cs:37
string?[] Sizes
Optional array of strings that specify sizes at which the icon can be used. Each string should be in ...
Definition: Icon.cs:70
Icon()
An optionally-sized icon that can be displayed in a user interface.
Definition: Icon.cs:14
Uri? Source
A standard URI pointing to an icon resource. May be an HTTP/HTTPS URL or a data: URI with Base64-enco...
Definition: Icon.cs:55
string? Theme
Optional specifier for the theme this icon is designed for. light indicates the icon is designed to b...
Definition: Icon.cs:79