Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ObjectExNihiloOutput.cs
1using System;
2using System.Collections.Generic;
3using System.Text;
6
8{
13 {
19 public Grade Supports(Type Object) => Object == typeof(Dictionary<string, IElement>) ? Grade.Ok : Grade.NotAtAll;
20
26 public string GetString(object Value)
27 {
28 Dictionary<string, IElement> ObjExNihilo = (Dictionary<string, IElement>)Value;
29
30 StringBuilder sb = new StringBuilder();
31 bool First = true;
32
33 sb.Append('{');
34
35 foreach (KeyValuePair<string, IElement> P in ObjExNihilo)
36 {
37 if (First)
38 First = false;
39 else
40 sb.Append(',');
41
42 if (CanBeVariable(P.Key))
43 sb.Append(P.Key);
44 else
45 {
46 sb.Append('"');
47 sb.Append(P.Key.
48 Replace("\\", "\\\\").
49 Replace("\"", "\\\"").
50 Replace("\n", "\\n").
51 Replace("\r", "\\r").
52 Replace("\t", "\\t").
53 Replace("\b", "\\b").
54 Replace("\f", "\\f").
55 Replace("\a", "\\a"));
56 sb.Append('"');
57 }
58
59 sb.Append(':');
60 sb.Append(Expression.ToString(P.Value.AssociatedObjectValue));
61 }
62
63 sb.Append('}');
64
65 return sb.ToString();
66 }
67
73 public static bool CanBeVariable(string Label)
74 {
75 bool HasLetters = false;
76
77 foreach (char ch in Label)
78 {
79 if (char.IsLetter(ch))
80 HasLetters = true;
81 else if (char.IsDigit(ch))
82 {
83 if (!HasLetters)
84 return false;
85 }
86 else if (ch != '_')
87 return false;
88 }
89
90 return HasLetters;
91 }
92 }
93}
Class managing a script expression.
Definition: Expression.cs:39
static string ToString(double Value)
Converts a value to a string, that can be parsed as part of an expression.
Definition: Expression.cs:4496
Converts values of type Dictionary{string, IElement} to expression strings.
string GetString(object Value)
Gets a string representing a value.
Grade Supports(Type Object)
If the interface understands objects such as Object .
static bool CanBeVariable(string Label)
Checks if a label can be used as a variable directly or not.
Interface for custom string output classes. Converts objects of a given type to an expression string.
Grade
Grade enumeration
Definition: Grade.cs:7