-
Notifications
You must be signed in to change notification settings - Fork 0
/
UtilityCollection.cs
190 lines (171 loc) · 7.04 KB
/
UtilityCollection.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*
200303210923 Created.
REFERENCE
C# Programmer's ArrayList.IndexOf Method
ms-help://MS.NETFrameworkSDKv1.1/cpref/html/frlrfSystemCollectionsArrayListClassIndexOfTopic.htm
*/
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Text;
using System.Web;
namespace WordEngineering
{
/// <summary>UtilityCollection will offer collection services.</summary>
/// <remarks>UtilityCollection will offer collection services.</remarks>
public class UtilityCollection
{
/// <summary>The entry point for the application.</summary>
/// <param name="argv">A list of command line arguments</param>
public static void Main
(
string[] argv
)
{
}//public static void Main
/// <summary>Concatenate index and values</summary>
/// <param name="list">Supports a simple iteration over a collection.</param>
/// <code>
/// <example>
/// ArrayList arrayListBibleBook = new ArrayList();
/// arrayListBibleBook.Add("Genesis");
/// arrayListBibleBook.Add("Exodus");
/// arrayListBibleBook.Add("Leveticus");
/// arrayListBibleBook.Add("Numbers");
/// arrayListBibleBook.Add("Deuteronomy");
/// System.Console.WriteLine("Bible Books Collection: {0}", UtilityCollection.ToString(arrayListBibleBook));
/// </example>
/// </code>
public static string ToString( IEnumerable list )
{
StringBuilder sb = new StringBuilder();
System.Collections.IEnumerator enumerator = list.GetEnumerator();
while ( enumerator.MoveNext() )
{
sb.Append(enumerator.Current);
sb.Append(ElementSeparator);
}//while ( enumerator.MoveNext() )
return sb.ToString();
}//public override string ToString( IEnumerable list )
/// <summary>Returns the index of the first occurrence of a value in a two-dimensional Array.</summary>
/// <param name="array">The array.</param>
/// <param name="key">The key.</param>
public static string IndexOf
(
string[][] array,
string key
)
{
return IndexOf( array, key, 0, 1 );
}
/// <summary>Returns the index of the first occurrence of a value in a two-dimensional Array.</summary>
/// <param name="array">The array.</param>
/// <param name="key">The key.</param>
/// <param name="rankKey">The array dimension's key.</param>
/// <param name="rankValue">The array dimension's value.</param>
public static string IndexOf
(
string[][] array,
string key,
int rankKey,
int rankValue
)
{
int index = -1;
int length = array.Length;
string value = null;
for ( index = 0; index < length; ++index )
{
if ( string.Compare( array[index][rankKey], key, true ) == 0 )
{
value = array[index][rankValue];
break;
}//if ( string.Compare( array[index][rankKey], rankValue, true ) == 0 )
}//for ( index = 0; index < length; ++index )
return ( value );
}//public static string IndexOf( string[][] array, int rankKey, int rankValue )
/// <summary>NameValueCollection: Extract the key and value.</summary>
/// <param name="nameValueCollection">The name value collection.</param>
/// <param name="nameValueCollectionKey">The name value collection key.</param>
/// <param name="nameValueCollectionValue">The name value collection value.</param>
public static void NameValueCollectionExtract
(
NameValueCollection nameValueCollection,
ref String[] nameValueCollectionKey,
ref String[][] nameValueCollectionValue
)
{
int nameValueCollectionKeyIndex = 0;
int nameValueCollectionKeyTotal = 0;
int nameValueCollectionValueIndex = 0;
int nameValueCollectionValueTotal = 0;
HttpContext httpContext = HttpContext.Current;
nameValueCollectionKeyTotal = nameValueCollection.Count;
nameValueCollectionKey = new String[nameValueCollectionKeyTotal];
nameValueCollectionKey = nameValueCollection.AllKeys;
nameValueCollectionValue = new String[nameValueCollectionKeyTotal][];
for
(
nameValueCollectionKeyIndex = 0;
nameValueCollectionKeyIndex < nameValueCollectionKeyTotal;
++nameValueCollectionKeyIndex
)
{
nameValueCollectionValue[ nameValueCollectionKeyIndex ] = new String[nameValueCollectionKeyIndex];
nameValueCollectionValue[ nameValueCollectionKeyIndex ] =
nameValueCollection.GetValues(nameValueCollectionKey[nameValueCollectionKeyIndex]);
if ( httpContext != null )
{
nameValueCollectionKey[nameValueCollectionKeyIndex] = httpContext.Server.HtmlEncode( nameValueCollectionKey[nameValueCollectionKeyIndex] );
#if (DEBUG)
httpContext.Response.Write("Key: " + nameValueCollectionKey[nameValueCollectionKeyIndex] + "<br/>");
#endif
}//if ( httpContext != null )
nameValueCollectionValueTotal = nameValueCollectionValue[ nameValueCollectionKeyIndex ].Length;
for
(
nameValueCollectionValueIndex = 0;
nameValueCollectionValueIndex < nameValueCollectionValueTotal;
++nameValueCollectionValueIndex
)
{
if ( httpContext != null )
{
nameValueCollectionValue[nameValueCollectionKeyIndex][nameValueCollectionValueIndex] = httpContext.Server.HtmlEncode( nameValueCollectionValue[nameValueCollectionKeyIndex][nameValueCollectionValueIndex] );
#if (DEBUG)
httpContext.Response.Write("Value: " + nameValueCollectionValue[nameValueCollectionKeyIndex][nameValueCollectionValueIndex] + "<br/>");
#endif
}//if ( httpContext != null )
}//for ( nameValueCollectionValueIndex = 0; nameValueCollectionValueIndex < nameValueCollectionValueTotal; ++nameValueCollectionValueIndex )
}//for ( nameValueCollectionKeyIndex = 0; nameValueCollectionKeyIndex < nameValueCollectionKeyTotal; ++nameValueCollectionKeyIndex )
}//public static void NameValueCollectionExtract( NameValueCollection nameValueCollection, ref String[] nameValueCollectionKey, ref String[][] nameValueCollectionValue )
///<summary>PrintKeysAndValues()</summary>
public static void PrintKeysAndValues
(
Hashtable hashtable
)
{
HttpContext httpContext = HttpContext.Current;
IDictionaryEnumerator iDictionaryEnumerator;
iDictionaryEnumerator = hashtable.GetEnumerator();
while ( iDictionaryEnumerator.MoveNext() )
{
if ( httpContext == null )
{
System.Console.WriteLine
(
"{0} | {1}",
iDictionaryEnumerator.Key,
iDictionaryEnumerator.Value
);
}
else
{
httpContext.Response.Write( "Key: " + iDictionaryEnumerator.Key + " | " + " Value: " + iDictionaryEnumerator.Value + "<br/>" );
}
}//while ( iDictionaryEnumerator.MoveNext() )
}//public static void PrintKeysAndValues()
/// <summary>The element separator.</summary>
public const char ElementSeparator = '|';
}//public class UtilityCollection
}//namespace WordEngineering