// (C) 2003 Andreas Nahr
//
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
using System;
using System.Collections;
+using System.ComponentModel.Design.Serialization;
using System.Globalization;
using System.Runtime.InteropServices;
public virtual bool CanConvertFrom (ITypeDescriptorContext context, Type sourceType)
{
+ if (sourceType == typeof (InstanceDescriptor)) {
+ return true;
+ }
+
return false;
}
public virtual object ConvertFrom (ITypeDescriptorContext context, CultureInfo culture, object value)
{
- throw new NotSupportedException (this.ToString() + " cannot be created from '" +
- value.GetType().ToString() + "'");
+ if (value is InstanceDescriptor) {
+ return ((InstanceDescriptor) value).Invoke ();
+ }
+
+ return GetConvertFromException (value);
}
public object ConvertFromInvariantString (string text)
return String.Empty;
}
- throw new NotSupportedException ("Conversion not supported");
+ return GetConvertToException (value, destinationType);
}
public string ConvertToInvariantString (object value)
protected Exception GetConvertFromException (object value)
{
- throw new NotSupportedException (this.ToString() + " cannot convert from '" +
- value.GetType().ToString() + "'");
+ string destinationType;
+ if (value == null)
+ destinationType = "(null)";
+ else
+ destinationType = value.GetType ().FullName;
+
+ throw new NotSupportedException (string.Format (CultureInfo.InvariantCulture,
+ "{0} cannot convert from {1}.", this.GetType ().Name,
+ destinationType));
}
protected Exception GetConvertToException (object value, Type destinationType)
{
- throw new NotSupportedException (this.ToString() + " cannot convert from '" +
- value.GetType().ToString() + "' to '" + destinationType.ToString() + "'");
+ string sourceType;
+ if (value == null)
+ sourceType = "(null)";
+ else
+ sourceType = value.GetType ().FullName;
+
+ throw new NotSupportedException (string.Format (CultureInfo.InvariantCulture,
+ "'{0}' is unable to convert '{1}' to '{2}'.", this.GetType ().Name,
+ sourceType, destinationType.FullName));
}
public object CreateInstance (IDictionary propertyValues)
public PropertyDescriptorCollection GetProperties (ITypeDescriptorContext context, object value)
{
- return GetProperties (context, value, null);
+ return GetProperties (context, value, new Attribute[1] { BrowsableAttribute.Yes });
}
public virtual PropertyDescriptorCollection GetProperties (ITypeDescriptorContext context,
this.values = values;
}
+ void ICollection.CopyTo (Array array, int index) {
+ CopyTo (array, index);
+ }
+
public void CopyTo (Array array, int index)
{
values.CopyTo (array, index);
}
+ IEnumerator IEnumerable.GetEnumerator () {
+ return GetEnumerator ();
+ }
+
public IEnumerator GetEnumerator ()
{
return values.GetEnumerator ();
public SimplePropertyDescriptor (Type componentType,
string name,
Type propertyType) :
- this (componentType, name, propertyType, new Attribute [0])
+ this (componentType, name, propertyType, null)
{
}