2 // System.Data.DataColumnPropertyDescriptor.cs
5 // Daniel Morgan <danmorg@sc.rr.com>
7 // (c) copyright 2002 Daniel Morgan
11 using System.Data.Common;
12 using System.ComponentModel;
13 using System.Reflection;
17 public class DataColumnPropertyDescriptor : PropertyDescriptor
19 private bool readOnly = true;
20 private Type componentType = null;
21 private Type propertyType = null;
22 private PropertyInfo prop = null;
23 private int columnIndex = 0;
25 public DataColumnPropertyDescriptor (string name, int columnIndex, Attribute [] attrs)
28 this.columnIndex = columnIndex;
31 public void SetReadOnly (bool value)
36 public void SetComponentType (Type type)
41 public void SetPropertyType (Type type)
46 private PropertyInfo GetPropertyInfo ()
48 string defaultMemberName = "";
49 object[] attribs = componentType.GetCustomAttributes (true);
\r
51 for (int at = 0; at < attribs.Length; at++) {
\r
52 if (attribs[at] is DefaultMemberAttribute) {
\r
53 defaultMemberName = ((DefaultMemberAttribute) attribs[at]).MemberName;
\r
58 // FIXME: what do I do if a DefaultMemeberAttribute is not found?
\r
59 // should I try looking for DefaultPropertyAttribute?
\r
60 if (defaultMemberName.Equals(""))
\r
61 throw new Exception("Default property not found.");
\r
63 Type[] parmTypes = new Type[1];
\r
64 parmTypes[0] = propertyType;
\r
65 PropertyInfo propertyInfo = componentType.GetProperty (defaultMemberName, parmTypes);
69 public override object GetValue (object component)
71 // FIXME: what is the correct way to Get a Value?
72 if(componentType == typeof(DataRowView) && component is DataRowView) {
73 DataRowView drv = (DataRowView) component;
74 return drv[base.Name];
76 else if(componentType == typeof(DbDataRecord) && component is DbDataRecord) {
77 DbDataRecord dr = (DbDataRecord) component;
78 return dr[columnIndex];
80 throw new InvalidOperationException();
84 prop = GetPropertyInfo ();
86 // FIXME: should I allow multiple parameters?
\r
87 object[] parms = new object[1];
\r
88 parms[0] = base.Name;
\r
89 return prop.GetValue (component, parms);
93 public override void SetValue(object component, object value)
95 DataRowView drv = (DataRowView) component;
96 drv[base.Name] = value;
99 prop = GetPropertyInfo ();
101 if (readOnly == true) {
102 // FIXME: what really happens if read only?
103 throw new Exception("Property is ReadOnly");
106 // FIXME: should I allow multiple parameters?
\r
107 object[] parms = new Object[1];
\r
108 parms[0] = base.Name;
\r
109 prop.SetValue (component, value, parms);
114 public override void ResetValue(object component)
120 public override bool CanResetValue(object component)
122 return false; // FIXEME
126 public override bool ShouldSerializeValue(object component)
131 public override Type ComponentType {
133 return componentType;
137 public override bool IsReadOnly {
143 public override Type PropertyType {