DbDataRecord.cs 5.0 KB

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