-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathPlatformSupport.cs
247 lines (222 loc) · 8.6 KB
/
PlatformSupport.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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#if WINDOWS_UWP
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Windows.Networking;
using Windows.Networking.Sockets;
#endif
#if NETSTANDARD || PCL || WINDOWS_UWP
// This interface doesn't exist in DNXCORE50, define it manually
namespace System
{
public interface ICloneable
{
object Clone();
}
}
#endif
namespace System.Collections.Generic
{
using System.Collections.ObjectModel;
using Microsoft.Azure.Amqp;
/// <summary>Provides a collection whose items are types that serve as keys.</summary>
/// <typeparam name="TItem">The item types contained in the collection that also serve as the keys for the collection.</typeparam>
public class KeyedByTypeCollection<TItem> : KeyedCollection<Type, TItem>
{
/// <summary>Initializes a new instance of the <see cref="T:System.Collections.Generic.KeyedByTypeCollection`1" /> class. </summary>
public KeyedByTypeCollection() : base(null, 4)
{
}
/// <summary>Initializes a new instance of the <see cref="T:System.Collections.Generic.KeyedByTypeCollection`1" /> class for a specified enumeration of objects.</summary>
/// <param name="items">The <see cref="T:System.Collections.Generic.IEnumerable`1" /> of generic type <see cref="T:System.Object" /> used to initialize the collection.</param>
/// <exception cref="T:System.ArgumentNullException">
/// <paramref name="items" /> is null.</exception>
public KeyedByTypeCollection(IEnumerable<TItem> items) : base(null, 4)
{
if (items == null)
{
throw new ArgumentNullException("items");
}
foreach (TItem current in items)
{
base.Add(current);
}
}
/// <summary>Returns the first item in the collection of a specified type.</summary>
/// <returns>The object of type <paramref name="T" /> if it is a reference type and the value of type <paramref name="T" /> if it is a value type. The default value of the type is returned if no object of type <paramref name="T" /> is contained in the collection: null if it is a reference type and 0 if it is a value type.</returns>
/// <typeparam name="T">The type of item in the collection to find.</typeparam>
public T Find<T>()
{
return this.Find<T>(false);
}
/// <summary>Removes an object of a specified type from the collection.</summary>
/// <returns>The object removed from the collection.</returns>
/// <typeparam name="T">The type of item in the collection to remove.</typeparam>
public T Remove<T>()
{
return this.Find<T>(true);
}
T Find<T>(bool remove)
{
for (int i = 0; i < base.Count; i++)
{
TItem tItem = base[i];
if (tItem is T)
{
if (remove)
{
base.Remove(tItem);
}
return (T)((object)tItem);
}
}
return default(T);
}
/// <summary>Returns a collection of objects of type <paramref name="T" /> that are contained in the <see cref="T:System.Collections.Generic.KeyedByTypeCollection`1" />.</summary>
/// <returns>A <see cref="T:System.Collections.ObjectModel.Collection`1" /> of type <paramref name="T" /> that contains the objects of type <paramref name="T" /> from the original collection.</returns>
/// <typeparam name="T">The type of item in the collection to find.</typeparam>
public Collection<T> FindAll<T>()
{
return this.FindAll<T>(false);
}
/// <summary>Removes all of the elements of a specified type from the collection.</summary>
/// <returns>The <see cref="T:System.Collections.ObjectModel.Collection`1" /> that contains the objects of type <paramref name="T" /> from the original collection.</returns>
/// <typeparam name="T">The type of item in the collection to remove.</typeparam>
public Collection<T> RemoveAll<T>()
{
return this.FindAll<T>(true);
}
Collection<T> FindAll<T>(bool remove)
{
Collection<T> collection = new Collection<T>();
foreach (TItem current in this)
{
if (current is T)
{
collection.Add((T)((object)current));
}
}
if (remove)
{
foreach (T current2 in collection)
{
base.Remove((TItem)((object)current2));
}
}
return collection;
}
/// <summary>Gets the type of an item contained in the collection.</summary>
/// <returns>The type of the specified <paramref name="item" /> in the collection.</returns>
/// <param name="item">The item in the collection whose type is to be retrieved.</param>
/// <exception cref="T:System.ArgumentNullException">
/// <paramref name="item" /> is null.</exception>
protected override Type GetKeyForItem(TItem item)
{
if (item == null)
{
throw new ArgumentNullException("item");
}
return item.GetType();
}
/// <summary>Inserts an element into the collection at a specific location.</summary>
/// <param name="index">The zero-based index at which <paramref name="item" /> should be inserted. </param>
/// <param name="item">The object to insert into the collection.</param>
/// <exception cref="T:System.ArgumentNullException">
/// <paramref name="item" /> is null.</exception>
protected override void InsertItem(int index, TItem item)
{
if (item == null)
{
throw new ArgumentNullException("item");
}
if (base.Contains(item.GetType()))
{
string message = string.Format(
"The value could not be added to the collection, as the collection already contains an item of the same type: '{0}'. This collection only supports one instance of each type.",
item.GetType().FullName);
throw new ArgumentNullException("item", message);
}
base.InsertItem(index, item);
}
/// <summary>Replaces the item at the specified index with a new object.</summary>
/// <param name="index">The zero-based index of the <paramref name="item" /> to be replaced.</param>
/// <param name="item">The object to add to the collection.</param>
/// <exception cref="T:System.ArgumentNullException">
/// <paramref name="item" /> is null.</exception>
protected override void SetItem(int index, TItem item)
{
if (item == null)
{
throw new ArgumentNullException("item");
}
base.SetItem(index, item);
}
}
}
#if WINDOWS_UWP || PCL
namespace System.Threading
{
//
// Summary:
// Represents a callback method to be executed by a thread pool thread.
//
// Parameters:
// state:
// An object containing information to be used by the callback method.
public delegate void WaitCallback(object state);
}
#endif
#if WINDOWS_UWP
class Win32
{
[DllImport("kernel32.dll")]
public static extern int GetCurrentProcessId();
}
#endif
namespace Diagnostics
{
static class CurrentProcess
{
public static int ID
{
get
{
#if WINDOWS_UWP
return Win32.GetCurrentProcessId();
#elif PCL
throw new System.NotImplementedException();
#else
return System.Diagnostics.Process.GetCurrentProcess().Id;
#endif
}
}
}
}
namespace Platform.System.Text
{
#if PCL
class Encoding
{
public static global::System.Text.Encoding ASCII
{
get
{
throw new global::System.NotImplementedException(Microsoft.Azure.Amqp.PCL.Resources.ReferenceAssemblyInvalidUse);
}
}
}
#else
class Encoding
{
public static global::System.Text.Encoding ASCII
{
get
{
return global::System.Text.Encoding.ASCII;
}
}
}
#endif
}