From: Atsushi Eno Date: Wed, 17 Nov 2010 20:52:55 +0000 (+0900) Subject: Support x:Arguments in XamlObjectWriter. X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=4c8dd3f47bfba7e91836877a487fcad707838f2f;p=mono.git Support x:Arguments in XamlObjectWriter. --- diff --git a/mcs/class/System.Xaml/System.Xaml/XamlObjectWriter.cs b/mcs/class/System.Xaml/System.Xaml/XamlObjectWriter.cs index 964a8a90346..abc4582d2b7 100644 --- a/mcs/class/System.Xaml/System.Xaml/XamlObjectWriter.cs +++ b/mcs/class/System.Xaml/System.Xaml/XamlObjectWriter.cs @@ -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) (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) (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)); diff --git a/mcs/class/System.Xaml/Test/System.Xaml/XamlObjectWriterTest.cs b/mcs/class/System.Xaml/Test/System.Xaml/XamlObjectWriterTest.cs index ba714001471..ceda7bcca9e 100755 --- a/mcs/class/System.Xaml/Test/System.Xaml/XamlObjectWriterTest.cs +++ b/mcs/class/System.Xaml/Test/System.Xaml/XamlObjectWriterTest.cs @@ -931,7 +931,6 @@ namespace MonoTests.System.Xaml } [Test] - [Category ("NotWorking")] public void Write_ArgumentAttributed () { //var obj = new ArgumentAttributed ("foo", "bar");