ScriptStack 1.0.4
Loading...
Searching...
No Matches
ArrayList.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.Threading;
5
7{
8
9 public class ArrayList : Dictionary<object, object>
10 {
11
12 #region Private Methods
13
14 private void OutputValue(StringBuilder stringBuilder, object objectValue)
15 {
16
17 if (objectValue.GetType() != typeof(ArrayList))
18 stringBuilder.Append("\"" + objectValue + "\"");
19
20 else
21 stringBuilder.Append(objectValue);
22
23 return;
24
25 }
26
27 private bool EqualValues(object objectValue1, object objectValue2)
28 {
29
30 Type type1 = objectValue1.GetType();
31
32 Type type2 = objectValue2.GetType();
33
34 if (type1 == typeof(int) && type2 == typeof(int))
35 return (int)objectValue1 == (int)objectValue2;
36
37 else if (type1 == typeof(int) && type2 == typeof(float))
38 return (int)objectValue1 == (float)objectValue2;
39
40 else if (type1 == typeof(float) && type2 == typeof(int))
41 return (float)objectValue1 == (int)objectValue2;
42
43 else if (type1 == typeof(float) && type2 == typeof(float))
44 return (float)objectValue1 == (float)objectValue2;
45
46 else if (type1 == typeof(string) || type2 == typeof(string))
47 return objectValue1.ToString() == objectValue2.ToString();
48
49 else return objectValue1 == objectValue2;
50
51 }
52
53 private void AddValue(object objectValue)
54 {
55 int iIndex = 0;
56 while (ContainsKey(iIndex)) ++iIndex;
57 this[iIndex] = objectValue;
58 }
59
60 private void SubtractValue(object objectValue)
61 {
62 List<object> listValues = new List<object>();
63 foreach (object objectOldValue in Values)
64 {
65 if (!EqualValues(objectOldValue, objectValue)) listValues.Add(objectOldValue);
66 }
67 Clear();
68 int iIndex = 0;
69 foreach (object objectOldValue in listValues)
70 {
71 this[iIndex++] = objectOldValue;
72 }
73 }
74
75 private void AddArray(ArrayList assocativeArray)
76 {
77 int iIndex = 0;
78 while (ContainsKey(iIndex)) ++iIndex;
79 foreach (object objectValue in assocativeArray.Values)
80 {
81 this[iIndex++] = objectValue;
82 }
83 }
84
85 private void SubtractArray(ArrayList associativeArray)
86 {
87 foreach (object objectValue in associativeArray.Values)
88 SubtractValue(objectValue);
89 }
90
91 #endregion
92
93 #region Public Methods
94
95 public void Add(object objectValue)
96 {
97
98 if (objectValue.GetType() == typeof(ArrayList))
99 AddArray((ArrayList)objectValue);
100
101 else
102 AddValue(objectValue);
103
104 }
105
106 public void Subtract(object objectValue)
107 {
108
109 if (objectValue.GetType() == typeof(ArrayList))
110 SubtractArray((ArrayList)objectValue);
111
112 else SubtractValue(objectValue);
113
114 }
115
116 public override string ToString()
117 {
118 string culture = Thread.CurrentThread.CurrentCulture.NumberFormat.PercentDecimalSeparator;
119 string decimalSeparator = ",";
120 //if (culture.ToString().Trim() == ",") decimalSeparator = ";";
121 StringBuilder stringBuilder = new StringBuilder();
122 stringBuilder.Append("{ ");
123 bool bFirst = true;
124 foreach (object objectKey in Keys)
125 {
126 if (!bFirst) stringBuilder.Append(decimalSeparator + " ");
127 bFirst = false;
128 OutputValue(stringBuilder, objectKey);
129 stringBuilder.Append(": ");
130 OutputValue(stringBuilder, this[objectKey]);
131 }
132 stringBuilder.Append(" }");
133 return stringBuilder.ToString();
134 }
135
136 #endregion
137
138 #region Public Properties
139
140 public new object this[object objectKey]
141 {
142
143 get
144 {
145
146 if (objectKey.GetType() == typeof(string) && ((string)objectKey) == "size")
147 return this.Count;
148
149 if (!ContainsKey(objectKey))
150 return NullReference.Instance;
151
152 return base[objectKey];
153
154 }
155 set
156 {
157
158 if (objectKey == null)
159 objectKey = NullReference.Instance;
160
161 if (objectKey.GetType() == typeof(string) && ((string)objectKey) == "size")
162 throw new ExecutionException("Der Member 'size' eines Arrays ist eine 'read-only' Eigenschaft.");
163
164 if (value == null)
165 base[objectKey] = NullReference.Instance;
166
167 else
168 base[objectKey] = value;
169
170 }
171
172 }
173
174 #endregion
175
176 }
177
178}
override string ToString()
Definition ArrayList.cs:116
void Subtract(object objectValue)
Definition ArrayList.cs:106
void Add(object objectValue)
Definition ArrayList.cs:95