DbDataRecord.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. //
  2. // System.Data.Common.DbDataRecord.cs
  3. //
  4. // Author:
  5. // Tim Coleman ([email protected])
  6. //
  7. // Copyright (C) Tim Coleman, 2002
  8. //
  9. using System.Collections;
  10. using System.ComponentModel;
  11. using System.Data;
  12. namespace System.Data.Common {
  13. public class DbDataRecord : IDataRecord, ICustomTypeDescriptor
  14. {
  15. #region Fields
  16. SchemaInfo[] schema;
  17. object[] values;
  18. int fieldCount;
  19. FieldNameLookup lookup;
  20. #endregion
  21. #region Constructors
  22. internal DbDataRecord (SchemaInfo[] schema, object[] values, FieldNameLookup lookup)
  23. {
  24. this.schema = schema;
  25. this.lookup = lookup;
  26. this.values = values;
  27. this.fieldCount = values.Length;
  28. }
  29. #endregion
  30. #region Properties
  31. public int FieldCount {
  32. get { return fieldCount; }
  33. }
  34. public object this [string name] {
  35. get { return this [GetOrdinal (name)]; }
  36. }
  37. [System.Runtime.CompilerServices.IndexerName("Item")]
  38. public object this [int index] {
  39. get { return GetValue (index); }
  40. }
  41. #endregion
  42. #region Methods
  43. public bool GetBoolean (int i)
  44. {
  45. return (bool) GetValue (i);
  46. }
  47. public byte GetByte (int i)
  48. {
  49. return (byte) GetValue (i);
  50. }
  51. [MonoTODO]
  52. public long GetBytes (int i, long dataIndex, byte[] buffer, int bufferIndex, int length)
  53. {
  54. throw new NotImplementedException ();
  55. }
  56. public char GetChar (int i)
  57. {
  58. return (char) GetValue (i);
  59. }
  60. [MonoTODO]
  61. public long GetChars (int i, long dataIndex, char[] buffer, int bufferIndex, int length)
  62. {
  63. throw new NotImplementedException ();
  64. }
  65. [MonoTODO]
  66. public IDataReader GetData (int i)
  67. {
  68. throw new NotImplementedException ();
  69. }
  70. public string GetDataTypeName (int i)
  71. {
  72. return schema[i].DataTypeName;
  73. }
  74. public DateTime GetDateTime (int i)
  75. {
  76. return (DateTime) GetValue (i);
  77. }
  78. public decimal GetDecimal (int i)
  79. {
  80. return (decimal) GetValue (i);
  81. }
  82. public double GetDouble (int i)
  83. {
  84. return (double) GetValue (i);
  85. }
  86. public Type GetFieldType (int i)
  87. {
  88. return schema[i].FieldType;
  89. }
  90. public float GetFloat (int i)
  91. {
  92. return (float) GetValue (i);
  93. }
  94. public Guid GetGuid (int i)
  95. {
  96. return (Guid) GetValue (i);
  97. }
  98. public short GetInt16 (int i)
  99. {
  100. return (short) GetValue (i);
  101. }
  102. public int GetInt32 (int i)
  103. {
  104. return (int) GetValue (i);
  105. }
  106. public long GetInt64 (int i)
  107. {
  108. return (long) GetValue (i);
  109. }
  110. public string GetName (int i)
  111. {
  112. return (string) lookup [i];
  113. }
  114. public int GetOrdinal (string name)
  115. {
  116. return lookup.IndexOf (name);
  117. }
  118. public string GetString (int i)
  119. {
  120. return (string) GetValue (i);
  121. }
  122. public object GetValue (int i)
  123. {
  124. object value = values [i];
  125. if (value == null)
  126. value = DBNull.Value;
  127. return value;
  128. }
  129. [MonoTODO]
  130. public int GetValues (object[] values)
  131. {
  132. object[] newArray = new object[this.values.Length];
  133. values.CopyTo (newArray, 0);
  134. return values.Length;
  135. }
  136. [MonoTODO]
  137. AttributeCollection ICustomTypeDescriptor.GetAttributes ()
  138. {
  139. return new AttributeCollection(null);
  140. }
  141. [MonoTODO]
  142. string ICustomTypeDescriptor.GetClassName ()
  143. {
  144. return "";
  145. }
  146. [MonoTODO]
  147. string ICustomTypeDescriptor.GetComponentName ()
  148. {
  149. return null;
  150. }
  151. [MonoTODO]
  152. TypeConverter ICustomTypeDescriptor.GetConverter ()
  153. {
  154. return null;
  155. }
  156. [MonoTODO]
  157. EventDescriptor ICustomTypeDescriptor.GetDefaultEvent ()
  158. {
  159. return null;
  160. }
  161. [MonoTODO]
  162. PropertyDescriptor ICustomTypeDescriptor.GetDefaultProperty ()
  163. {
  164. return null;
  165. }
  166. [MonoTODO]
  167. object ICustomTypeDescriptor.GetEditor (Type editorBaseType)
  168. {
  169. return null;
  170. }
  171. [MonoTODO]
  172. EventDescriptorCollection ICustomTypeDescriptor.GetEvents ()
  173. {
  174. return new EventDescriptorCollection(null);
  175. }
  176. [MonoTODO]
  177. EventDescriptorCollection ICustomTypeDescriptor.GetEvents (Attribute[] attributes)
  178. {
  179. return new EventDescriptorCollection(null);
  180. }
  181. [MonoTODO]
  182. PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties ()
  183. {
  184. DataColumnPropertyDescriptor[] descriptors =
  185. new DataColumnPropertyDescriptor[FieldCount];
  186. DataColumnPropertyDescriptor descriptor;
  187. DataColumn dataColumn;
  188. for(int col = 0; col < FieldCount; col++) {
  189. descriptor = new DataColumnPropertyDescriptor(
  190. GetName(col), col, null);
  191. descriptor.SetComponentType(typeof(DbDataRecord));
  192. descriptor.SetPropertyType(GetFieldType(col));
  193. descriptors[col] = descriptor;
  194. }
  195. return new PropertyDescriptorCollection (descriptors);
  196. }
  197. [MonoTODO]
  198. PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties (Attribute[] attributes)
  199. {
  200. PropertyDescriptorCollection descriptors;
  201. descriptors = ((ICustomTypeDescriptor) this).GetProperties ();
  202. // TODO: filter out descriptors which do not contain
  203. // any of those attributes
  204. // except, those descriptors
  205. // that contain DefaultMemeberAttribute
  206. return descriptors;
  207. }
  208. [MonoTODO]
  209. object ICustomTypeDescriptor.GetPropertyOwner (PropertyDescriptor pd)
  210. {
  211. return this;
  212. }
  213. public bool IsDBNull (int i)
  214. {
  215. return GetValue (i) == null;
  216. }
  217. #endregion // Methods
  218. }
  219. }