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)
30 public void SetReadOnly (bool value)
35 public void SetComponentType (Type type)
40 public void SetPropertyType (Type type)
45 private PropertyInfo GetPropertyInfo ()
47 string defaultMemberName = "";
48 object[] attribs = componentType.GetCustomAttributes (true);
\r
50 for (int at = 0; at < attribs.Length; at++) {
\r
51 if (attribs[at] is DefaultMemberAttribute) {
\r
52 defaultMemberName = ((DefaultMemberAttribute) attribs[at]).MemberName;
\r
57 // FIXME: what do I do if a DefaultMemeberAttribute is not found?
\r
58 // should I try looking for DefaultPropertyAttribute?
\r
59 if (defaultMemberName.Equals(""))
\r
60 throw new Exception("Default property not found.");
\r
62 Type[] parmTypes = new Type[1];
\r
63 parmTypes[0] = propertyType;
\r
64 PropertyInfo propertyInfo = componentType.GetProperty (defaultMemberName, parmTypes);
68 public override object GetValue (object component)
70 // FIXME: what is the correct way to Get a Value?
71 if(componentType == typeof(DataRowView) && component is DataRowView) {
72 DataRowView drv = (DataRowView) component;
73 return drv[base.Name];
75 else if(component == typeof(DbDataRecord) && component is DbDataRecord) {
76 DbDataRecord dr = (DbDataRecord) component;
77 return dr[columnIndex];
79 throw new InvalidOperationException();
83 prop = GetPropertyInfo ();
85 // FIXME: should I allow multiple parameters?
\r
86 object[] parms = new object[1];
\r
87 parms[0] = base.Name;
\r
88 return prop.GetValue (component, parms);
92 public override void SetValue(object component, object value)
94 DataRowView drv = (DataRowView) component;
95 drv[base.Name] = value;
98 prop = GetPropertyInfo ();
100 if (readOnly == true) {
101 // FIXME: what really happens if read only?
102 throw new Exception("Property is ReadOnly");
105 // FIXME: should I allow multiple parameters?
\r
106 object[] parms = new Object[1];
\r
107 parms[0] = base.Name;
\r
108 prop.SetValue (component, value, parms);
113 public override void ResetValue(object component)
119 public override bool CanResetValue(object component)
121 return false; // FIXEME
125 public override bool ShouldSerializeValue(object component)
130 public override Type ComponentType {
132 return componentType;
136 public override bool IsReadOnly {
142 public override Type PropertyType {