2010-04-14 Atsushi Enomoto <atsushi@ximian.com>
authorAtsushi Eno <atsushieno@gmail.com>
Wed, 14 Apr 2010 15:31:16 +0000 (15:31 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Wed, 14 Apr 2010 15:31:16 +0000 (15:31 -0000)
* XamlTypeName.cs : corcompare shows I was missing useful two.

svn path=/trunk/mcs/; revision=155399

mcs/class/System.Xaml/System.Xaml.Schema/ChangeLog
mcs/class/System.Xaml/System.Xaml.Schema/XamlTypeName.cs

index 2050f7ff5783d627e6b3815c1c1610ac542559b7..40b62cee2cf2324e4736bf69852507c3fadedf12 100644 (file)
@@ -1,3 +1,7 @@
+2010-04-14  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * XamlTypeName.cs : corcompare shows I was missing useful two.
+
 2010-04-14  Atsushi Enomoto  <atsushi@ximian.com>
 
        * XamlTypeName.cs : implemented.
index e19a0972fcc6edb6fdb91d53c1e6991c8a6b96e4..137c03eb7d6fa2ca7f42d8f4e43e2fa597b6d6cd 100644 (file)
@@ -28,6 +28,14 @@ namespace System.Xaml.Schema
 {
        public class XamlTypeName
        {
+               public static XamlTypeName Parse (string typeName, IXamlNamespaceResolver namespaceResolver)
+               {
+                       XamlTypeName n;
+                       if (!TryParse (typeName, namespaceResolver, out n))
+                               throw new FormatException (String.Format ("Invalid typeName: '{0}'", typeName));
+                       return n;
+               }
+
                public static bool TryParse (string typeName, IXamlNamespaceResolver namespaceResolver, out XamlTypeName result)
                {
                        if (typeName == null)
@@ -42,11 +50,8 @@ namespace System.Xaml.Schema
                        if (idx >= 0) {
                                if (typeName [typeName.Length - 1] != ')')
                                        return false;
-                               try {
-                                       args = ParseList (typeName.Substring (idx + 1, typeName.Length - idx - 2), namespaceResolver);
-                               } catch (FormatException) {
+                               if (!TryParseList (typeName.Substring (idx + 1, typeName.Length - idx - 2), namespaceResolver, out args))
                                        return false;
-                               }
                                typeName = typeName.Substring (0, idx);
                        }
 
@@ -74,15 +79,24 @@ namespace System.Xaml.Schema
                static readonly char [] commas = {','};
 
                public static IList<XamlTypeName> ParseList (string typeNameList, IXamlNamespaceResolver namespaceResolver)
+               {
+                       IList<XamlTypeName> list;
+                       if (!TryParseList (typeNameList, namespaceResolver, out list))
+                               throw new FormatException (String.Format ("Invalid type name list: '{0}'", typeNameList));
+                       return list;
+               }
+
+               public static bool TryParseList (string typeNameList, IXamlNamespaceResolver namespaceResolver, out IList<XamlTypeName> list)
                {
                        if (typeNameList == null)
                                throw new ArgumentNullException ("typeNameList");
                        if (namespaceResolver == null)
                                throw new ArgumentNullException ("namespaceResolver");
 
+                       list = null;
                        var split = typeNameList.Split (commas);
                        if (split.Length == 0)
-                               throw new FormatException (String.Format ("Invalid type name list: '{0}'", typeNameList));
+                               return false;
 
                        var arr = new XamlTypeName [split.Length];
 
@@ -90,11 +104,12 @@ namespace System.Xaml.Schema
                                var s = split [i].Trim ();
                                XamlTypeName tn;
                                if (!TryParse (s, namespaceResolver, out tn))
-                                       throw new FormatException (String.Format ("Invalid type name list: '{0}'", typeNameList));
+                                       return false;
                                arr [i] = tn;
                        }
 
-                       return arr;
+                       list = arr;
+                       return true;
                }
 
                public static string ToString (IList<XamlTypeName> typeNameList, INamespacePrefixLookup prefixLookup)