Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
EnumerableEncoder.cs
1using System;
2using System.Collections;
3using System.Reflection;
4using System.Text;
6
8{
13 {
18 {
19 }
20
27 public void Encode(object Object, int? Indent, StringBuilder Json)
28 {
29 IEnumerable E = (IEnumerable)Object;
30 IEnumerator e = E.GetEnumerator();
31 bool First = true;
32
33 Json.Append('[');
34
35 if (Indent.HasValue)
36 Indent++;
37
38 while (e.MoveNext())
39 {
40 if (First)
41 First = false;
42 else
43 Json.Append(',');
44
45 if (Indent.HasValue)
46 {
47 Json.AppendLine();
48 Json.Append(new string('\t', Indent.Value));
49 }
50
51 JSON.Encode(e.Current, Indent, Json);
52 }
53
54 if (Indent.HasValue)
55 {
56 Indent--;
57
58 if (!First)
59 {
60 Json.AppendLine();
61 Json.Append(new string('\t', Indent.Value));
62 }
63 }
64
65 Json.Append(']');
66 }
67
73 public Grade Supports(Type ObjectType)
74 {
75 return typeof(IEnumerable).GetTypeInfo().IsAssignableFrom(ObjectType.GetTypeInfo()) ? Grade.Barely : Grade.NotAtAll;
76 }
77 }
78}
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
void Encode(object Object, int? Indent, StringBuilder Json)
Encodes the Object to JSON.
Grade Supports(Type ObjectType)
How well the JSON encoder encodes objects of type ObjectType .
Interface for encoding objects of certain types to JSON.
Definition: IJsonEncoder.cs:11
Grade
Grade enumeration
Definition: Grade.cs:7