#if NET_2_0
using System.ComponentModel;
+#if !NET_2_1
using System.ComponentModel.Design.Serialization;
+#endif
using System.Globalization;
using System.Reflection;
namespace System {
- public class UriTypeConverter : TypeConverter {
+ public
+#if MOONLIGHT
+ sealed
+#endif
+ class UriTypeConverter : TypeConverter {
public UriTypeConverter ()
{
return true;
if (type == typeof (Uri))
return true;
+#if NET_2_1
+ return false;
+#else
return (type == typeof (InstanceDescriptor));
+#endif
}
public override bool CanConvertFrom (ITypeDescriptorContext context, Type sourceType)
if (value == null)
throw new ArgumentNullException ("value");
- if (!CanConvertTo (context, value.GetType ()))
+ if (!CanConvertFrom (context, value.GetType ()))
throw new NotSupportedException (Locale.GetText ("Cannot convert from value."));
if (value is Uri)
string s = (value as string);
if (s != null)
- return new Uri (s);
-
+ return new Uri (s, UriKind.RelativeOrAbsolute);
+#if !NET_2_1
InstanceDescriptor id = (value as InstanceDescriptor);
if (id != null) {
return id.Invoke ();
}
-
+#endif
return base.ConvertFrom (context, culture, value);
}
Uri uri = (value as Uri);
if (uri != null) {
if (destinationType == typeof (string))
- return uri.AbsoluteUri;
+ return uri.ToString ();
if (destinationType == typeof (Uri))
return uri;
+#if !NET_2_1
if (destinationType == typeof (InstanceDescriptor)) {
- ConstructorInfo ci = typeof (Uri).GetConstructor (new Type [1] { typeof (string) });
- return new InstanceDescriptor (ci , new object [] { uri.AbsoluteUri });
+ ConstructorInfo ci = typeof (Uri).GetConstructor (new Type [2] { typeof (string), typeof (UriKind) });
+ return new InstanceDescriptor (ci , new object [] { uri.ToString (), uri.IsAbsoluteUri ? UriKind.Absolute : UriKind.Relative });
}
+#endif
}
return base.ConvertTo (context, culture, value, destinationType);
}
+#if !NET_2_1
public override bool IsValid (ITypeDescriptorContext context, object value)
{
if (value == null)
// from it. However all strings seems to be accepted (see unit tests)
return ((value is string) || (value is Uri));
}
+#endif
}
}