From 6bfb5c36444fa292a12d89a10fc9e9b376c44925 Mon Sep 17 00:00:00 2001 From: Atsushi Eno Date: Thu, 20 Jan 2011 17:55:53 +0900 Subject: [PATCH] Implement some XamlTypeInvoker methods (mostly unused yet). --- .../System.Xaml.Schema/XamlTypeInvoker.cs | 33 ++++++++++++++-------- mcs/class/System.Xaml/System.Xaml/XamlType.cs | 2 +- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/mcs/class/System.Xaml/System.Xaml.Schema/XamlTypeInvoker.cs b/mcs/class/System.Xaml/System.Xaml.Schema/XamlTypeInvoker.cs index 2e27cf65152..b1556bbeb5e 100644 --- a/mcs/class/System.Xaml/System.Xaml.Schema/XamlTypeInvoker.cs +++ b/mcs/class/System.Xaml/System.Xaml.Schema/XamlTypeInvoker.cs @@ -65,20 +65,29 @@ namespace System.Xaml.Schema { if (instance == null) throw new ArgumentNullException ("instance"); + if (item == null) + throw new ArgumentNullException ("item"); + + var ct = instance.GetType (); + var xct = type.SchemaContext.GetXamlType (ct); + MethodInfo mi = null; - var t = instance.GetType (); if (type.UnderlyingType != null) { - if (!type.SchemaContext.GetXamlType (t).IsCollection) // not sure why this check is done only when UnderlyingType exists... - throw new NotSupportedException (String.Format ("Non-collection type '{0}' does not support this operation", t)); + if (!xct.IsCollection) // not sure why this check is done only when UnderlyingType exists... + throw new NotSupportedException (String.Format ("Non-collection type '{0}' does not support this operation", xct)); + if (ct.IsAssignableFrom (type.UnderlyingType)) + mi = GetAddMethod (type.SchemaContext.GetXamlType (item.GetType ())); + } + + if (mi == null) { + if (xct.IsGeneric) + mi = ct.GetMethod ("Add", ct.GetGenericArguments ()); + else + mi = ct.GetMethod ("Add", new Type [] {typeof (object)}); } - MethodInfo mi; - if (t.IsGenericType) - mi = instance.GetType ().GetMethod ("Add", t.GetGenericArguments ()); - else - mi = instance.GetType ().GetMethod ("Add", new Type [] {typeof (object)}); if (mi == null) - throw new InvalidOperationException (String.Format ("The collection type '{0}' does not have 'Add' method", t)); + throw new InvalidOperationException (String.Format ("The collection type '{0}' does not have 'Add' method", ct)); mi.Invoke (instance, new object [] {item}); } @@ -102,12 +111,14 @@ namespace System.Xaml.Schema public virtual MethodInfo GetAddMethod (XamlType contentType) { - throw new NotImplementedException (); + return type.UnderlyingType == null || type.ItemType == null || type.LookupCollectionKind () == XamlCollectionKind.None ? null : type.UnderlyingType.GetMethod ("Add", new Type [] {contentType.UnderlyingType}); } + public virtual MethodInfo GetEnumeratorMethod () { - throw new NotImplementedException (); + return type.UnderlyingType == null || type.LookupCollectionKind () == XamlCollectionKind.None ? null : type.UnderlyingType.GetMethod ("GetEnumerator"); } + public virtual IEnumerator GetItems (object instance) { if (instance == null) diff --git a/mcs/class/System.Xaml/System.Xaml/XamlType.cs b/mcs/class/System.Xaml/System.Xaml/XamlType.cs index bcde76a6e51..5705bc1a77e 100755 --- a/mcs/class/System.Xaml/System.Xaml/XamlType.cs +++ b/mcs/class/System.Xaml/System.Xaml/XamlType.cs @@ -520,7 +520,7 @@ namespace System.Xaml } // This implementation is not verified. (No place to use.) - protected virtual XamlCollectionKind LookupCollectionKind () + protected internal virtual XamlCollectionKind LookupCollectionKind () { if (UnderlyingType == null) return BaseType != null ? BaseType.LookupCollectionKind () : XamlCollectionKind.None; -- 2.11.4.GIT