Support x:Arguments in XamlObjectWriter.
authorAtsushi Eno <atsushi@ximian.com>
Wed, 17 Nov 2010 20:52:55 +0000 (05:52 +0900)
committerAtsushi Eno <atsushi@ximian.com>
Wed, 17 Nov 2010 20:52:55 +0000 (05:52 +0900)
mcs/class/System.Xaml/System.Xaml/XamlObjectWriter.cs
mcs/class/System.Xaml/Test/System.Xaml/XamlObjectWriterTest.cs

index 964a8a90346579bbd153ed008ab5c22ffc578c16..abc4582d2b7d58896fe621750eeee57b4b418f86 100644 (file)
@@ -164,13 +164,7 @@ namespace System.Xaml
                        if (xm == XamlLanguage.PositionalParameters) {
                                manager.AcceptMultipleValues = false;
                                //state.PositionalParameterIndex = -1;
-                               var args = state.Type.GetSortedConstructorArguments ();
-                               var argt = args != null ? (IList<XamlType>) (from arg in args select arg.Type).ToArray () : state.Type.GetPositionalParameters (state.Contents.Count);
-                               var argv = new object [argt.Count];
-                               for (int i = 0; i < argv.Length; i++)
-                                       argv [i] = GetCorrectlyTypedValue (argt [i], state.Contents [i]);
-                               state.Value = state.Type.Invoker.CreateInstance (argv);
-                               state.IsInstantiated = true;
+                               FillConstructedObject (true);
                        } else if (xm == XamlLanguage.FactoryMethod) {
                                if (contents.Count != 1 || !(contents [0] is string))
                                        throw new XamlObjectWriterException (String.Format ("FactoryMethod must be non-empty string name. {0} value exists.", contents.Count > 0 ? contents [0] : "0"));
@@ -183,7 +177,7 @@ namespace System.Xaml
                                        state.Value = mi.Invoke (null, contents.ToArray ());
                                }
                                else
-                                       throw new NotImplementedException ();
+                                       FillConstructedObject (false);
                        } else if (xm == XamlLanguage.Initialization) {
                                // ... and no need to do anything. The object value to pop *is* the return value.
                        } else if (xm == XamlLanguage.Items) {
@@ -209,6 +203,20 @@ namespace System.Xaml
                        //written_properties_stack.Peek ().Add (xm);
                }
 
+               void FillConstructedObject (bool considerPositionalParameters)
+               {
+                       var state = object_states.Peek ();
+
+                       var args = state.Type.GetSortedConstructorArguments ();
+                       var argt = args != null ? (IList<XamlType>) (from arg in args select arg.Type).ToArray () : considerPositionalParameters ? state.Type.GetPositionalParameters (state.Contents.Count) : null;
+
+                       var argv = new object [argt.Count];
+                       for (int i = 0; i < argv.Length; i++)
+                               argv [i] = GetCorrectlyTypedValue (argt [i], state.Contents [i]);
+                       state.Value = state.Type.Invoker.CreateInstance (argv);
+                       state.IsInstantiated = true;
+               }
+
                object GetCorrectlyTypedValue (XamlType xt, object value)
                {
                        try {
@@ -364,7 +372,7 @@ namespace System.Xaml
 
                        var xm = members.Count > 0 ? members.Peek () : null;
                        var pstate = xm != null ? object_states.Peek () : null;
-                       var wpl = xm != null && xm != XamlLanguage.Items ? pstate.WrittenProperties : null;
+                       var wpl = xm == null || xm.Type.IsCollection || xm.Type.IsDictionary ? null : pstate.WrittenProperties;
                        if (wpl != null && wpl.Contains (xm))
                                throw new XamlDuplicateMemberException (String.Format ("Property '{0}' is already set to this '{1}' object", xm, pstate.Type));
 
index ba714001471ff04340820a3b10fe1b080832d6b4..ceda7bcca9ebe82d956030ab1af7f3b96e6dc71d 100755 (executable)
@@ -931,7 +931,6 @@ namespace MonoTests.System.Xaml
                }
                
                [Test]
-               [Category ("NotWorking")]
                public void Write_ArgumentAttributed ()
                {
                        //var obj = new ArgumentAttributed ("foo", "bar");