2 // System.Data.DataColumnPropertyDescriptor.cs
5 // Daniel Morgan <danmorg@sc.rr.com>
7 // (c) copyright 2002 Daniel Morgan
11 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
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:
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
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.
34 using System.Data.Common;
35 using System.ComponentModel;
36 using System.Reflection;
40 internal class DataColumnPropertyDescriptor : PropertyDescriptor
42 private bool readOnly = true;
43 private Type componentType = null;
44 private Type propertyType = null;
45 //private PropertyInfo prop = null;
46 private int columnIndex = 0;
48 public DataColumnPropertyDescriptor (string name, int columnIndex, Attribute [] attrs)
51 this.columnIndex = columnIndex;
54 public DataColumnPropertyDescriptor (DataColumn dc)
55 : base (dc.ColumnName, null)
57 this.columnIndex = dc.Ordinal;
58 this.componentType = typeof(DataRowView);
59 this.propertyType = dc.DataType;
60 this.readOnly = dc.ReadOnly;
63 public void SetReadOnly (bool value)
68 public void SetComponentType (Type type)
73 public void SetPropertyType (Type type)
78 public override object GetValue (object component)
80 // FIXME: what is the correct way to Get a Value?
81 if(componentType == typeof(DataRowView) && component is DataRowView) {
82 DataRowView drv = (DataRowView) component;
83 return drv[base.Name];
85 else if(componentType == typeof(DbDataRecord) && component is DbDataRecord) {
86 DbDataRecord dr = (DbDataRecord) component;
87 return dr[columnIndex];
89 throw new InvalidOperationException();
93 prop = GetPropertyInfo ();
95 // FIXME: should I allow multiple parameters?
96 object[] parms = new object[1];
98 return prop.GetValue (component, parms);
102 public override void SetValue(object component, object value)
104 DataRowView drv = (DataRowView) component;
105 drv[base.Name] = value;
108 prop = GetPropertyInfo ();
110 if (readOnly == true) {
111 // FIXME: what really happens if read only?
112 throw new Exception("Property is ReadOnly");
115 // FIXME: should I allow multiple parameters?
116 object[] parms = new Object[1];
117 parms[0] = base.Name;
118 prop.SetValue (component, value, parms);
123 public override void ResetValue(object component)
129 public override bool CanResetValue(object component)
131 return false; // FIXEME
135 public override bool ShouldSerializeValue(object component)
140 public override Type ComponentType {
142 return componentType;
146 public override bool IsReadOnly {
152 public override Type PropertyType {