2
0

DataKeyArray.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. //
  2. // System.Web.UI.WebControls.DataKey.cs
  3. //
  4. // Authors:
  5. // Lluis Sanchez Gual ([email protected])
  6. //
  7. // (C) 2005-2010 Novell, Inc (http://www.novell.com)
  8. //
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. using System;
  30. using System.Collections;
  31. using System.Web;
  32. using System.Web.UI;
  33. namespace System.Web.UI.WebControls
  34. {
  35. public sealed class DataKeyArray : ICollection, IEnumerable, IStateManager
  36. {
  37. IList keys;
  38. bool trackViewState;
  39. internal DataKeyArray (IList keys)
  40. {
  41. this.keys = keys;
  42. }
  43. public DataKeyArray (ArrayList keys)
  44. {
  45. this.keys = keys;
  46. }
  47. public int Count {
  48. get { return keys.Count; }
  49. }
  50. public bool IsReadOnly {
  51. get { return false; }
  52. }
  53. public bool IsSynchronized {
  54. get { return false; }
  55. }
  56. public DataKey this [int index] {
  57. get { return (DataKey) keys [index]; }
  58. }
  59. public object SyncRoot {
  60. get { return this; }
  61. }
  62. public void CopyTo (DataKey[] array, int index)
  63. {
  64. foreach (DataKey current in this)
  65. array [index++] = current;
  66. }
  67. void ICollection.CopyTo(Array array, int index)
  68. {
  69. foreach(object current in this)
  70. array.SetValue(current, index++);
  71. }
  72. public IEnumerator GetEnumerator()
  73. {
  74. return keys.GetEnumerator();
  75. }
  76. void IStateManager.LoadViewState (object savedState)
  77. {
  78. if (savedState == null) return;
  79. object[] data = (object[]) savedState;
  80. for (int n=0; n<data.Length && n<keys.Count; n++)
  81. ((IStateManager)keys[n]).LoadViewState (data [n]);
  82. }
  83. object IStateManager.SaveViewState ()
  84. {
  85. if (keys.Count == 0) return null;
  86. object[] data = new object [keys.Count];
  87. for (int n=0; n<keys.Count; n++)
  88. data [n] = ((IStateManager)keys[n]).SaveViewState ();
  89. return data;
  90. }
  91. void IStateManager.TrackViewState ()
  92. {
  93. trackViewState = true;
  94. foreach (IStateManager k in keys)
  95. k.TrackViewState ();
  96. }
  97. bool IStateManager.IsTrackingViewState {
  98. get { return trackViewState; }
  99. }
  100. }
  101. }