ObjectListItem.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /**
  2. * Project : Mono
  3. * Namespace : System.Web.UI.MobileControls
  4. * Class : ObjectListCommandEventHandler
  5. * Author : Gaurav Vaish
  6. *
  7. * Copyright : 2003 with Gaurav Vaish, and with
  8. * Ximian Inc
  9. */
  10. using System;
  11. using System.Web.Mobile;
  12. namespace System.Web.UI.MobileControls
  13. {
  14. public class ObjectListItem : MobileListItem
  15. {
  16. private ObjectList owner;
  17. private string[] fields;
  18. private bool dirty = false;
  19. internal ObjectListItem(ObjectList owner, object dataItem)
  20. : base(dataItem, null, null)
  21. {
  22. this.owner = owner;
  23. this.fields = new string[owner.AllFields.Count];
  24. }
  25. internal ObjectListItem(ObjectList owner)
  26. : this(owner, null)
  27. {
  28. }
  29. public string this[int key]
  30. {
  31. get
  32. {
  33. if(fields != null && fields.Length >= key - 1
  34. && fields[key] != null)
  35. return fields[key];
  36. return String.Empty;
  37. }
  38. set
  39. {
  40. if(fields != null && fields.Length >= key - 1)
  41. fields[key] = value;
  42. if(IsTrackingViewState)
  43. dirty = true;
  44. }
  45. }
  46. internal bool Dirty
  47. {
  48. get
  49. {
  50. return dirty;
  51. }
  52. set
  53. {
  54. dirty = value;
  55. }
  56. }
  57. public string this[string fieldName]
  58. {
  59. get
  60. {
  61. return this[IndexOf(fieldName)];
  62. }
  63. set
  64. {
  65. this[IndexOf(fieldName)] = value;
  66. }
  67. }
  68. [MonoTODO("Exception_Details_Not_Exact")]
  69. private int IndexOf(string fieldName)
  70. {
  71. int index = owner.AllFields.IndexOf(fieldName);
  72. if(index < 0)
  73. {
  74. throw new ArgumentException("ObjectList_FieldNotFound");
  75. }
  76. return index;
  77. }
  78. public override bool Equals(object obj)
  79. {
  80. bool retVal = false;
  81. if(obj is ObjectListItem)
  82. {
  83. ObjectListItem oli = (ObjectListItem) obj;
  84. if(oli.fields != null && this.fields != null)
  85. {
  86. if(this.fields.Length == oli.fields.Length)
  87. {
  88. int i;
  89. for(i = 0; i < fields.Length; i++)
  90. {
  91. if(fields[i] != oli.fields[i])
  92. break;
  93. }
  94. if(i == fields.Length)
  95. retVal = true;
  96. }
  97. }
  98. retVal &= (Value == oli.Value);
  99. retVal &= (Text == oli.Text);
  100. }
  101. return retVal;
  102. }
  103. public override int GetHashCode()
  104. {
  105. return (fields == null ? Value.GetHashCode() :
  106. fields[0].GetHashCode());
  107. }
  108. }
  109. }