2using System.Collections.Generic;
5using System.Globalization;
13 #region Private Methods
15 private void OutputValue(StringBuilder stringBuilder,
object objectValue)
18 if (objectValue.GetType() != typeof(
ArrayList))
19 stringBuilder.Append(
"\"" + objectValue +
"\"");
22 stringBuilder.Append(objectValue);
28 private bool EqualValues(
object objectValue1,
object objectValue2)
31 Type type1 = objectValue1.GetType();
33 Type type2 = objectValue2.GetType();
35 if (type1 == typeof(
int) && type2 == typeof(
int))
36 return (
int)objectValue1 == (int)objectValue2;
38 else if (type1 == typeof(
int) && type2 == typeof(
float))
39 return (
int)objectValue1 == (float)objectValue2;
41 else if (type1 == typeof(
float) && type2 == typeof(
int))
42 return (
float)objectValue1 == (int)objectValue2;
44 else if (type1 == typeof(
float) && type2 == typeof(
float))
45 return (
float)objectValue1 == (float)objectValue2;
47 else if (type1 == typeof(
string) || type2 == typeof(
string))
48 return objectValue1.ToString() == objectValue2.ToString();
50 else return objectValue1 == objectValue2;
57 while (ContainsKey(iIndex)) ++iIndex;
58 this[iIndex] = objectValue;
63 List<object> listValues =
new List<object>();
64 foreach (
object objectOldValue
in Values)
66 if (!
EqualValues(objectOldValue, objectValue)) listValues.Add(objectOldValue);
70 foreach (
object objectOldValue
in listValues)
72 this[iIndex++] = objectOldValue;
79 while (ContainsKey(iIndex)) ++iIndex;
80 foreach (
object objectValue
in assocativeArray.Values)
82 this[iIndex++] = objectValue;
88 foreach (
object objectValue
in associativeArray.Values)
94 #region Public Methods
96 public void Add(
object objectValue)
99 if (objectValue.GetType() == typeof(
ArrayList))
110 if (objectValue.GetType() == typeof(
ArrayList))
123 var sb =
new StringBuilder();
126 return sb.ToString();
129 private static void WriteJsonValue(StringBuilder sb,
object value, HashSet<object> stack)
131 if (value ==
null || value is NullReference)
143 switch (Type.GetTypeCode(value.GetType()))
145 case TypeCode.Boolean:
146 sb.Append(((
bool)value) ?
"true" :
"false");
148 case TypeCode.String:
157 case TypeCode.UInt16:
158 case TypeCode.UInt32:
159 case TypeCode.UInt64:
160 case TypeCode.Single:
161 case TypeCode.Double:
162 case TypeCode.Decimal:
166 sb.Append(Convert.ToString(value, CultureInfo.InvariantCulture));
168 case TypeCode.DateTime:
189 bool allIntKeys =
true;
191 foreach (var k
in al.Keys)
193 if (k is
int i && i >= 0)
195 if (i > maxIndex) maxIndex = i;
206 for (
int i = 0; i <= maxIndex; i++)
208 if (i > 0) sb.Append(
',');
209 if (al.TryGetValue(i, out var v))
220 foreach (var kv
in al)
222 if (!first) sb.Append(
',');
239 foreach (
char c
in s)
243 case '"': sb.Append(
"\\\"");
break;
244 case '\\': sb.Append(
"\\\\");
break;
245 case '\b': sb.Append(
"\\b");
break;
246 case '\f': sb.Append(
"\\f");
break;
247 case '\n': sb.Append(
"\\n");
break;
248 case '\r': sb.Append(
"\\r");
break;
249 case '\t': sb.Append(
"\\t");
break;
252 sb.Append(
"\\u" + ((
int)c).
ToString(
"x4"));
268 public new bool Equals(
object x,
object y) => ReferenceEquals(x, y);
269 public int GetHashCode(
object obj) => System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(obj);
274 #region Public Properties
276 public new object this[
object objectKey]
282 if (objectKey.GetType() == typeof(
string) && ((
string)objectKey) ==
"size")
285 if (!ContainsKey(objectKey))
286 return NullReference.Instance;
288 return base[objectKey];
294 if (objectKey ==
null)
295 objectKey = NullReference.Instance;
297 if (objectKey.GetType() == typeof(
string) && ((
string)objectKey) ==
"size")
298 throw new ExecutionException(
"Der Member 'size' eines Arrays ist eine 'read-only' Eigenschaft.");
301 base[objectKey] = NullReference.Instance;
304 base[objectKey] = value;
Reference equality comparer for cycle detection.
int GetHashCode(object obj)
static readonly ReferenceEqualityComparer Instance
new bool Equals(object x, object y)
void SubtractArray(ArrayList associativeArray)
static void WriteJsonArrayList(StringBuilder sb, ArrayList al, HashSet< object > stack)
override string ToString()
void Subtract(object objectValue)
void AddValue(object objectValue)
void SubtractValue(object objectValue)
bool EqualValues(object objectValue1, object objectValue2)
void Add(object objectValue)
static void WriteJsonString(StringBuilder sb, string s)
static void WriteJsonValue(StringBuilder sb, object value, HashSet< object > stack)
void AddArray(ArrayList assocativeArray)
void OutputValue(StringBuilder stringBuilder, object objectValue)