forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPclExportClient.cs
More file actions
1827 lines (1547 loc) · 52.5 KB
/
PclExportClient.cs
File metadata and controls
1827 lines (1547 loc) · 52.5 KB
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//
// System.Collections.Specialized.NameObjectCollectionBase.cs
//
// Author:
// Gleb Novodran
// Andreas Nahr (ClassDevelopment@A-SoftTech.com)
//
// (C) Ximian, Inc. http://www.ximian.com
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
/*** REMINDER: Keep this file in sync with ServiceStack.Text/Pcl.NameValueCollection.cs ***/
using System.IO;
using System.Net;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using ServiceStack.Text;
using System.Globalization;
#if NETFX_CORE || PCL || SL5 || NETSTANDARD1_1
//namespace System.Collections.Specialized
namespace ServiceStack.Pcl
{
using System;
using System.Collections;
using System.Collections.Generic;
using System.Net;
using System.Reflection;
using System.Runtime.Serialization;
using System.Text;
public class Hashtable : Dictionary<string, object>
{
public Hashtable(IDictionary<string, object> dictionary, IEqualityComparer<string> comparer) : base(dictionary, comparer) {}
public Hashtable(int capacity, IEqualityComparer<string> comparer) : base(capacity, comparer) {}
public Hashtable(int capacity) : base(capacity) {}
public Hashtable(IDictionary<string, object> dictionary) : base(dictionary) {}
public Hashtable(IEqualityComparer<string> comparer) : base(comparer) {}
public Hashtable() {}
}
public class SerializableAttribute : Attribute {}
public class ArrayList : List<object>{}
public class StringEqualityComparer : IEqualityComparer<string>
{
private readonly IEqualityComparer comparer;
public StringEqualityComparer(IEqualityComparer comparer)
{
this.comparer = comparer;
}
public bool Equals(string x, string y)
{
if (x == null && y == null) return true;
if (x == null || y == null) return false;
return comparer.Equals(x, y);
}
public int GetHashCode(string obj)
{
return comparer.GetHashCode(obj);
}
}
[Serializable]
public abstract class NameObjectCollectionBase : ICollection, IEnumerable
//, ISerializable, IDeserializationCallback
{
private Hashtable m_ItemsContainer;
/// <summary>
/// Extends Hashtable based Items container to support storing null-key pairs
/// </summary>
private _Item m_NullKeyItem;
private ArrayList m_ItemsArray;
private IComparer m_comparer;
private int m_defCapacity;
private bool m_readonly;
SerializationInfo infoCopy;
private KeysCollection keyscoll;
private IEqualityComparer equality_comparer;
internal IEqualityComparer EqualityComparer
{
get { return equality_comparer; }
}
internal IComparer Comparer
{
get { return m_comparer; }
}
internal class _Item
{
public string key;
public object value;
public _Item(string key, object value)
{
this.key = key;
this.value = value;
}
}
/// <summary>
/// Implements IEnumerable interface for KeysCollection
/// </summary>
[Serializable]
internal class _KeysEnumerator : IEnumerator
{
private NameObjectCollectionBase m_collection;
private int m_position;
internal _KeysEnumerator(NameObjectCollectionBase collection)
{
m_collection = collection;
Reset();
}
public object Current
{
get
{
if ((m_position < m_collection.Count) || (m_position < 0))
return m_collection.BaseGetKey(m_position);
else
throw new InvalidOperationException();
}
}
public bool MoveNext()
{
return ((++m_position) < m_collection.Count);
}
public void Reset()
{
m_position = -1;
}
}
/// <summary>
/// SDK: Represents a collection of the String keys of a collection.
/// </summary>
[Serializable]
public class KeysCollection : ICollection, IEnumerable
{
private NameObjectCollectionBase m_collection;
internal KeysCollection(NameObjectCollectionBase collection)
{
this.m_collection = collection;
}
public virtual string Get(int index)
{
return m_collection.BaseGetKey(index);
}
// ICollection methods -----------------------------------
void ICollection.CopyTo(Array array, int arrayIndex)
{
ArrayList items = m_collection.m_ItemsArray;
if (null == array)
throw new ArgumentNullException("array");
if (arrayIndex < 0)
throw new ArgumentOutOfRangeException("arrayIndex");
if ((array.Length > 0) && (arrayIndex >= array.Length))
throw new ArgumentException("arrayIndex is equal to or greater than array.Length");
if (arrayIndex + items.Count > array.Length)
throw new ArgumentException("Not enough room from arrayIndex to end of array for this KeysCollection");
if (array != null && array.Rank > 1)
throw new ArgumentException("array is multidimensional");
object[] objArray = (object[])array;
for (int i = 0; i < items.Count; i++, arrayIndex++)
objArray[arrayIndex] = ((_Item)items[i]).key;
}
bool ICollection.IsSynchronized
{
get
{
return false;
}
}
object ICollection.SyncRoot
{
get
{
return m_collection;
}
}
/// <summary>
/// Gets the number of keys in the NameObjectCollectionBase.KeysCollection
/// </summary>
public int Count
{
get
{
return m_collection.Count;
}
}
public string this[int index]
{
get { return Get(index); }
}
// IEnumerable methods --------------------------------
/// <summary>
/// SDK: Returns an enumerator that can iterate through the NameObjectCollectionBase.KeysCollection.
/// </summary>
/// <returns></returns>
public IEnumerator GetEnumerator()
{
return new _KeysEnumerator(m_collection);
}
}
//--------------- Protected Instance Constructors --------------
/// <summary>
/// SDK: Initializes a new instance of the NameObjectCollectionBase class that is empty.
/// </summary>
protected NameObjectCollectionBase()
{
m_readonly = false;
m_comparer = StringComparer.Ordinal;
m_defCapacity = 0;
Init();
}
protected NameObjectCollectionBase(int capacity)
{
m_readonly = false;
m_comparer = StringComparer.Ordinal;
m_defCapacity = capacity;
Init();
}
protected NameObjectCollectionBase(IEqualityComparer equalityComparer)
: this(0, (equalityComparer ?? StringComparer.OrdinalIgnoreCase))
{
}
protected NameObjectCollectionBase(SerializationInfo info, StreamingContext context)
{
infoCopy = info;
}
protected NameObjectCollectionBase(int capacity, IEqualityComparer equalityComparer)
{
m_readonly = false;
equality_comparer = (equalityComparer ?? StringComparer.OrdinalIgnoreCase);
m_defCapacity = capacity;
Init();
}
private void Init()
{
if (m_ItemsContainer != null)
{
m_ItemsContainer.Clear();
m_ItemsContainer = null;
}
if (m_ItemsArray != null)
{
m_ItemsArray.Clear();
m_ItemsArray = null;
}
if (equality_comparer == null)
equality_comparer = StringComparer.OrdinalIgnoreCase;
m_ItemsContainer = new Hashtable(m_defCapacity, new StringEqualityComparer(equality_comparer));
m_ItemsArray = new ArrayList();
m_NullKeyItem = null;
}
//--------------- Public Instance Properties -------------------
public virtual NameObjectCollectionBase.KeysCollection Keys
{
get
{
if (keyscoll == null)
keyscoll = new KeysCollection(this);
return keyscoll;
}
}
//--------------- Public Instance Methods ----------------------
//
/// <summary>
/// SDK: Returns an enumerator that can iterate through the NameObjectCollectionBase.
///
/// <remark>This enumerator returns the keys of the collection as strings.</remark>
/// </summary>
/// <returns></returns>
public virtual IEnumerator GetEnumerator()
{
return new _KeysEnumerator(this);
}
// ISerializable
public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
{
if (info == null)
throw new ArgumentNullException("info");
int count = Count;
string[] keys = new string[count];
object[] values = new object[count];
int i = 0;
foreach (_Item item in m_ItemsArray)
{
keys[i] = item.key;
values[i] = item.value;
i++;
}
info.AddValue("KeyComparer", equality_comparer, typeof(IEqualityComparer));
info.AddValue("Version", 4, typeof(int));
info.AddValue("ReadOnly", m_readonly);
info.AddValue("Count", count);
info.AddValue("Keys", keys, typeof(string[]));
info.AddValue("Values", values, typeof(object[]));
}
// ICollection
public virtual int Count
{
get
{
return m_ItemsArray.Count;
}
}
bool ICollection.IsSynchronized
{
get { return false; }
}
object ICollection.SyncRoot
{
get { return this; }
}
void ICollection.CopyTo(Array array, int index)
{
((ICollection)Keys).CopyTo(array, index);
}
// IDeserializationCallback
public virtual void OnDeserialization(object sender)
{
SerializationInfo info = infoCopy;
// If a subclass overrides the serialization constructor
// and inplements its own serialization process, infoCopy will
// be null and we can ignore this callback.
if (info == null)
return;
infoCopy = null;
m_comparer = (IComparer)info.GetValue("Comparer", typeof(IComparer));
if (m_comparer == null)
throw new SerializationException("The comparer is null");
m_readonly = info.GetBoolean("ReadOnly");
string[] keys = (string[])info.GetValue("Keys", typeof(string[]));
if (keys == null)
throw new SerializationException("keys is null");
object[] values = (object[])info.GetValue("Values", typeof(object[]));
if (values == null)
throw new SerializationException("values is null");
Init();
int count = keys.Length;
for (int i = 0; i < count; i++)
BaseAdd(keys[i], values[i]);
}
//--------------- Protected Instance Properties ----------------
/// <summary>
/// SDK: Gets or sets a value indicating whether the NameObjectCollectionBase instance is read-only.
/// </summary>
protected bool IsReadOnly
{
get
{
return m_readonly;
}
set
{
m_readonly = value;
}
}
//--------------- Protected Instance Methods -------------------
/// <summary>
/// Adds an Item with the specified key and value into the <see cref="NameObjectCollectionBase"/>NameObjectCollectionBase instance.
/// </summary>
/// <param name="name"></param>
/// <param name="value"></param>
protected void BaseAdd(string name, object value)
{
if (this.IsReadOnly)
throw new NotSupportedException("Collection is read-only");
_Item newitem = new _Item(name, value);
if (name == null)
{
//todo: consider nullkey entry
if (m_NullKeyItem == null)
m_NullKeyItem = newitem;
}
else
if (!HasItem(name))
{
m_ItemsContainer.Add(name, newitem);
}
m_ItemsArray.Add(newitem);
}
protected void BaseClear()
{
if (this.IsReadOnly)
throw new NotSupportedException("Collection is read-only");
Init();
}
/// <summary>
/// SDK: Gets the value of the entry at the specified index of the NameObjectCollectionBase instance.
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
protected object BaseGet(int index)
{
return ((_Item)m_ItemsArray[index]).value;
}
/// <summary>
/// SDK: Gets the value of the first entry with the specified key from the NameObjectCollectionBase instance.
/// </summary>
/// <remark>CAUTION: The BaseGet method does not distinguish between a null reference which is returned because the specified key is not found and a null reference which is returned because the value associated with the key is a null reference.</remark>
/// <param name="name"></param>
/// <returns></returns>
protected object BaseGet(string name)
{
_Item item = FindFirstMatchedItem(name);
/// CAUTION: The BaseGet method does not distinguish between a null reference which is returned because the specified key is not found and a null reference which is returned because the value associated with the key is a null reference.
if (item == null)
return null;
else
return item.value;
}
/// <summary>
/// SDK:Returns a String array that contains all the keys in the NameObjectCollectionBase instance.
/// </summary>
/// <returns>A String array that contains all the keys in the NameObjectCollectionBase instance.</returns>
protected string[] BaseGetAllKeys()
{
int cnt = m_ItemsArray.Count;
string[] allKeys = new string[cnt];
for (int i = 0; i < cnt; i++)
allKeys[i] = BaseGetKey(i);//((_Item)m_ItemsArray[i]).key;
return allKeys;
}
/// <summary>
/// SDK: Returns an Object array that contains all the values in the NameObjectCollectionBase instance.
/// </summary>
/// <returns>An Object array that contains all the values in the NameObjectCollectionBase instance.</returns>
protected object[] BaseGetAllValues()
{
int cnt = m_ItemsArray.Count;
object[] allValues = new object[cnt];
for (int i = 0; i < cnt; i++)
allValues[i] = BaseGet(i);
return allValues;
}
protected object[] BaseGetAllValues(Type type)
{
if (type == null)
throw new ArgumentNullException("'type' argument can't be null");
int cnt = m_ItemsArray.Count;
object[] allValues = (object[])Array.CreateInstance(type, cnt);
for (int i = 0; i < cnt; i++)
allValues[i] = BaseGet(i);
return allValues;
}
protected string BaseGetKey(int index)
{
return ((_Item)m_ItemsArray[index]).key;
}
/// <summary>
/// Gets a value indicating whether the NameObjectCollectionBase instance contains entries whose keys are not a null reference
/// </summary>
/// <returns>true if the NameObjectCollectionBase instance contains entries whose keys are not a null reference otherwise, false.</returns>
protected bool BaseHasKeys()
{
return (m_ItemsContainer.Count > 0);
}
protected void BaseRemove(string name)
{
int cnt = 0;
String key;
if (this.IsReadOnly)
throw new NotSupportedException("Collection is read-only");
if (name != null)
{
m_ItemsContainer.Remove(name);
}
else
{
m_NullKeyItem = null;
}
cnt = m_ItemsArray.Count;
for (int i = 0; i < cnt; )
{
key = BaseGetKey(i);
if (Equals(key, name))
{
m_ItemsArray.RemoveAt(i);
cnt--;
}
else
i++;
}
}
/// <summary>
///
/// </summary>
/// <param name="index"></param>
/// <LAME>This function implemented the way Microsoft implemented it -
/// item is removed from hashtable and array without considering the case when there are two items with the same key but different values in array.
/// E.g. if
/// hashtable is [("Key1","value1")] and array contains [("Key1","value1")("Key1","value2")] then
/// after RemoveAt(1) the collection will be in following state:
/// hashtable:[]
/// array: [("Key1","value1")]
/// It's ok only then the key is uniquely assosiated with the value
/// To fix it a comparsion of objects stored under the same key in the hashtable and in the arraylist should be added
/// </LAME>>
protected void BaseRemoveAt(int index)
{
if (this.IsReadOnly)
throw new NotSupportedException("Collection is read-only");
string key = BaseGetKey(index);
if (key != null)
{
// TODO: see LAME description above
m_ItemsContainer.Remove(key);
}
else
m_NullKeyItem = null;
m_ItemsArray.RemoveAt(index);
}
/// <summary>
/// SDK: Sets the value of the entry at the specified index of the NameObjectCollectionBase instance.
/// </summary>
/// <param name="index"></param>
/// <param name="value"></param>
protected void BaseSet(int index, object value)
{
if (this.IsReadOnly)
throw new NotSupportedException("Collection is read-only");
_Item item = (_Item)m_ItemsArray[index];
item.value = value;
}
/// <summary>
/// Sets the value of the first entry with the specified key in the NameObjectCollectionBase instance, if found; otherwise, adds an entry with the specified key and value into the NameObjectCollectionBase instance.
/// </summary>
/// <param name="name">The String key of the entry to set. The key can be a null reference </param>
/// <param name="value">The Object that represents the new value of the entry to set. The value can be a null reference</param>
protected void BaseSet(string name, object value)
{
if (this.IsReadOnly)
throw new NotSupportedException("Collection is read-only");
_Item item = FindFirstMatchedItem(name);
if (item != null)
item.value = value;
else
BaseAdd(name, value);
}
private bool HasItem(string name)
{
return FindFirstMatchedItem(name) != m_NullKeyItem;
}
//[MonoTODO]
private _Item FindFirstMatchedItem(string name)
{
if (name != null)
{
object value;
if (m_ItemsContainer.TryGetValue(name, out value))
return (value as _Item) ?? m_NullKeyItem;
return m_NullKeyItem;
}
//TODO: consider null key case
return m_NullKeyItem;
}
internal bool Equals(string s1, string s2)
{
if (m_comparer != null)
return (m_comparer.Compare(s1, s2) == 0);
else
return equality_comparer.Equals(s1, s2);
}
}
[Serializable]
public class NameValueCollection : NameObjectCollectionBase
{
string[] cachedAllKeys = null;
string[] cachedAll = null;
//--------------------- Constructors -----------------------------
public NameValueCollection () : base ()
{
}
public NameValueCollection (int capacity) : base (capacity)
{
}
public NameValueCollection (NameValueCollection col)
: base(col.EqualityComparer)
{
if (col==null)
throw new ArgumentNullException ("col");
Add(col);
}
protected NameValueCollection (SerializationInfo info, StreamingContext context)
:base (info, context)
{
}
public NameValueCollection (IEqualityComparer equalityComparer)
: base (equalityComparer)
{
}
public NameValueCollection (int capacity, IEqualityComparer equalityComparer)
: base (capacity, equalityComparer)
{
}
public virtual string[] AllKeys
{
get {
if (cachedAllKeys == null)
cachedAllKeys = BaseGetAllKeys ();
return this.cachedAllKeys;
}
}
public string this [int index]
{
get{
return this.Get (index);
}
}
public string this [string name] {
get{
return this.Get (name);
}
set{
this.Set (name,value);
}
}
public void Add (NameValueCollection c)
{
if (this.IsReadOnly)
throw new NotSupportedException ("Collection is read-only");
if (c == null)
throw new ArgumentNullException ("c");
// make sense - but it's not the exception thrown
// throw new ArgumentNullException ();
InvalidateCachedArrays ();
int max = c.Count;
for (int i=0; i < max; i++){
string key = c.GetKey (i);
string[] values = c.GetValues (i);
if (values != null && values.Length > 0) {
foreach (string value in values)
Add (key, value);
} else
Add (key, null);
}
}
/// in SDK doc: If the same value already exists under the same key in the collection,
/// it just adds one more value in other words after
/// <code>
/// NameValueCollection nvc;
/// nvc.Add ("LAZY","BASTARD")
/// nvc.Add ("LAZY","BASTARD")
/// </code>
/// nvc.Get ("LAZY") will be "BASTARD,BASTARD" instead of "BASTARD"
public virtual void Add (string name, string value)
{
if (this.IsReadOnly)
throw new NotSupportedException ("Collection is read-only");
InvalidateCachedArrays ();
ArrayList values = (ArrayList)BaseGet (name);
if (values == null){
values = new ArrayList ();
if (value != null)
values.Add (value);
BaseAdd (name, values);
}
else {
if (value != null)
values.Add (value);
}
}
public virtual void Clear ()
{
if (this.IsReadOnly)
throw new NotSupportedException ("Collection is read-only");
InvalidateCachedArrays ();
BaseClear ();
}
public void CopyTo (Array dest, int index)
{
if (dest == null)
throw new ArgumentNullException ("dest", "Null argument - dest");
if (index < 0)
throw new ArgumentOutOfRangeException ("index", "index is less than 0");
if (dest.Rank > 1)
throw new ArgumentException ("dest", "multidim");
if (cachedAll == null)
RefreshCachedAll ();
try {
cachedAll.CopyTo (dest, index);
} catch (ArrayTypeMismatchException) {
throw new InvalidCastException();
}
}
private void RefreshCachedAll ()
{
this.cachedAll = null;
int max = this.Count;
cachedAll = new string [max];
for (int i = 0; i < max; i++)
cachedAll [i] = this.Get (i);
}
public virtual string Get (int index)
{
ArrayList values = (ArrayList)BaseGet (index);
// if index is out of range BaseGet throws an ArgumentOutOfRangeException
return AsSingleString (values);
}
public virtual string Get (string name)
{
ArrayList values = (ArrayList)BaseGet (name);
return AsSingleString (values);
}
private static string AsSingleString (ArrayList values)
{
const char separator = ',';
if (values == null)
return null;
int max = values.Count;
switch (max) {
case 0:
return null;
case 1:
return (string)values [0];
case 2:
return String.Concat ((string)values [0], separator, (string)values [1]);
default:
int len = max;
for (int i = 0; i < max; i++)
len += ((string)values [i]).Length;
StringBuilder sb = new StringBuilder ((string)values [0], len);
for (int i = 1; i < max; i++){
sb.Append (separator);
sb.Append (values [i]);
}
return sb.ToString ();
}
}
public virtual string GetKey (int index)
{
return BaseGetKey (index);
}
public virtual string[] GetValues (int index)
{
ArrayList values = (ArrayList)BaseGet (index);
return AsStringArray (values);
}
public virtual string[] GetValues (string name)
{
ArrayList values = (ArrayList)BaseGet (name);
return AsStringArray (values);
}
private static string[] AsStringArray (ArrayList values)
{
if (values == null)
return null;
int max = values.Count;//get_Count ();
if (max == 0)
return null;
string[] valArray = new string[max];
values.CopyTo (valArray);
return valArray;
}
public bool HasKeys ()
{
return BaseHasKeys ();
}
public virtual void Remove (string name)
{
if (this.IsReadOnly)
throw new NotSupportedException ("Collection is read-only");
InvalidateCachedArrays ();
BaseRemove (name);
}
public virtual void Set (string name, string value)
{
if (this.IsReadOnly)
throw new NotSupportedException ("Collection is read-only");
InvalidateCachedArrays ();
ArrayList values = new ArrayList ();
if (value != null) {
values.Add (value);
BaseSet (name,values);
}
else {
// remove all entries
BaseSet (name, null);
}
}
protected void InvalidateCachedArrays ()
{
cachedAllKeys = null;
cachedAll = null;
}
}
}
//namespace System.Runtime.Serialization
namespace ServiceStack.Pcl
{
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Text;
using ServiceStack;
public sealed class SerializationInfo
{
Dictionary<string, SerializationEntry> serialized = new Dictionary<string, SerializationEntry>();
List<SerializationEntry> values = new List<SerializationEntry>();
string assemblyName; // the assembly being serialized
string fullTypeName; // the type being serialized.
#if NET_4_0
Type objectType;
bool isAssemblyNameSetExplicit;
bool isFullTypeNameSetExplicit;
#endif
IFormatterConverter converter;
/* used by the runtime */
private SerializationInfo(Type type)
{
assemblyName = type.AssemblyQualifiedName;
fullTypeName = type.FullName;
converter = new FormatterConverter();
#if NET_4_0
objectType = type;
#endif
}
/* used by the runtime */
private SerializationInfo(Type type, SerializationEntry[] data)
{
int len = data.Length;
assemblyName = type.AssemblyQualifiedName;
fullTypeName = type.FullName;
converter = new FormatterConverter();
#if NET_4_0
objectType = type;
#endif
for (int i = 0; i < len; i++)
{
serialized.Add(data[i].Name, data[i]);
values.Add(data[i]);
}
}
// Constructor
[CLSCompliant(false)]
public SerializationInfo(Type type, IFormatterConverter converter)
{
if (type == null)
throw new ArgumentNullException("type", "Null argument");
if (converter == null)
throw new ArgumentNullException("converter", "Null argument");
this.converter = converter;
assemblyName = type.AssemblyQualifiedName;
fullTypeName = type.FullName;
#if NET_4_0
objectType = type;