ObjectListItem.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. //
  2. // Permission is hereby granted, free of charge, to any person obtaining
  3. // a copy of this software and associated documentation files (the
  4. // "Software"), to deal in the Software without restriction, including
  5. // without limitation the rights to use, copy, modify, merge, publish,
  6. // distribute, sublicense, and/or sell copies of the Software, and to
  7. // permit persons to whom the Software is furnished to do so, subject to
  8. // the following conditions:
  9. //
  10. // The above copyright notice and this permission notice shall be
  11. // included in all copies or substantial portions of the Software.
  12. //
  13. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  14. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  15. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  16. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  17. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  18. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  19. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20. //
  21. /**
  22. * Project : Mono
  23. * Namespace : System.Web.UI.MobileControls
  24. * Class : ObjectListCommandEventHandler
  25. * Author : Gaurav Vaish
  26. *
  27. * Copyright : 2003 with Gaurav Vaish, and with
  28. * Ximian Inc
  29. */
  30. using System;
  31. using System.Web.Mobile;
  32. namespace System.Web.UI.MobileControls
  33. {
  34. public class ObjectListItem : MobileListItem
  35. {
  36. private ObjectList owner;
  37. private string[] fields;
  38. private bool dirty = false;
  39. internal ObjectListItem(ObjectList owner, object dataItem)
  40. : base(dataItem, null, null)
  41. {
  42. this.owner = owner;
  43. this.fields = new string[owner.AllFields.Count];
  44. }
  45. internal ObjectListItem(ObjectList owner)
  46. : this(owner, null)
  47. {
  48. }
  49. public string this[int key]
  50. {
  51. get
  52. {
  53. if(fields != null && fields.Length >= key - 1
  54. && fields[key] != null)
  55. return fields[key];
  56. return String.Empty;
  57. }
  58. set
  59. {
  60. if(fields != null && fields.Length >= key - 1)
  61. fields[key] = value;
  62. if(IsTrackingViewState)
  63. dirty = true;
  64. }
  65. }
  66. internal bool Dirty
  67. {
  68. get
  69. {
  70. return dirty;
  71. }
  72. set
  73. {
  74. dirty = value;
  75. }
  76. }
  77. public string this[string fieldName]
  78. {
  79. get
  80. {
  81. return this[IndexOf(fieldName)];
  82. }
  83. set
  84. {
  85. this[IndexOf(fieldName)] = value;
  86. }
  87. }
  88. [MonoTODO("Exception_Details_Not_Exact")]
  89. private int IndexOf(string fieldName)
  90. {
  91. int index = owner.AllFields.IndexOf(fieldName);
  92. if(index < 0)
  93. {
  94. throw new ArgumentException("ObjectList_FieldNotFound");
  95. }
  96. return index;
  97. }
  98. public override bool Equals(object obj)
  99. {
  100. bool retVal = false;
  101. if(obj is ObjectListItem)
  102. {
  103. ObjectListItem oli = (ObjectListItem) obj;
  104. if(oli.fields != null && this.fields != null)
  105. {
  106. if(this.fields.Length == oli.fields.Length)
  107. {
  108. int i;
  109. for(i = 0; i < fields.Length; i++)
  110. {
  111. if(fields[i] != oli.fields[i])
  112. break;
  113. }
  114. if(i == fields.Length)
  115. retVal = true;
  116. }
  117. }
  118. retVal &= (Value == oli.Value);
  119. retVal &= (Text == oli.Text);
  120. }
  121. return retVal;
  122. }
  123. public override int GetHashCode()
  124. {
  125. return (fields == null ? Value.GetHashCode() :
  126. fields[0].GetHashCode());
  127. }
  128. }
  129. }