BaseParamsCollection.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. //
  2. // System.Web.BaseParamsCollection
  3. //
  4. // Authors:
  5. // Vladimir Krasnov ([email protected])
  6. //
  7. // (C) 2006 Mainsoft Co. (http://www.mainsoft.com)
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. using System;
  29. using System.Collections.Specialized;
  30. using System.Runtime.Serialization;
  31. namespace System.Web
  32. {
  33. abstract class BaseParamsCollection : WebROCollection
  34. {
  35. protected HttpRequest _request;
  36. protected bool _loaded = false;
  37. public BaseParamsCollection (HttpRequest request)
  38. {
  39. _request = request;
  40. IsReadOnly = true;
  41. }
  42. void LoadInfo ()
  43. {
  44. if (_loaded)
  45. return;
  46. IsReadOnly = false;
  47. InsertInfo ();
  48. IsReadOnly = true;
  49. _loaded = true;
  50. }
  51. protected abstract void InsertInfo ();
  52. public override string Get (int index)
  53. {
  54. LoadInfo ();
  55. return base.Get (index);
  56. }
  57. protected abstract string InternalGet (string name);
  58. public override string Get (string name)
  59. {
  60. if (!_loaded) {
  61. #if TARGET_JVM
  62. return InternalGet (name);
  63. #else
  64. string s = InternalGet (name);
  65. if (s != null && s.Length > 0)
  66. return s;
  67. LoadInfo ();
  68. #endif
  69. }
  70. return base.Get (name);
  71. }
  72. public override string GetKey (int index)
  73. {
  74. LoadInfo ();
  75. return base.GetKey (index);
  76. }
  77. public override string[] GetValues (int index)
  78. {
  79. string text1;
  80. string[] array1;
  81. text1 = Get (index);
  82. if (text1 == null)
  83. return null;
  84. array1 = new string[1];
  85. array1[0] = text1;
  86. return array1;
  87. }
  88. public override string[] GetValues (string name)
  89. {
  90. string text1;
  91. string[] array1;
  92. text1 = Get (name);
  93. if (text1 == null)
  94. return null;
  95. array1 = new string[1];
  96. array1[0] = text1;
  97. return array1;
  98. }
  99. public override void GetObjectData (SerializationInfo info, StreamingContext context)
  100. {
  101. throw new SerializationException ();
  102. }
  103. public override string[] AllKeys
  104. {
  105. get {
  106. LoadInfo ();
  107. return base.AllKeys;
  108. }
  109. }
  110. public override int Count
  111. {
  112. get {
  113. LoadInfo ();
  114. return base.Count;
  115. }
  116. }
  117. public override NameObjectCollectionBase.KeysCollection Keys {
  118. get {
  119. LoadInfo ();
  120. return base.Keys;
  121. }
  122. }
  123. public override System.Collections.IEnumerator GetEnumerator () {
  124. LoadInfo ();
  125. return base.GetEnumerator ();
  126. }
  127. }
  128. }