2010-04-20 Atsushi Enomoto <atsushi@ximian.com>
authorAtsushi Eno <atsushieno@gmail.com>
Tue, 20 Apr 2010 11:38:32 +0000 (11:38 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Tue, 20 Apr 2010 11:38:32 +0000 (11:38 -0000)
* XamlType.cs : implement LookupPositionalParameters().

* XamlTypeTest.cs : added tests for GetPositionalParameters().

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

mcs/class/System.Xaml/System.Xaml/ChangeLog
mcs/class/System.Xaml/System.Xaml/XamlType.cs
mcs/class/System.Xaml/Test/System.Xaml/ChangeLog
mcs/class/System.Xaml/Test/System.Xaml/XamlTypeTest.cs

index 699d54aa61dd2671e9fb01ef1cf156b8f1310400..27ed0d9e6a5d527a3b0c259634f4aae4f4678214 100644 (file)
@@ -1,3 +1,7 @@
+2010-04-20  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * XamlType.cs : implement LookupPositionalParameters().
+
 2010-04-20  Atsushi Enomoto  <atsushi@ximian.com>
 
        * XamlObjectReader.cs : use Type, not TargetType.
index 4b70d18466df1559b6465b13d3f351db04957630..3625d6137f96f551e9d49a9a27b4a1484ba2c499 100644 (file)
@@ -590,7 +590,27 @@ namespace System.Xaml
 
                protected virtual IList<XamlType> LookupPositionalParameters (int parameterCount)
                {
-                       throw new NotImplementedException ();
+                       if (UnderlyingType == null/* || !IsMarkupExtension*/) // see nunit tests...
+                               return null;
+
+                       // check if there is applicable ConstructorArgumentAttribute.
+                       // If there is, then return its type.
+                       if (parameterCount == 1) {
+                               foreach (var xm in GetAllMembers ()) {
+                                       // not sure if we can ignore xm's CustomAttributeProvider, but it's a default lookup implementation anyways...
+                                       var ca = xm.UnderlyingMember.GetCustomAttribute<ConstructorArgumentAttribute> (false);
+                                       if (ca != null)
+                                               return new XamlType [] {xm.Type};
+                               }
+                       }
+
+                       var methods = (from m in UnderlyingType.GetConstructors (BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance) where m.GetParameters ().Length == parameterCount select m).ToArray ();
+                       if (methods.Length == 1)
+                               return (from p in methods [0].GetParameters () select SchemaContext.GetXamlType (p.ParameterType)).ToArray ();
+
+                       if (SchemaContext.SupportMarkupExtensionsWithDuplicateArity)
+                               throw new NotSupportedException ("The default LookupPositionalParameters implementation does not allow duplicate arity of markup extensions");
+                       return null;
                }
 
                BindingFlags flags_get_static = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static;
index 0c95416a0db4a6910589610cf85c2279ffe24b47..0121fac1e195b120bce9cc45b5c0e32517ecfc9d 100644 (file)
@@ -1,3 +1,7 @@
+2010-04-20  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * XamlTypeTest.cs : added tests for GetPositionalParameters().
+
 2010-04-18  Atsushi Enomoto  <atsushi@ximian.com>
 
        * XamlObjectReaderTest.cs : enable working test.
index 2e1e91355dca0c9794a440758af90da58e468e77..2232c6637880c60999c960fc1555b9d355755578 100644 (file)
@@ -567,6 +567,30 @@ namespace MonoTests.System.Xaml
                        Assert.AreEqual ("{http://schemas.microsoft.com/winfx/2006/xaml}TypeExtension", XamlLanguage.Type.ToString (), "#2");
                        Assert.AreEqual ("{http://schemas.microsoft.com/winfx/2006/xaml}ArrayExtension", XamlLanguage.Array.ToString (), "#3");
                }
+
+               [Test]
+               public void GetPositionalParameters ()
+               {
+                       IList<XamlType> l;
+                       l = XamlLanguage.Type.GetPositionalParameters (1);
+                       Assert.IsNotNull (l, "#1");
+                       Assert.AreEqual (1, l.Count, "#2");
+                       Assert.AreEqual (typeof (Type), l [0].UnderlyingType, "#3"); // not TypeExtension but Type.
+                       Assert.AreEqual ("Type", l [0].Name, "#4");
+               }
+
+               [Test]
+               public void GetPositionalParametersWrongCount ()
+               {
+                       Assert.IsNull (XamlLanguage.Type.GetPositionalParameters (2), "#1");
+               }
+
+               [Test]
+               public void GetPositionalParametersNoMemberExtension ()
+               {
+                       // wow, so it returns some meaningless method parameters.
+                       Assert.IsNotNull (new XamlType (typeof (MyXamlType), sctx).GetPositionalParameters (3), "#1");
+               }
        }
 
        class MyXamlType : XamlType