DbDataRecord.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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. if(values == null)
  133. throw new ArgumentNullException("values");
  134. int count = values.Length > this.values.Length ? this.values.Length : values.Length;
  135. for(int i = 0; i < count; i++)
  136. values[i] = this.values[i];
  137. return count;
  138. }
  139. [MonoTODO]
  140. AttributeCollection ICustomTypeDescriptor.GetAttributes ()
  141. {
  142. return new AttributeCollection(null);
  143. }
  144. [MonoTODO]
  145. string ICustomTypeDescriptor.GetClassName ()
  146. {
  147. return "";
  148. }
  149. [MonoTODO]
  150. string ICustomTypeDescriptor.GetComponentName ()
  151. {
  152. return null;
  153. }
  154. [MonoTODO]
  155. TypeConverter ICustomTypeDescriptor.GetConverter ()
  156. {
  157. return null;
  158. }
  159. [MonoTODO]
  160. EventDescriptor ICustomTypeDescriptor.GetDefaultEvent ()
  161. {
  162. return null;
  163. }
  164. [MonoTODO]
  165. PropertyDescriptor ICustomTypeDescriptor.GetDefaultProperty ()
  166. {
  167. return null;
  168. }
  169. [MonoTODO]
  170. object ICustomTypeDescriptor.GetEditor (Type editorBaseType)
  171. {
  172. return null;
  173. }
  174. [MonoTODO]
  175. EventDescriptorCollection ICustomTypeDescriptor.GetEvents ()
  176. {
  177. return new EventDescriptorCollection(null);
  178. }
  179. [MonoTODO]
  180. EventDescriptorCollection ICustomTypeDescriptor.GetEvents (Attribute[] attributes)
  181. {
  182. return new EventDescriptorCollection(null);
  183. }
  184. [MonoTODO]
  185. PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties ()
  186. {
  187. DataColumnPropertyDescriptor[] descriptors =
  188. new DataColumnPropertyDescriptor[FieldCount];
  189. DataColumnPropertyDescriptor descriptor;
  190. DataColumn dataColumn;
  191. for(int col = 0; col < FieldCount; col++) {
  192. descriptor = new DataColumnPropertyDescriptor(
  193. GetName(col), col, null);
  194. descriptor.SetComponentType(typeof(DbDataRecord));
  195. descriptor.SetPropertyType(GetFieldType(col));
  196. descriptors[col] = descriptor;
  197. }
  198. return new PropertyDescriptorCollection (descriptors);
  199. }
  200. [MonoTODO]
  201. PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties (Attribute[] attributes)
  202. {
  203. PropertyDescriptorCollection descriptors;
  204. descriptors = ((ICustomTypeDescriptor) this).GetProperties ();
  205. // TODO: filter out descriptors which do not contain
  206. // any of those attributes
  207. // except, those descriptors
  208. // that contain DefaultMemeberAttribute
  209. return descriptors;
  210. }
  211. [MonoTODO]
  212. object ICustomTypeDescriptor.GetPropertyOwner (PropertyDescriptor pd)
  213. {
  214. return this;
  215. }
  216. public bool IsDBNull (int i)
  217. {
  218. return GetValue (i) == null;
  219. }
  220. #endregion // Methods
  221. }
  222. }