Remove some illogical hacks in GetSerializerFor().
authorAtsushi Eno <atsushi@ximian.com>
Tue, 16 Nov 2010 17:41:55 +0000 (02:41 +0900)
committerAtsushi Eno <atsushi@ximian.com>
Tue, 16 Nov 2010 17:41:55 +0000 (02:41 +0900)
mcs/class/System.Xaml/System.Windows.Markup/ValueSerializer.cs

index 9130ebce62a0748c37397f16669487f63a5e34e8..d3a001de3d2e6a8b5a7ccdbe8ea9391e1a240eef 100644 (file)
@@ -24,6 +24,7 @@ using System;
 using System.Collections;
 using System.Collections.Generic;
 using System.ComponentModel;
+using System.Linq;
 using System.Reflection;
 using System.Xaml;
 
@@ -47,19 +48,21 @@ namespace System.Windows.Markup
                        throw new NotImplementedException ();
                }
 
-               [MonoTODO ("IValueSerializerContext parameter is not supported")]
                public static ValueSerializer GetSerializerFor (Type type, IValueSerializerContext context)
                {
                        if (type == null)
                                throw new ArgumentNullException ("type");
+                       // weird, but .NET also throws NIE(!)
+                       if (context != null)
+                               throw new NotImplementedException ();
 
-                       // FIXME: it is likely a hack.
-                       if (Type.GetTypeCode (type) != TypeCode.Object)
+                       // MarkupExtension is serialized without ValueSerializer.
+                       if (typeof (MarkupExtension).IsAssignableFrom (type))
+                               return null;
+
+                       var tc = TypeDescriptor.GetConverter (type);
+                       if (tc != null && tc.GetType () != typeof (TypeConverter))
                                return new TypeConverterValueSerializer (type);
-                       if (type == typeof (TimeSpan))
-                               return new TypeConverterValueSerializer (typeof (TimeSpan));
-                       if (type == typeof (Uri))
-                               return new TypeConverterValueSerializer (typeof (Uri));
                        return null;
                }