From 2159a3696045c3bd3264838c3aeb89cddc0528ba Mon Sep 17 00:00:00 2001 From: Rama Krishnan Raghupathy Date: Thu, 9 Jul 2015 12:14:33 -0700 Subject: [PATCH] Fixing Databinding scenario for KeyValuePair. Refactoring the databinding code for CLRIReferenceImpl/CLRIReferenceArrayImpl/ICustomPropertyProviderProxy [tfs-changeset: 1499363] --- src/mscorlib/model.xml | 7 --- .../WindowsRuntime/CLRIKeyValuePairImpl.cs | 9 ++- .../WindowsRuntime/CLRIReferenceImpl.cs | 72 +++------------------- .../WindowsRuntime/ICustomPropertyProvider.cs | 60 ++++-------------- .../InteropServices/WindowsRuntime/RuntimeClass.cs | 4 ++ 5 files changed, 35 insertions(+), 117 deletions(-) diff --git a/src/mscorlib/model.xml b/src/mscorlib/model.xml index 0d81f3e..8c11c30 100644 --- a/src/mscorlib/model.xml +++ b/src/mscorlib/model.xml @@ -10198,13 +10198,6 @@ - - - - - - - diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIKeyValuePairImpl.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIKeyValuePairImpl.cs index 683a7f3..a4e8855 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIKeyValuePairImpl.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIKeyValuePairImpl.cs @@ -10,7 +10,8 @@ using System.Diagnostics.Contracts; namespace System.Runtime.InteropServices.WindowsRuntime { // Provides access to a System.Collections.Generic.KeyValuePair via the IKeyValuePair WinRT interface. - internal sealed class CLRIKeyValuePairImpl : IKeyValuePair + internal sealed class CLRIKeyValuePairImpl : IKeyValuePair, + IGetProxyTarget { private readonly KeyValuePair _pair; @@ -54,5 +55,11 @@ namespace System.Runtime.InteropServices.WindowsRuntime { return _pair.ToString(); } + + object IGetProxyTarget.GetTarget() + { + return _pair; + } + } } diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIReferenceImpl.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIReferenceImpl.cs index 99c546a..3455023 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIReferenceImpl.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIReferenceImpl.cs @@ -11,7 +11,7 @@ using System.Security; namespace System.Runtime.InteropServices.WindowsRuntime { - internal sealed class CLRIReferenceImpl : CLRIPropertyValueImpl, IReference, ICustomPropertyProvider + internal sealed class CLRIReferenceImpl : CLRIPropertyValueImpl, IReference, 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. Need to QI for IReference 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 : CLRIPropertyValueImpl, + internal sealed class CLRIReferenceArrayImpl : CLRIPropertyValueImpl, + IGetProxyTarget, IReferenceArray, - 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. Need to QI for IReferenceArray with the appropriate GUID, call // the get_Value property, allocate an appropriately-sized managed object, marshal the native object diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ICustomPropertyProvider.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ICustomPropertyProvider.cs index 51c6261..1840e61 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ICustomPropertyProvider.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ICustomPropertyProvider.cs @@ -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 : IGetProxyTarget, - ICustomPropertyProvider, ICustomQueryInterface, IEnumerable, // IBindableIterable -> IBindableIterable/IIterable IBindableVector, // IBindableVector -> IBindableVector/IVector @@ -195,31 +186,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime return new ICustomPropertyProviderProxy(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 diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/RuntimeClass.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/RuntimeClass.cs index 0139fab..ee5602f 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/RuntimeClass.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/RuntimeClass.cs @@ -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) -- 2.7.4