Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
DsnFields.cs
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace Waher.Content.Dsn
6{
10 public abstract class DsnFields
11 {
12 private readonly KeyValuePair<string, string>[] other;
13
18 public DsnFields(string[] Rows)
19 {
20 List<KeyValuePair<string, string>> Other = new List<KeyValuePair<string, string>>();
21
22 foreach (string Row in Rows)
23 {
24 int i = Row.IndexOf(':');
25 string Key;
26 string Value;
27
28 if (i < 0)
29 {
30 Key = Row.Trim();
31 Value = string.Empty;
32 }
33 else
34 {
35 Key = Row.Substring(0, i).Trim();
36 Value = Row.Substring(i + 1).Trim();
37 }
38
39 if (!this.Parse(Key, Value))
40 Other.Add(new KeyValuePair<string, string>(Key, Value));
41 }
42
43 this.other = Other.ToArray();
44 }
45
52 protected abstract bool Parse(string Key, string Value);
53
60 protected bool ParseType(ref string Value, out string Type)
61 {
62 int i = Value.IndexOf(';');
63 if (i < 0)
64 {
65 Type = string.Empty;
66 return false;
67 }
68 else
69 {
70 Type = Value.Substring(0, i).TrimEnd();
71 Value = Value.Substring(i + 1).TrimStart();
72 return true;
73 }
74 }
75
79 public KeyValuePair<string, string>[] Other => this.other;
80 }
81}
Base class for DSN field classes.
Definition: DsnFields.cs:11
KeyValuePair< string, string >[] Other
Other fields.
Definition: DsnFields.cs:79
bool ParseType(ref string Value, out string Type)
Parses a type value prefixed to the field value.
Definition: DsnFields.cs:60
abstract bool Parse(string Key, string Value)
Parses a field
DsnFields(string[] Rows)
Base class for DSN field classes.
Definition: DsnFields.cs:18