* XamlType.cs : implement LookupPositionalParameters().
* XamlTypeTest.cs : added tests for GetPositionalParameters().
svn path=/trunk/mcs/; revision=155793
+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.
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;
+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.
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