Fix XamlType.Name to take TypeArguments into consideration.
authorAtsushi Eno <atsushi@ximian.com>
Thu, 28 Oct 2010 16:38:52 +0000 (01:38 +0900)
committerAtsushi Eno <atsushi@ximian.com>
Thu, 28 Oct 2010 16:38:52 +0000 (01:38 +0900)
mcs/class/System.Xaml/System.Xaml/TypeExtensionMethods.cs
mcs/class/System.Xaml/System.Xaml/XamlMember.cs
mcs/class/System.Xaml/System.Xaml/XamlType.cs

index 88d8250f33d095951aad38038313a304ae2b4eaf..5375ae072691d145798c3ae33d3ab75a816a1622 100644 (file)
@@ -34,14 +34,6 @@ namespace System.Xaml
 {
        static class TypeExtensionMethods
        {
-               // FIXME: this likely needs to be replaced with XamlTypeName
-               public static string GetXamlName (this Type type)
-               {
-                       if (!type.IsNested)
-                               return type.Name;
-                       return type.DeclaringType.GetXamlName () + "+" + type.Name;
-               }
-
                #region inheritance search and custom attribute provision
 
                public static T GetCustomAttribute<T> (this ICustomAttributeProvider type, bool inherit) where T : Attribute
index 7d8f3fe23f509c9b8266faa7136faa36f0270c3a..45ed220f6819babcb50582ef98f40dd467c5f7d9 100644 (file)
@@ -278,6 +278,7 @@ namespace System.Xaml
                        return ToString ().GetHashCode (); // should in general work.
                }
 
+               [MonoTODO ("there are some patterns that return different kind of value: e.g. List<int>.Capacity")]
                public override string ToString ()
                {
                        if (is_attachable || String.IsNullOrEmpty (PreferredXamlNamespace)) {
index b64ebce595cd0e5a3316e4c1a6a781851a6c026b..154eb98a1ea3a43639b4b7da601e13fadcecb518 100644 (file)
@@ -52,15 +52,20 @@ namespace System.Xaml
 
                        XamlType xt;
                        if (XamlLanguage.InitializingTypes) {
-                               Name = type.GetXamlName ();
+                               Name = GetXamlName (type);
                                PreferredXamlNamespace = XamlLanguage.Xaml2006Namespace;
                        } else if ((xt = XamlLanguage.AllTypes.FirstOrDefault (t => t.UnderlyingType == type)) != null) {
                                Name = xt.Name;
                                PreferredXamlNamespace = XamlLanguage.Xaml2006Namespace;
                        } else {
-                               Name = type.GetXamlName ();
+                               Name = GetXamlName (type);
                                PreferredXamlNamespace = String.Format ("clr-namespace:{0};assembly={1}", type.Namespace, type.Assembly.GetName ().Name);
                        }
+                       if (type.IsGenericType) {
+                               TypeArguments = new List<XamlType> ();
+                               foreach (var gta in type.GetGenericArguments ())
+                                       TypeArguments.Add (schemaContext.GetXamlType (gta));
+                       }
                }
 
                public XamlType (string unknownTypeNamespace, string unknownTypeName, IList<XamlType> typeArguments, XamlSchemaContext schemaContext)
@@ -281,7 +286,8 @@ namespace System.Xaml
 
                public override string ToString ()
                {
-                       return String.IsNullOrEmpty (PreferredXamlNamespace) ? Name : String.Concat ("{", PreferredXamlNamespace, "}", Name);
+                       return new XamlTypeName (this).ToString ();
+                       //return String.IsNullOrEmpty (PreferredXamlNamespace) ? Name : String.Concat ("{", PreferredXamlNamespace, "}", Name);
                }
 
                public virtual bool CanAssignTo (XamlType xamlType)
@@ -762,5 +768,18 @@ namespace System.Xaml
 
                        return null;
                }
+
+               static string GetXamlName (Type type)
+               {
+                       string n;
+                       if (!type.IsNested)
+                               n = type.Name;
+                       else
+                               n = GetXamlName (type.DeclaringType) + "+" + type.Name;
+                       if (type.IsGenericType && !type.ContainsGenericParameters) // the latter condition is to filter out "nested non-generic type within generic type".
+                               return n.Substring (0, n.IndexOf ('`'));
+                       else
+                               return n;
+               }
        }
 }