Fixing Databinding scenario for KeyValuePair. Refactoring the databinding code for...
authorRama Krishnan Raghupathy <ramarag@microsoft.com>
Thu, 9 Jul 2015 19:14:33 +0000 (12:14 -0700)
committerRama Krishnan Raghupathy <ramarag@microsoft.com>
Thu, 9 Jul 2015 19:14:33 +0000 (12:14 -0700)
[tfs-changeset: 1499363]

src/mscorlib/model.xml
src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIKeyValuePairImpl.cs
src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIReferenceImpl.cs
src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ICustomPropertyProvider.cs
src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/RuntimeClass.cs

index 0d81f3e..8c11c30 100644 (file)
       <Member Name="Remove(System.Object)" />
       <Member Name="RemoveAt(System.Int32)" />
     </Type>
-    <Type Status="ImplRoot" Name="System.Runtime.InteropServices.WindowsRuntime.ICustomPropertyProvider" Condition="FEATURE_COMINTEROP">
-      <Member Name="GetCustomProperty(System.String)" />
-      <Member Name="GetIndexedProperty(System.String,System.Type)" />
-      <Member Name="GetStringRepresentation" />
-      <Member MemberType="Property"  Name="Type" />
-      <Member Name="get_Type" />
-    </Type>
     <Type Status="ImplRoot" Name="System.Runtime.InteropServices.WindowsRuntime.CLRIReferenceImpl&lt;T&gt;" Condition="FEATURE_COMINTEROP">
       <Member Name="UnboxHelper(System.Object)" />
     </Type>
index 683a7f3..a4e8855 100644 (file)
@@ -10,7 +10,8 @@ using System.Diagnostics.Contracts;
 namespace System.Runtime.InteropServices.WindowsRuntime
 {
     // Provides access to a System.Collections.Generic.KeyValuePair<K, V> via the IKeyValuePair<K, V> WinRT interface.
-    internal sealed class CLRIKeyValuePairImpl<K, V> : IKeyValuePair<K, V>
+    internal sealed class CLRIKeyValuePairImpl<K, V> : IKeyValuePair<K, V>,
+                                                       IGetProxyTarget
     {
         private readonly KeyValuePair<K, V> _pair;
 
@@ -54,5 +55,11 @@ namespace System.Runtime.InteropServices.WindowsRuntime
         {
             return _pair.ToString();
         }
+
+        object IGetProxyTarget.GetTarget()
+        {
+            return _pair;
+        }
+
     }
 }
index 99c546a..3455023 100644 (file)
@@ -11,7 +11,7 @@ using System.Security;
 
 namespace System.Runtime.InteropServices.WindowsRuntime
 {
-    internal sealed class CLRIReferenceImpl<T> : CLRIPropertyValueImpl, IReference<T>, ICustomPropertyProvider
+    internal sealed class CLRIReferenceImpl<T> : CLRIPropertyValueImpl, IReference<T>, IGetProxyTarget 
     {
         private T _value;
 
@@ -38,37 +38,11 @@ namespace System.Runtime.InteropServices.WindowsRuntime
             }
         }
 
-        [Pure]
-        ICustomProperty ICustomPropertyProvider.GetCustomProperty(string name)
+        object IGetProxyTarget.GetTarget()
         {
-            // _value should not be null
-            return ICustomPropertyProviderImpl.CreateProperty((object)_value, name);
+            return (object)_value;
         }
 
-        [Pure]
-        ICustomProperty ICustomPropertyProvider.GetIndexedProperty(string name, Type indexParameterType)
-        {
-            // _value should not be null
-            return ICustomPropertyProviderImpl.CreateIndexedProperty((object)_value, name, indexParameterType);
-        }
-
-        [Pure]
-        string ICustomPropertyProvider.GetStringRepresentation()
-        {
-            // _value should not be null
-            return ((object)_value).ToString();
-        }
-
-        Type ICustomPropertyProvider.Type 
-        { 
-            [Pure]        
-            get
-            {
-                // _value should not be null
-                return ((object)_value).GetType();
-            }
-        }
-        
         // We have T in an IReference<T>.  Need to QI for IReference<T> with the appropriate GUID, call
         // the get_Value property, allocate an appropriately-sized managed object, marshal the native object
         // to the managed object, and free the native method.  Also we want the return value boxed (aka normal value type boxing).
@@ -86,9 +60,9 @@ namespace System.Runtime.InteropServices.WindowsRuntime
     }
 
     // T can be any WinRT-compatible type
-    internal sealed class CLRIReferenceArrayImpl<T> : CLRIPropertyValueImpl, 
+    internal sealed class CLRIReferenceArrayImpl<T> : CLRIPropertyValueImpl,
+                                                      IGetProxyTarget, 
                                                       IReferenceArray<T>, 
-                                                      ICustomPropertyProvider,
                                                       IList                     // Jupiter data binding needs IList/IEnumerable
     {
         private T[] _value;
@@ -120,37 +94,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime
             }
         }
 
-        [Pure]
-        ICustomProperty ICustomPropertyProvider.GetCustomProperty(string name)
-        {
-            // _value should not be null
-            return ICustomPropertyProviderImpl.CreateProperty((object)_value, name);
-        }
-
-        [Pure]
-        ICustomProperty ICustomPropertyProvider.GetIndexedProperty(string name, Type indexParameterType)
-        {
-            // _value should not be null
-            return ICustomPropertyProviderImpl.CreateIndexedProperty((object)_value, name, indexParameterType);
-        }
-
-        [Pure]
-        string ICustomPropertyProvider.GetStringRepresentation()
-        {
-            // _value should not be null
-            return ((object)_value).ToString();
-        }
-
-        Type ICustomPropertyProvider.Type 
-        { 
-            [Pure]        
-            get
-            {
-                // _value should not be null
-                return ((object)_value).GetType();
-            }
-        }
-
         //
         // IEnumerable methods. Used by data-binding in Jupiter when you try to data bind
         // against a managed array
@@ -255,6 +198,11 @@ namespace System.Runtime.InteropServices.WindowsRuntime
                 return _list.IsSynchronized;
             }
         }
+
+        object IGetProxyTarget.GetTarget()
+        {
+            return (object)_value;
+        }
         
         // We have T in an IReferenceArray<T>.  Need to QI for IReferenceArray<T> with the appropriate GUID, call
         // the get_Value property, allocate an appropriately-sized managed object, marshal the native object
index 51c6261..1840e61 100644 (file)
@@ -15,29 +15,9 @@ using System.Security;
 
 namespace System.Runtime.InteropServices.WindowsRuntime
 {
-    [ComImport]
-    [Guid("7C925755-3E48-42B4-8677-76372267033F")]
-    [WindowsRuntimeImport]
-    internal interface ICustomPropertyProvider 
-    {    
-        [Pure]
-        ICustomProperty GetCustomProperty(string name);
-
-        [Pure]
-        ICustomProperty GetIndexedProperty(string name, Type indexParameterType);
-
-        [Pure]
-        string GetStringRepresentation();
-
-        Type Type 
-        { 
-            [Pure]        
-            get; 
-        }
-    }
 
     //
-    // Implementation helpers
+    // ICustomProperty Implementation helpers
     //
     internal static class ICustomPropertyProviderImpl
     {
@@ -50,6 +30,10 @@ namespace System.Runtime.InteropServices.WindowsRuntime
             Contract.Requires(target != null);
             Contract.Requires(propertyName != null);
 
+            IGetProxyTarget proxy = target as IGetProxyTarget;
+            if (proxy != null) 
+                target = proxy.GetTarget();
+
             // Only return public instance/static properties
             PropertyInfo propertyInfo = target.GetType().GetProperty(
                 propertyName,
@@ -82,6 +66,10 @@ namespace System.Runtime.InteropServices.WindowsRuntime
             Contract.Requires(target != null);
             Contract.Requires(propertyName != null);
 
+            IGetProxyTarget proxy = target as IGetProxyTarget;
+            if (proxy != null) 
+                target = proxy.GetTarget();
+
             // Only return public instance/static properties
             PropertyInfo propertyInfo = target.GetType().GetProperty(
                 propertyName,
@@ -101,6 +89,10 @@ namespace System.Runtime.InteropServices.WindowsRuntime
         [System.Security.SecurityCritical]
         static internal unsafe void GetType(object target, TypeNameNative *pIndexedParamType)
         {            
+            IGetProxyTarget proxy = target as IGetProxyTarget;
+            if (proxy != null) 
+                target = proxy.GetTarget();
+
             SystemTypeMarshaler.ConvertToNative(target.GetType(), pIndexedParamType);
         }        
     }
@@ -140,7 +132,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime
     //
     //
     internal class ICustomPropertyProviderProxy<T1, T2> : IGetProxyTarget,
-                                                          ICustomPropertyProvider, 
                                                           ICustomQueryInterface,
                                                           IEnumerable,          // IBindableIterable -> IBindableIterable/IIterable<T>
                                                           IBindableVector,      // IBindableVector -> IBindableVector/IVector<T>
@@ -195,31 +186,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime
             return new ICustomPropertyProviderProxy<T1, T2>(target, supportFlags);                
         }
 
-        //
-        // ICustomPropertyProvider implementation
-        //
-        ICustomProperty ICustomPropertyProvider.GetCustomProperty(string name)
-        {
-            return ICustomPropertyProviderImpl.CreateProperty(_target, name);
-        }
-
-        ICustomProperty ICustomPropertyProvider.GetIndexedProperty(string name, Type indexParameterType)
-        {
-            return ICustomPropertyProviderImpl.CreateIndexedProperty(_target, name, indexParameterType);
-        }
-
-        string ICustomPropertyProvider.GetStringRepresentation()
-        {
-            return WindowsRuntime.IStringableHelper.ToString(_target);
-        }
-
-        Type ICustomPropertyProvider.Type 
-        { 
-            get
-            {
-                return _target.GetType();
-            }
-        }
 
         //
         // override ToString() to make sure callers get correct IStringable.ToString() behavior in native code
index 0139fab..ee5602f 100644 (file)
@@ -31,6 +31,10 @@ namespace System.Runtime.InteropServices.WindowsRuntime {
     {
         internal static string ToString(object obj)
         {
+            IGetProxyTarget proxy = obj as IGetProxyTarget;
+            if (proxy != null) 
+                obj = proxy.GetTarget();
+
             // Check whether the type implements IStringable.
             IStringable stringableType = obj as IStringable;
             if (stringableType != null)