DbDataRecord.cs 5.8 KB

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