SqlDbType missing value.
[mono.git] / mcs / class / System.Data / System.Data / DataColumnPropertyDescriptor.cs
1 //
2 // System.Data.DataColumnPropertyDescriptor.cs
3 //
4 // Author:
5 //   Daniel Morgan <danmorg@sc.rr.com>
6 //
7 // (c) copyright 2002 Daniel Morgan
8 //
9
10 //
11 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
20 // 
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
23 // 
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 //
32
33 using System;
34 using System.Data.Common;
35 using System.ComponentModel;
36 using System.Reflection;
37
38 namespace System.Data 
39 {
40         internal class DataColumnPropertyDescriptor : PropertyDescriptor 
41         {
42                 private bool readOnly = true;
43                 private Type componentType = null;
44                 private Type propertyType = null;
45                 private bool browsable = true;
46
47                 //private PropertyInfo prop = null;
48                 private int columnIndex = 0;
49
50                 public DataColumnPropertyDescriptor (string name, int columnIndex, Attribute [] attrs)
51                         : base (name, attrs) 
52                 {
53                         this.columnIndex = columnIndex;
54                 }
55
56                 public DataColumnPropertyDescriptor (DataColumn dc)
57                         : base (dc.ColumnName, null) 
58                 {
59                         this.columnIndex = dc.Ordinal;
60                         this.componentType = typeof(DataRowView);
61                         this.propertyType = dc.DataType;
62                         this.readOnly = dc.ReadOnly;
63                 }
64
65                 public void SetReadOnly (bool value) 
66                 {
67                         readOnly = value;
68                 }
69                 
70                 public void SetComponentType (Type type) 
71                 {
72                         componentType = type;
73                 }
74
75                 public void SetPropertyType (Type type) 
76                 {
77                         propertyType = type;
78                 }
79
80                 public void SetBrowsable (bool browsable)
81                 {
82                         this.browsable = browsable;
83                 }
84
85                 public override object GetValue (object component) 
86                 {
87                         // FIXME: what is the correct way to Get a Value?
88                         if(componentType == typeof(DataRowView) && component is DataRowView) {
89                                 DataRowView drv = (DataRowView) component;
90                                 return drv[base.Name];
91                         }
92                         else if(componentType == typeof(DbDataRecord) && component is DbDataRecord) {
93                                 DbDataRecord dr = (DbDataRecord) component;
94                                 return dr[columnIndex];
95                         }
96                         throw new InvalidOperationException();
97
98                         /*
99                         if (prop == null)
100                                 prop = GetPropertyInfo ();              
101                                                         
102                         // FIXME: should I allow multiple parameters?                                                                                   
103                         object[] parms = new object[1];
104                         parms[0] = base.Name;
105                         return prop.GetValue (component, parms);
106                         */
107                 }
108
109                 public override void SetValue(object component, object value) 
110                 {
111                         DataRowView drv = (DataRowView) component;
112                         drv[base.Name] = value;
113                         /*
114                         if (prop == null)
115                                 prop = GetPropertyInfo ();              
116
117                         if (readOnly == true) {
118                                 // FIXME: what really happens if read only?
119                                 throw new Exception("Property is ReadOnly");
120                         }
121                         
122                         // FIXME: should I allow multiple parameters?
123                         object[] parms = new Object[1];
124                         parms[0] = base.Name;
125                         prop.SetValue (component, value, parms);
126                         */
127                 }
128
129                 [MonoTODO]
130                 public override void ResetValue(object component) 
131                 {
132                         // FIXME:
133                 }
134
135                 [MonoTODO]
136                 public override bool CanResetValue(object component) 
137                 {
138                         return false; // FIXEME
139                 }
140
141                 [MonoTODO]
142                 public override bool ShouldSerializeValue(object component) 
143                 {
144                         return false;
145                 }
146
147                 public override Type ComponentType {
148                         get {
149                                 return componentType;
150                         }
151                 }
152
153                 public override bool IsReadOnly {
154                         get {
155                                 return readOnly;        
156                         }
157                 }
158
159                 public override bool IsBrowsable {
160                         get { return browsable && base.IsBrowsable; }
161                 }
162
163                 public override Type PropertyType {
164                         get {
165                                 return propertyType;
166                         }
167                 }
168         }
169 }