@@ -10,195 +10,6 @@ namespace AddDigitalSignature
10
10
{
11
11
public static class ExtensionMethods
12
12
{
13
-
14
- public static void Clear ( this BlockingCollection < string > blockingCollection )
15
- {
16
- try
17
- {
18
- if ( blockingCollection == null )
19
- {
20
- return ;
21
- }
22
-
23
- while ( blockingCollection . Count > 0 )
24
- {
25
- string item ;
26
- blockingCollection . TryTake ( out item ) ;
27
- item = null ;
28
- }
29
-
30
- blockingCollection . Dispose ( ) ;
31
- }
32
- catch ( System . Exception ex )
33
- {
34
- //cGlobalSettings.oLogger.WriteLogException("Clear", ex);
35
- }
36
-
37
- }
38
-
39
-
40
- public static void Clear ( this BlockingCollection < int > blockingCollection )
41
- {
42
- try
43
- {
44
- if ( blockingCollection == null )
45
- {
46
- return ;
47
- }
48
-
49
- while ( blockingCollection . Count > 0 )
50
- {
51
- int item ;
52
- blockingCollection . TryTake ( out item ) ;
53
- }
54
-
55
- blockingCollection . Dispose ( ) ;
56
- }
57
- catch ( System . Exception ex )
58
- {
59
- //cGlobalSettings.oLogger.WriteLogException("Clear", ex);
60
- }
61
-
62
- }
63
-
64
- public static IEnumerable < T > Distinct < T , TKey > ( this IEnumerable < T > @this , Func < T , TKey > keySelector )
65
- {
66
- return @this . GroupBy ( keySelector ) . Select ( grps => grps ) . Select ( e => e . First ( ) ) ;
67
- }
68
-
69
-
70
- public static Dictionary < TKey , TValue >
71
- Merge < TKey , TValue > ( Dictionary < TKey , TValue > [ ] dicts ,
72
- Func < IGrouping < TKey , TValue > , TValue > resolveDuplicates )
73
- {
74
- if ( resolveDuplicates == null )
75
- resolveDuplicates = new Func < IGrouping < TKey , TValue > , TValue > ( group => group . First ( ) ) ;
76
-
77
- return dicts . SelectMany < Dictionary < TKey , TValue > , KeyValuePair < TKey , TValue > > ( dict => dict )
78
- . ToLookup ( pair => pair . Key , pair => pair . Value )
79
- . ToDictionary ( group => group . Key , group => resolveDuplicates ( group ) ) ;
80
- }
81
-
82
-
83
-
84
-
85
-
86
-
87
-
88
-
89
- public static Dictionary < TKey , TValue > Merge < TKey , TValue > ( this IEnumerable < Dictionary < TKey , TValue > > dicts ,
90
- Func < IGrouping < TKey , TValue > , TValue > resolveDuplicates )
91
- {
92
- if ( resolveDuplicates == null )
93
- resolveDuplicates = new Func < IGrouping < TKey , TValue > , TValue > ( group => group . First ( ) ) ;
94
-
95
- return dicts . SelectMany < Dictionary < TKey , TValue > , KeyValuePair < TKey , TValue > > ( dict => dict )
96
- . ToLookup ( pair => pair . Key , pair => pair . Value )
97
- . ToDictionary ( group => group . Key , group => resolveDuplicates ( group ) ) ;
98
- }
99
-
100
- public static long ToLong ( long nFileSizeHigh , long nFileSizeLow )
101
- {
102
- return ( long ) ( ( nFileSizeHigh << 0x20 ) | ( nFileSizeLow & 0xffffffffL ) ) ;
103
-
104
- }
105
-
106
- public static DateTime ToDateTime ( this System . Runtime . InteropServices . ComTypes . FILETIME filetime )
107
- {
108
- long highBits = filetime . dwHighDateTime ;
109
- highBits = highBits << 32 ;
110
- return DateTime . FromFileTimeUtc ( highBits + ( long ) filetime . dwLowDateTime ) ;
111
- }
112
-
113
-
114
- public static long ToLong ( this System . Runtime . InteropServices . ComTypes . FILETIME filetime )
115
- {
116
- long highBits = filetime . dwHighDateTime ;
117
- highBits = highBits << 32 ;
118
- return DateTime . FromFileTimeUtc ( highBits + ( long ) filetime . dwLowDateTime ) . Ticks ;
119
- }
120
-
121
- /// <summary>
122
- /// http://stackoverflow.com/questions/419019/split-list-into-sublists-with-linq
123
- ///
124
- /// </summary>
125
- /// <typeparam name="T"></typeparam>
126
- /// <param name="source"></param>
127
- /// <param name="groupSize"></param>
128
- /// <returns></returns>
129
- public static List < List < T > > Split < T > ( this List < T > source , int groupSize )
130
- {
131
- return source
132
- . Select ( ( x , i ) => new { Index = i , Value = x } )
133
- . GroupBy ( x => x . Index / groupSize /*3*/ )
134
- . Select ( x => x . Select ( v => v . Value ) . ToList ( ) )
135
- . ToList ( ) ;
136
- }
137
-
138
-
139
- // public static string SafeGetString(this SQLiteDataReader reader, int colIndex)
140
- // {
141
- // if (!reader.IsDBNull(colIndex))
142
- // return reader.GetString(colIndex);
143
- // else
144
- // return string.Empty;
145
- // }
146
-
147
- // public static Int32 SafeGetInt32(this SQLiteDataReader reader, int colIndex, Int32 defaultReturnValue)
148
- // {
149
- // if (!reader.IsDBNull(colIndex))
150
- // return reader.GetInt32(colIndex);
151
- // else
152
- // return defaultReturnValue;
153
- // }
154
-
155
- // public static Int64 SafeGetInt64(this SQLiteDataReader reader, int colIndex, Int64 defaultReturnValue)
156
- // {
157
- // if (!reader.IsDBNull(colIndex))
158
- // return reader.GetInt64(colIndex);
159
- // else
160
- // return defaultReturnValue;
161
- // }
162
-
163
- // public static T SafeGetValue<T>(this SQLiteDataReader reader, int colIndex, T defaultReturnValue)
164
- // {
165
- // if (!reader.IsDBNull(colIndex))
166
- // {
167
- // if (typeof(T) == typeof(int))
168
- // {
169
- // return (T)Convert.ChangeType(reader.GetInt32(colIndex), typeof(T));
170
- // }
171
- // else if (typeof(T) == typeof(long))
172
- // {
173
- // return (T)Convert.ChangeType(reader.GetInt64(colIndex), typeof(T));
174
- // }
175
- // else if (typeof(T) == typeof(string))
176
- // {
177
- // return (T)Convert.ChangeType(reader.GetString(colIndex), typeof(T));
178
- // }
179
- // else
180
- // {
181
- ////#error "not defined"
182
- // Debug.Assert(false);
183
- // }
184
-
185
-
186
- // }
187
-
188
- // return defaultReturnValue;
189
- // }
190
-
191
- public static List < Dictionary < T1 , T2 > > Split < T1 , T2 > ( this Dictionary < T1 , T2 > source , int groupSize )
192
- {
193
- return source
194
- . Select ( ( x , i ) => new { Index = i , Value = x } )
195
- . GroupBy ( x => x . Index / groupSize /*3*/ )
196
- . Select ( x => x . Select ( v => v . Value ) . ToDictionary ( z => z . Key , z => z . Value ) )
197
- . ToList ( ) ;
198
- }
199
-
200
-
201
-
202
13
public static IEnumerable < string > Split ( this string str , int n )
203
14
{
204
15
if ( String . IsNullOrEmpty ( str ) || n < 1 )
@@ -212,12 +23,4 @@ public static IEnumerable<string> Split(this string str, int n)
212
23
}
213
24
}
214
25
}
215
-
216
- static class DataRowExtensions
217
- {
218
- public static object GetValueWithContainsCheck ( this DataRow row , string column )
219
- {
220
- return row . Table . Columns . Contains ( column ) ? row ? [ column ] : null ;
221
- }
222
- }
223
26
}
0 commit comments