1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2006 Novell, Inc. (http://www.novell.com)
23 // Peter Dennis Bartok (pbartok@novell.com)
24 // Ivan N. Zlatev (contact i-nz.net)
29 using System
.ComponentModel
;
30 using System
.Windows
.Forms
;
32 namespace System
.Windows
.Forms
.Design
34 internal class ControlBindingsConverter
: TypeConverter
36 public ControlBindingsConverter()
40 // TODO: Should create some sort of a special PropertyDescriptor and handle the data binding
43 public override PropertyDescriptorCollection
GetProperties (ITypeDescriptorContext context
,
44 object value, Attribute
[] attributes
)
46 PropertyDescriptorCollection properties
= new PropertyDescriptorCollection (new PropertyDescriptor
[0]);
47 ControlBindingsCollection collection
= value as ControlBindingsCollection
;
49 object bindableComponent
= collection
.BindableComponent
;
51 object bindableComponent
= collection
.Control
;
53 if (collection
!= null && bindableComponent
!= null) {
54 foreach (PropertyDescriptor property
in
55 TypeDescriptor
.GetProperties (bindableComponent
, attributes
)) {
56 if (((BindableAttribute
) property
.Attributes
[typeof (BindableAttribute
)]).Bindable
)
57 properties
.Add (new DataBindingPropertyDescriptor (property
, attributes
, true));
63 public override bool GetPropertiesSupported (ITypeDescriptorContext context
)
68 public override bool CanConvertTo (ITypeDescriptorContext context
, Type destinationType
)
70 if (destinationType
== typeof (string))
72 return base.CanConvertTo (context
, destinationType
);
75 public override object ConvertTo (ITypeDescriptorContext context
, System
.Globalization
.CultureInfo culture
,
76 object value, Type destinationType
)
78 if (destinationType
== typeof (string))
80 return base.ConvertTo (context
, culture
, value, destinationType
);
85 private class DataBindingPropertyDescriptor
: PropertyDescriptor
90 public DataBindingPropertyDescriptor (PropertyDescriptor property
, Attribute
[] attrs
, bool readOnly
)
91 : base (property
.Name
, attrs
)
97 public override object GetValue (object component
)
99 // throw new NotImplementedException ();
104 public override void SetValue (object component
, object value)
106 // throw new NotImplementedException ();
110 public override void ResetValue (object component
)
112 throw new NotImplementedException ();
116 public override bool CanResetValue (object component
)
118 // throw new NotImplementedException ();
122 public override bool ShouldSerializeValue (object component
)
128 public override Type PropertyType
{
130 // throw new NotImplementedException ();
131 return typeof (DataBindingPropertyDescriptor
);
136 public override TypeConverter Converter
{
138 // throw new NotImplementedException ();
143 public override Type ComponentType
{
144 get { return typeof (ControlBindingsCollection); }
147 public override bool IsReadOnly
{
148 get { return _readOnly; }