New test.
[mono.git] / mcs / class / System / System / UriTypeConverter.cs
index daf781df4987eaa6e26d7a56c70f99560e1b0325..ea066b4f1d45146bf74420126d7179f95dae4ca2 100644 (file)
 #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 ()
                {
@@ -48,7 +54,11 @@ namespace System {
                                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)
@@ -72,7 +82,7 @@ namespace System {
                        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)
@@ -80,13 +90,13 @@ namespace System {
 
                        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);
                }
 
@@ -98,18 +108,21 @@ namespace System {
                        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)
@@ -119,6 +132,7 @@ namespace System {
                        // from it. However all strings seems to be accepted (see unit tests)
                        return ((value is string) || (value is Uri));
                }
+#endif
        }
 }