Move XamlType-generic PositionalParameter stuff from XamlObjectReader-specific source...
authorAtsushi Eno <atsushi@ximian.com>
Thu, 4 Nov 2010 07:49:44 +0000 (16:49 +0900)
committerAtsushi Eno <atsushi@ximian.com>
Thu, 4 Nov 2010 07:49:44 +0000 (16:49 +0900)
mcs/class/System.Xaml/System.Xaml/TypeExtensionMethods.cs
mcs/class/System.Xaml/System.Xaml/XamlNode.cs
mcs/class/System.Xaml/System.Xaml/XamlWriterStateManager.cs
mcs/class/System.Xaml/Test/System.Xaml/XamlObjectWriterTest.cs

index f0f7f95f9af108c228817322c22f2dab912c5c5e..9acc547bfaa90282e71224334a7b19ead8b26a9a 100644 (file)
@@ -139,6 +139,34 @@ namespace System.Xaml
                        return true;
                }
 
+               public static bool HasPositionalParameters (this XamlType type)
+               {
+                       // FIXME: find out why only TypeExtension and StaticExtension yield this directive. Seealso XamlObjectReaderTest.Read_CustomMarkupExtension*()
+                       return  type == XamlLanguage.Type ||
+                               type == XamlLanguage.Static ||
+                               ExaminePositionalParametersApplicable (type) && type.ConstructionRequiresArguments;
+               }
+               
+               static bool ExaminePositionalParametersApplicable (this XamlType type)
+               {
+                       if (!type.IsMarkupExtension || type.UnderlyingType == null)
+                               return false;
+
+                       var args = type.GetSortedConstructorArguments ();
+                       if (args == null)
+                               return false;
+
+                       foreach (var arg in args)
+                               if (arg.Type != null && !arg.Type.IsContentValue () && arg.Type.TypeConverter == null)
+                                       return false;
+
+                       Type [] argTypes = (from arg in args select arg.Type.UnderlyingType).ToArray ();
+                       if (argTypes.Any (at => at == null))
+                               return false;
+                       var ci = type.UnderlyingType.GetConstructor (argTypes);
+                       return ci != null;
+               }
+               
                public static IEnumerable<XamlMember> GetConstructorArguments (this XamlType type)
                {
                        return type.GetAllMembers ().Where (m => m.UnderlyingMember != null && m.GetCustomAttributeProvider ().GetCustomAttribute<ConstructorArgumentAttribute> (false) != null);
index 2ec063ff868e96fadf3e44a5a5206f522d27a0f6..7573fa4868645d9c48199e98cfd3210c50fe2c09 100644 (file)
@@ -395,33 +395,10 @@ namespace System.Xaml
 
        internal static class TypeExtensionMethods2
        {
-               static bool ExaminePositionalParametersApplicable (this XamlType type)
-               {
-                       if (!type.IsMarkupExtension || type.UnderlyingType == null)
-                               return false;
-
-                       var args = type.GetSortedConstructorArguments ();
-                       if (args == null)
-                               return false;
-
-                       foreach (var arg in args)
-                               if (arg.Type != null && !arg.Type.IsContentValue () && arg.Type.TypeConverter == null)
-                                       return false;
-
-                       Type [] argTypes = (from arg in args select arg.Type.UnderlyingType).ToArray ();
-                       if (argTypes.Any (at => at == null))
-                               return false;
-                       var ci = type.UnderlyingType.GetConstructor (argTypes);
-                       return ci != null;
-               }
-       
                // Note that this returns XamlMember which might not actually appear in XamlObjectReader. For example, XamlLanguage.Items won't be returned when there is no item in the collection.
                public static IEnumerable<XamlMember> GetAllObjectReaderMembersByType (this XamlType type, object dictionaryKey)
                {
-                       // FIXME: find out why only TypeExtension and StaticExtension yield this directive. Seealso XamlObjectReaderTest.Read_CustomMarkupExtension*()
-                       if (type == XamlLanguage.Type ||
-                           type == XamlLanguage.Static ||
-                           ExaminePositionalParametersApplicable (type) && type.ConstructionRequiresArguments) {
+                       if (type.HasPositionalParameters ()) {
                                yield return XamlLanguage.PositionalParameters;
                                yield break;
                        }
index 43edc63d59e1fd6a279e824a436b622f23ae4bd6..34c8a89343f0966f347589c380f4498758a93de7 100644 (file)
@@ -116,10 +116,17 @@ namespace System.Xaml
                // state
                XamlWriteState state = XamlWriteState.Initial;
                bool ns_pushed;
+               bool accept_multiple_values; // It is PositionalParameters-specific state.
 
                public bool HasNamespaces {
                        get { return ns_pushed; }
                }
+               
+               // FIXME: actually this property is a hack. It should preserve stacked flag values for each nested member in current tree state.
+               public bool AcceptMultipleValues {
+                       get { return accept_multiple_values; }
+                       set { accept_multiple_values = value; }
+               }
 
                public void OnClosingItem ()
                {
@@ -221,7 +228,7 @@ namespace System.Xaml
                        case XamlWriteState.ValueWritten:
                                switch (next) {
                                case XamlNodeType.Value:
-                                       if (allow_parallel_values)
+                                       if (allow_parallel_values | accept_multiple_values)
                                                return;
                                        break;
                                case XamlNodeType.StartObject:
index c4993dcd7b2d7d52b3b4aa91c7598ac23ba38aa4..3c6d778684e8dd2d2da6c5c98cb1221a6dea6b58 100644 (file)
@@ -334,6 +334,7 @@ namespace MonoTests.System.Xaml
                }
 
                [Test]
+               // This behavior is different from XamlXmlWriter. Compare to XamlXmlWriterTest.WriteValueList().
                public void WriteValueList ()
                {
                        var xw = new XamlObjectWriter (sctx, null);