Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ObjectMatrixEncoder.cs
1using System;
2using System.Text;
5
7{
12 {
17 {
18 }
19
26 public void Encode(object Object, int? Indent, StringBuilder Json)
27 {
28 ObjectMatrix M = (ObjectMatrix)Object;
29 string[] Names;
30 int Rows = M.Rows;
31 int Columns = M.Columns;
32 int x, y;
33
34 if (!(M.ColumnNames is null))
35 Names = M.ColumnNames;
36 else
37 {
38 Names = new string[Columns];
39
40 for (x = 0; x < Columns; x++)
41 Names[x] = "C" + (x + 1).ToString();
42 }
43
44 Json.Append('[');
45
46 if (Indent.HasValue)
47 Indent++;
48
49 for (y = 0; y < Rows; y++)
50 {
51 if (y > 0)
52 Json.Append(',');
53
54 if (Indent.HasValue)
55 {
56 Json.AppendLine();
57 Json.Append(new string('\t', Indent.Value));
58 Indent++;
59 }
60
61 Json.Append('{');
62
63 for (x = 0; x < Columns; x++)
64 {
65 if (x > 0)
66 Json.Append(',');
67
68 if (Indent.HasValue)
69 {
70 Json.AppendLine();
71 Json.Append(new string('\t', Indent.Value));
72 }
73
74 Json.Append('"');
75 Json.Append(JSON.Encode(Names[x]));
76 Json.Append("\":");
77 JSON.Encode(M.GetElement(x, y).AssociatedObjectValue, Indent, Json);
78 }
79
80 if (Indent.HasValue)
81 {
82 Indent--;
83 Json.AppendLine();
84 Json.Append(new string('\t', Indent.Value));
85 }
86
87 Json.Append('}');
88 }
89
90
91 if (Indent.HasValue)
92 {
93 Indent--;
94
95 if (Rows > 0 && Columns > 0)
96 {
97 Json.AppendLine();
98 Json.Append(new string('\t', Indent.Value));
99 }
100 }
101
102 Json.Append(']');
103 }
104
110 public Grade Supports(Type ObjectType)
111 {
112 return ObjectType == typeof(ObjectMatrix) ? Grade.Excellent : Grade.NotAtAll;
113 }
114 }
115}
Helps with common JSON-related tasks.
Definition: JSON.cs:14
static string Encode(string s)
Encodes a string for inclusion in JSON.
Definition: JSON.cs:507
Grade Supports(Type ObjectType)
How well the JSON encoder encodes objects of type ObjectType .
void Encode(object Object, int? Indent, StringBuilder Json)
Encodes the Object to JSON.
string[] ColumnNames
Contains optional column names.
Interface for encoding objects of certain types to JSON.
Definition: IJsonEncoder.cs:11
Grade
Grade enumeration
Definition: Grade.cs:7