Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
GenericObjectOutput.cs
1using System;
2using System.Collections.Generic;
3using System.Text;
7
9{
14 {
20 public Grade Supports(Type Object) => Object == typeof(GenericObject) ? Grade.Ok : Grade.NotAtAll;
21
27 public string GetString(object Value)
28 {
29 GenericObject Obj = (GenericObject)Value;
30
31 StringBuilder sb = new StringBuilder();
32 bool First = true;
33
34 sb.Append('{');
35
36 if (!string.IsNullOrEmpty(Obj.CollectionName) && !Obj.TryGetFieldValue("CollectionName", out object _))
37 this.Output("CollectionName", Obj.CollectionName, ref First, sb);
38
39 if (!string.IsNullOrEmpty(Obj.TypeName) && !Obj.TryGetFieldValue("TypeName", out object _))
40 this.Output("TypeName", Obj.TypeName, ref First, sb);
41
42 if (Obj.ObjectId != Guid.Empty && !Obj.TryGetFieldValue("ObjectId", out object _))
43 this.Output("ObjectId", Obj.ObjectId.ToString(), ref First, sb);
44
45 foreach (KeyValuePair<string, object> P in Obj.Properties)
46 this.Output(P.Key, P.Value, ref First, sb);
47
48 sb.Append('}');
49
50 return sb.ToString();
51 }
52
53 private void Output(string Name, object Value, ref bool First, StringBuilder sb)
54 {
55 if (First)
56 First = false;
57 else
58 sb.Append(", ");
59
61 sb.Append(Name);
62 else
63 {
64 sb.Append('"');
65 sb.Append(Name.
66 Replace("\\", "\\\\").
67 Replace("\"", "\\\"").
68 Replace("\n", "\\n").
69 Replace("\r", "\\r").
70 Replace("\t", "\\t").
71 Replace("\b", "\\b").
72 Replace("\f", "\\f").
73 Replace("\a", "\\a"));
74 sb.Append('"');
75 }
76
77 sb.Append(": ");
78 sb.Append(Expression.ToString(Value));
79 }
80 }
81}
Generic object. Contains a sequence of properties.
bool TryGetFieldValue(string PropertyName, out object Value)
Gets the value of a field or property of the object, given its name.
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.
static bool CanBeVariable(string Label)
Checks if a label can be used as a variable directly or not.
Converts values of type GenericObject to expression strings.
Grade Supports(Type Object)
If the interface understands objects such as Object .
string GetString(object Value)
Gets a string representing a value.
Interface for custom string output classes. Converts objects of a given type to an expression string.
Grade
Grade enumeration
Definition: Grade.cs:7