-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathDataDictionary.cs
More file actions
40 lines (33 loc) · 1.42 KB
/
DataDictionary.cs
File metadata and controls
40 lines (33 loc) · 1.42 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
using System;
using System.Collections.Generic;
namespace FFBitrateViewer
{
// Used for storing values
// Key -- case sensitive string
// Value -- null, int or double
// On adding a new item to the dictionary the value is automatically converted from string to null/int/double
public class DataDictionary : Dictionary<string, object?>
{
public new void Add(string key, object value)
{
if (value == null) base.Add(key, null);
else if (value is string @string)
{
if (int.TryParse(@string, out int @int)) base.Add(key, @int);
else if (Helpers.TryParseDouble(@string, out double @double, true/*withInfinity*/)) base.Add(key, @double);
else base.Add(key, null);
}
else if (Helpers.IsFloatingPointNumber(ref value)) base.Add(key, Convert.ToDouble(value));
else if (Helpers.IsIntegralNumber(ref value)) base.Add(key, Convert.ToInt32(value));
else throw new System.InvalidOperationException("Value must be numeric, string or null");
}
public void Add(Dictionary<string, string> pairs)
{
if(pairs != null) foreach(var pair in pairs) Add(pair.Key, pair.Value);
}
public void Add(Dictionary<string, object> pairs)
{
if (pairs != null) foreach (var pair in pairs) Add(pair.Key, pair.Value);
}
}
}