diff --git a/src/WinRT.Runtime/Projections/ICustomPropertyProvider.net5.cs b/src/WinRT.Runtime/Projections/ICustomPropertyProvider.net5.cs index 674631c80..469a5e6b3 100644 --- a/src/WinRT.Runtime/Projections/ICustomPropertyProvider.net5.cs +++ b/src/WinRT.Runtime/Projections/ICustomPropertyProvider.net5.cs @@ -1,55 +1,55 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -using System; -using System.Diagnostics.CodeAnalysis; -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using WinRT; - -// These types have the same GUIDs in both Microsoft.UI.Xaml and Windows.UI.Xaml, -// so we don't need to duplicate them for the internal usage here as they can be transparently used by both WUX and MUX. -namespace Microsoft.UI.Xaml.Data -{ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using System; +using System.Diagnostics.CodeAnalysis; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using WinRT; + +// These types have the same GUIDs in both Microsoft.UI.Xaml and Windows.UI.Xaml, +// so we don't need to duplicate them for the internal usage here as they can be transparently used by both WUX and MUX. +namespace Microsoft.UI.Xaml.Data +{ [global::WinRT.WindowsRuntimeType] - [global::WinRT.WindowsRuntimeHelperType(typeof(global::ABI.Microsoft.UI.Xaml.Data.ICustomProperty))] - [Guid("30DA92C0-23E8-42A0-AE7C-734A0E5D2782")] - internal interface ICustomProperty - { - object GetValue(object target); - void SetValue(object target, object value); - object GetIndexedValue(object target, object index); - void SetIndexedValue(object target, object value, object index); - bool CanRead { get; } - bool CanWrite { get; } - string Name { get; } - global::System.Type Type { get; } + [global::WinRT.WindowsRuntimeHelperType(typeof(global::ABI.Microsoft.UI.Xaml.Data.ICustomProperty))] + [Guid("30DA92C0-23E8-42A0-AE7C-734A0E5D2782")] + internal interface ICustomProperty + { + object GetValue(object target); + void SetValue(object target, object value); + object GetIndexedValue(object target, object index); + void SetIndexedValue(object target, object value, object index); + bool CanRead { get; } + bool CanWrite { get; } + string Name { get; } + global::System.Type Type { get; } } /// /// An interface complementing providing the implementation to expose the specified properties. /// -#if EMBED - internal -#else +#if EMBED + internal +#else public -#endif - interface IBindableCustomPropertyImplementation +#endif + interface IBindableCustomPropertyImplementation { /// /// Get the generated implementation representing the specified property name. /// /// The name of the property to get. /// The implementation for the property specified by . - public Microsoft.UI.Xaml.Data.BindableCustomProperty GetProperty(string name); - + public Microsoft.UI.Xaml.Data.BindableCustomProperty GetProperty(string name); + /// /// Get the generated implementation representing the specified index property type. /// /// The index property to get. /// The implementation for the property specified by . - public Microsoft.UI.Xaml.Data.BindableCustomProperty GetProperty(Type indexParameterType); + public Microsoft.UI.Xaml.Data.BindableCustomProperty GetProperty(Type indexParameterType); } /// @@ -57,9 +57,9 @@ interface IBindableCustomPropertyImplementation /// rather than reflection. This is used by the source generator generating the implementation for . /// [global::WinRT.WinRTExposedType(typeof(global::ABI.Microsoft.UI.Xaml.Data.ManagedCustomPropertyWinRTTypeDetails))] -#if EMBED - internal -#else +#if EMBED + internal +#else public #endif sealed class BindableCustomProperty : ICustomProperty @@ -124,184 +124,184 @@ void ICustomProperty.SetValue(object target, object value) _setValue(target, value); } - } -} - -namespace ABI.Microsoft.UI.Xaml.Data -{ - [Guid("30DA92C0-23E8-42A0-AE7C-734A0E5D2782")] - internal unsafe interface ICustomProperty + } +} + +namespace ABI.Microsoft.UI.Xaml.Data +{ + [Guid("30DA92C0-23E8-42A0-AE7C-734A0E5D2782")] + internal unsafe interface ICustomProperty { public static readonly IntPtr AbiToProjectionVftablePtr; public static global::System.Guid IID => global::WinRT.Interop.IID.IID_ICustomProperty; - + static unsafe ICustomProperty() { AbiToProjectionVftablePtr = ComWrappersSupport.AllocateVtableMemory(typeof(ICustomProperty), sizeof(IInspectable.Vftbl) + sizeof(IntPtr) * 8); *(IInspectable.Vftbl*)AbiToProjectionVftablePtr = IInspectable.Vftbl.AbiToProjectionVftable; ((delegate* unmanaged*)AbiToProjectionVftablePtr)[6] = &Do_Abi_get_Type_0; - ((delegate* unmanaged*)AbiToProjectionVftablePtr)[7] = &Do_Abi_get_Name_1; - ((delegate* unmanaged*)AbiToProjectionVftablePtr)[8] = &Do_Abi_GetValue_2; - ((delegate* unmanaged*)AbiToProjectionVftablePtr)[9] = &Do_Abi_SetValue_3; - ((delegate* unmanaged*)AbiToProjectionVftablePtr)[10] = &Do_Abi_GetIndexedValue_4; - ((delegate* unmanaged*)AbiToProjectionVftablePtr)[11] = &Do_Abi_SetIndexedValue_5; - ((delegate* unmanaged*)AbiToProjectionVftablePtr)[12] = &Do_Abi_get_CanWrite_6; + ((delegate* unmanaged*)AbiToProjectionVftablePtr)[7] = &Do_Abi_get_Name_1; + ((delegate* unmanaged*)AbiToProjectionVftablePtr)[8] = &Do_Abi_GetValue_2; + ((delegate* unmanaged*)AbiToProjectionVftablePtr)[9] = &Do_Abi_SetValue_3; + ((delegate* unmanaged*)AbiToProjectionVftablePtr)[10] = &Do_Abi_GetIndexedValue_4; + ((delegate* unmanaged*)AbiToProjectionVftablePtr)[11] = &Do_Abi_SetIndexedValue_5; + ((delegate* unmanaged*)AbiToProjectionVftablePtr)[12] = &Do_Abi_get_CanWrite_6; ((delegate* unmanaged*)AbiToProjectionVftablePtr)[13] = &Do_Abi_get_CanRead_7; - } - - [UnmanagedCallersOnly] - private static unsafe int Do_Abi_GetValue_2(IntPtr thisPtr, IntPtr target, IntPtr* result) - { - object __result = default; - - *result = default; - - try - { - __result = global::WinRT.ComWrappersSupport.FindObject(thisPtr).GetValue(MarshalInspectable.FromAbi(target)); - *result = MarshalInspectable.FromManaged(__result); - - } - catch (Exception __exception__) - { - global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); - return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); - } - return 0; - } - - [UnmanagedCallersOnly] - private static unsafe int Do_Abi_SetValue_3(IntPtr thisPtr, IntPtr target, IntPtr value) - { - try - { - global::WinRT.ComWrappersSupport.FindObject(thisPtr).SetValue(MarshalInspectable.FromAbi(target), MarshalInspectable.FromAbi(value)); - } - catch (Exception __exception__) - { - global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); - return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); - } - return 0; - } - - [UnmanagedCallersOnly] - private static unsafe int Do_Abi_GetIndexedValue_4(IntPtr thisPtr, IntPtr target, IntPtr index, IntPtr* result) - { - object __result = default; - - try - { - __result = global::WinRT.ComWrappersSupport.FindObject(thisPtr).GetIndexedValue(MarshalInspectable.FromAbi(target), MarshalInspectable.FromAbi(index)); - *result = MarshalInspectable.FromManaged(__result); - - } - catch (Exception __exception__) - { - global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); - return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); - } - return 0; - } - - [UnmanagedCallersOnly] - private static unsafe int Do_Abi_SetIndexedValue_5(IntPtr thisPtr, IntPtr target, IntPtr value, IntPtr index) - { - try - { - global::WinRT.ComWrappersSupport.FindObject(thisPtr).SetIndexedValue(MarshalInspectable.FromAbi(target), MarshalInspectable.FromAbi(value), MarshalInspectable.FromAbi(index)); - } - catch (Exception __exception__) - { - global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); - return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); - } - return 0; - } - - [UnmanagedCallersOnly] - private static unsafe int Do_Abi_get_CanRead_7(IntPtr thisPtr, byte* value) - { - bool __value = default; - - try - { - __value = global::WinRT.ComWrappersSupport.FindObject(thisPtr).CanRead; *value = (byte)(__value ? 1 : 0); - - } - catch (Exception __exception__) - { - global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); - return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); - } - return 0; - } - - [UnmanagedCallersOnly] - private static unsafe int Do_Abi_get_CanWrite_6(IntPtr thisPtr, byte* value) - { - bool __value = default; - - try - { - __value = global::WinRT.ComWrappersSupport.FindObject(thisPtr).CanWrite; *value = (byte)(__value ? 1 : 0); - - } - catch (Exception __exception__) - { - global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); - return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); - } - return 0; - } - - [UnmanagedCallersOnly] - private static unsafe int Do_Abi_get_Name_1(IntPtr thisPtr, IntPtr* value) - { - string __value = default; - - try - { - __value = global::WinRT.ComWrappersSupport.FindObject(thisPtr).Name; - *value = MarshalString.FromManaged(__value); - - } - catch (Exception __exception__) - { - global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); - return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); - } - return 0; - } - - [UnmanagedCallersOnly] - private static unsafe int Do_Abi_get_Type_0(IntPtr thisPtr, global::ABI.System.Type* value) - { - global::System.Type __value = default; - - try - { - __value = global::WinRT.ComWrappersSupport.FindObject(thisPtr).Type; - *value = global::ABI.System.Type.FromManaged(__value); - } - catch (Exception __exception__) - { - global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); - return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); - } - return 0; - } - } - internal static class ICustomProperty_Delegates - { - public unsafe delegate int get_Type_0(IntPtr thisPtr, global::ABI.System.Type* value); - public unsafe delegate int get_Name_1(IntPtr thisPtr, IntPtr* value); - public unsafe delegate int GetValue_2(IntPtr thisPtr, IntPtr target, IntPtr* result); - public unsafe delegate int SetValue_3(IntPtr thisPtr, IntPtr target, IntPtr value); - public unsafe delegate int GetIndexedValue_4(IntPtr thisPtr, IntPtr target, IntPtr index, IntPtr* result); - public unsafe delegate int SetIndexedValue_5(IntPtr thisPtr, IntPtr target, IntPtr value, IntPtr index); - public unsafe delegate int get_CanWrite_6(IntPtr thisPtr, byte* value); - public unsafe delegate int get_CanRead_7(IntPtr thisPtr, byte* value); + } + + [UnmanagedCallersOnly] + private static unsafe int Do_Abi_GetValue_2(IntPtr thisPtr, IntPtr target, IntPtr* result) + { + object __result = default; + + *result = default; + + try + { + __result = global::WinRT.ComWrappersSupport.FindObject(thisPtr).GetValue(MarshalInspectable.FromAbi(target)); + *result = MarshalInspectable.FromManaged(__result); + + } + catch (Exception __exception__) + { + global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); + return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); + } + return 0; + } + + [UnmanagedCallersOnly] + private static unsafe int Do_Abi_SetValue_3(IntPtr thisPtr, IntPtr target, IntPtr value) + { + try + { + global::WinRT.ComWrappersSupport.FindObject(thisPtr).SetValue(MarshalInspectable.FromAbi(target), MarshalInspectable.FromAbi(value)); + } + catch (Exception __exception__) + { + global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); + return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); + } + return 0; + } + + [UnmanagedCallersOnly] + private static unsafe int Do_Abi_GetIndexedValue_4(IntPtr thisPtr, IntPtr target, IntPtr index, IntPtr* result) + { + object __result = default; + + try + { + __result = global::WinRT.ComWrappersSupport.FindObject(thisPtr).GetIndexedValue(MarshalInspectable.FromAbi(target), MarshalInspectable.FromAbi(index)); + *result = MarshalInspectable.FromManaged(__result); + + } + catch (Exception __exception__) + { + global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); + return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); + } + return 0; + } + + [UnmanagedCallersOnly] + private static unsafe int Do_Abi_SetIndexedValue_5(IntPtr thisPtr, IntPtr target, IntPtr value, IntPtr index) + { + try + { + global::WinRT.ComWrappersSupport.FindObject(thisPtr).SetIndexedValue(MarshalInspectable.FromAbi(target), MarshalInspectable.FromAbi(value), MarshalInspectable.FromAbi(index)); + } + catch (Exception __exception__) + { + global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); + return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); + } + return 0; + } + + [UnmanagedCallersOnly] + private static unsafe int Do_Abi_get_CanRead_7(IntPtr thisPtr, byte* value) + { + bool __value = default; + + try + { + __value = global::WinRT.ComWrappersSupport.FindObject(thisPtr).CanRead; *value = (byte)(__value ? 1 : 0); + + } + catch (Exception __exception__) + { + global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); + return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); + } + return 0; + } + + [UnmanagedCallersOnly] + private static unsafe int Do_Abi_get_CanWrite_6(IntPtr thisPtr, byte* value) + { + bool __value = default; + + try + { + __value = global::WinRT.ComWrappersSupport.FindObject(thisPtr).CanWrite; *value = (byte)(__value ? 1 : 0); + + } + catch (Exception __exception__) + { + global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); + return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); + } + return 0; + } + + [UnmanagedCallersOnly] + private static unsafe int Do_Abi_get_Name_1(IntPtr thisPtr, IntPtr* value) + { + string __value = default; + + try + { + __value = global::WinRT.ComWrappersSupport.FindObject(thisPtr).Name; + *value = MarshalString.FromManaged(__value); + + } + catch (Exception __exception__) + { + global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); + return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); + } + return 0; + } + + [UnmanagedCallersOnly] + private static unsafe int Do_Abi_get_Type_0(IntPtr thisPtr, global::ABI.System.Type* value) + { + global::System.Type __value = default; + + try + { + __value = global::WinRT.ComWrappersSupport.FindObject(thisPtr).Type; + *value = global::ABI.System.Type.FromManaged(__value); + } + catch (Exception __exception__) + { + global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); + return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); + } + return 0; + } + } + internal static class ICustomProperty_Delegates + { + public unsafe delegate int get_Type_0(IntPtr thisPtr, global::ABI.System.Type* value); + public unsafe delegate int get_Name_1(IntPtr thisPtr, IntPtr* value); + public unsafe delegate int GetValue_2(IntPtr thisPtr, IntPtr target, IntPtr* result); + public unsafe delegate int SetValue_3(IntPtr thisPtr, IntPtr target, IntPtr value); + public unsafe delegate int GetIndexedValue_4(IntPtr thisPtr, IntPtr target, IntPtr index, IntPtr* result); + public unsafe delegate int SetIndexedValue_5(IntPtr thisPtr, IntPtr target, IntPtr value, IntPtr index); + public unsafe delegate int get_CanWrite_6(IntPtr thisPtr, byte* value); + public unsafe delegate int get_CanRead_7(IntPtr thisPtr, byte* value); } internal sealed class ManagedCustomPropertyWinRTTypeDetails : global::WinRT.IWinRTExposedTypeDetails @@ -309,93 +309,93 @@ internal sealed class ManagedCustomPropertyWinRTTypeDetails : global::WinRT.IWin public ComWrappers.ComInterfaceEntry[] GetExposedInterfaces() { return new ComWrappers.ComInterfaceEntry[] - { - new ComWrappers.ComInterfaceEntry - { - IID = ICustomProperty.IID, - Vtable = ICustomProperty.AbiToProjectionVftablePtr + { + new ComWrappers.ComInterfaceEntry + { + IID = ICustomProperty.IID, + Vtable = ICustomProperty.AbiToProjectionVftablePtr }, }; } } - [global::WinRT.WinRTExposedType(typeof(ManagedCustomPropertyWinRTTypeDetails))] - internal sealed class ManagedCustomProperty : global::Microsoft.UI.Xaml.Data.ICustomProperty - { - private readonly PropertyInfo _property; - - public ManagedCustomProperty(PropertyInfo property) - { - _property = property; - } - - public bool CanRead => _property.CanRead; - - public bool CanWrite => _property.CanWrite; - - public string Name => _property.Name; - - public Type Type => _property.PropertyType; - - public object GetIndexedValue(object target, object index) - { - return _property.GetValue(target, new[] { index }); - } - - public object GetValue(object target) - { - return _property.GetValue(target); - } - - public void SetIndexedValue(object target, object value, object index) - { - _property.SetValue(target, value, new[] { index }); - } - - public void SetValue(object target, object value) - { - _property.SetValue(target, value); - } - } - - [Guid("7C925755-3E48-42B4-8677-76372267033F")] - [StructLayout(LayoutKind.Sequential)] - internal unsafe struct ManagedCustomPropertyProviderVftbl - { - internal IInspectable.Vftbl IInspectableVftbl; - private void* GetCustomProperty_0; - private void* GetIndexedProperty_1; - private void* GetStringRepresentation_2; - private void* get_Type_3; - - private static readonly ManagedCustomPropertyProviderVftbl AbiToProjectionVftable; - public static readonly IntPtr AbiToProjectionVftablePtr; - - static unsafe ManagedCustomPropertyProviderVftbl() - { - AbiToProjectionVftable = new ManagedCustomPropertyProviderVftbl - { - IInspectableVftbl = global::WinRT.IInspectable.Vftbl.AbiToProjectionVftable, - - GetCustomProperty_0 = (delegate* unmanaged)&Do_Abi_GetCustomProperty_0, - GetIndexedProperty_1 = (delegate* unmanaged)&Do_Abi_GetIndexedProperty_1, - GetStringRepresentation_2 = (delegate* unmanaged)&Do_Abi_GetStringRepresentation_2, - get_Type_3 = (delegate* unmanaged)&Do_Abi_get_Type_3 - - }; - var nativeVftbl = (IntPtr*)ComWrappersSupport.AllocateVtableMemory(typeof(ManagedCustomPropertyProviderVftbl), sizeof(global::WinRT.IInspectable.Vftbl) + sizeof(IntPtr) * 4); - *(ManagedCustomPropertyProviderVftbl*)nativeVftbl = AbiToProjectionVftable; - AbiToProjectionVftablePtr = (IntPtr)nativeVftbl; - } - - - [UnmanagedCallersOnly] - private static unsafe int Do_Abi_GetCustomProperty_0(IntPtr thisPtr, IntPtr name, IntPtr* result) - { - global::Microsoft.UI.Xaml.Data.ICustomProperty __result = default; - try - { - string _name = MarshalString.FromAbi(name); + [global::WinRT.WinRTExposedType(typeof(ManagedCustomPropertyWinRTTypeDetails))] + internal sealed class ManagedCustomProperty : global::Microsoft.UI.Xaml.Data.ICustomProperty + { + private readonly PropertyInfo _property; + + public ManagedCustomProperty(PropertyInfo property) + { + _property = property; + } + + public bool CanRead => _property.CanRead; + + public bool CanWrite => _property.CanWrite; + + public string Name => _property.Name; + + public Type Type => _property.PropertyType; + + public object GetIndexedValue(object target, object index) + { + return _property.GetValue(target, new[] { index }); + } + + public object GetValue(object target) + { + return _property.GetValue(target); + } + + public void SetIndexedValue(object target, object value, object index) + { + _property.SetValue(target, value, new[] { index }); + } + + public void SetValue(object target, object value) + { + _property.SetValue(target, value); + } + } + + [Guid("7C925755-3E48-42B4-8677-76372267033F")] + [StructLayout(LayoutKind.Sequential)] + internal unsafe struct ManagedCustomPropertyProviderVftbl + { + internal IInspectable.Vftbl IInspectableVftbl; + private void* GetCustomProperty_0; + private void* GetIndexedProperty_1; + private void* GetStringRepresentation_2; + private void* get_Type_3; + + private static readonly ManagedCustomPropertyProviderVftbl AbiToProjectionVftable; + public static readonly IntPtr AbiToProjectionVftablePtr; + + static unsafe ManagedCustomPropertyProviderVftbl() + { + AbiToProjectionVftable = new ManagedCustomPropertyProviderVftbl + { + IInspectableVftbl = global::WinRT.IInspectable.Vftbl.AbiToProjectionVftable, + + GetCustomProperty_0 = (delegate* unmanaged)&Do_Abi_GetCustomProperty_0, + GetIndexedProperty_1 = (delegate* unmanaged)&Do_Abi_GetIndexedProperty_1, + GetStringRepresentation_2 = (delegate* unmanaged)&Do_Abi_GetStringRepresentation_2, + get_Type_3 = (delegate* unmanaged)&Do_Abi_get_Type_3 + + }; + var nativeVftbl = (IntPtr*)ComWrappersSupport.AllocateVtableMemory(typeof(ManagedCustomPropertyProviderVftbl), sizeof(global::WinRT.IInspectable.Vftbl) + sizeof(IntPtr) * 4); + *(ManagedCustomPropertyProviderVftbl*)nativeVftbl = AbiToProjectionVftable; + AbiToProjectionVftablePtr = (IntPtr)nativeVftbl; + } + + + [UnmanagedCallersOnly] + private static unsafe int Do_Abi_GetCustomProperty_0(IntPtr thisPtr, IntPtr name, IntPtr* result) + { + global::Microsoft.UI.Xaml.Data.ICustomProperty __result = default; + try + { + string _name = MarshalString.FromAbi(name); object target = global::WinRT.ComWrappersSupport.FindObject(thisPtr); if (target is global::Microsoft.UI.Xaml.Data.IBindableCustomPropertyImplementation bindableCustomPropertyImplementation) @@ -408,7 +408,8 @@ private static unsafe int Do_Abi_GetCustomProperty_0(IntPtr thisPtr, IntPtr name if (!RuntimeFeature.IsDynamicCodeCompiled) { throw new NotSupportedException( - $"ICustomProperty support used by XAML binding for '{target.GetType()}' requires the type to marked with 'WinRT.GeneratedBindableCustomPropertyAttribute'. " + + $"ICustomProperty support used by XAML binding for type '{target.GetType()}' (property '{_name}') requires the type to marked with 'WinRT.GeneratedBindableCustomPropertyAttribute'. " + + $"If this is a built-in type or a type that can't be marked, a wrapper type should be used around it that is marked to enable this support."); } @@ -418,7 +419,7 @@ private static unsafe int Do_Abi_GetCustomProperty_0(IntPtr thisPtr, IntPtr name [MethodImpl(MethodImplOptions.NoInlining)] static void GetCustomPropertyForJit(object target, string name, IntPtr* result) { - global::Microsoft.UI.Xaml.Data.ICustomProperty __result = default; + global::Microsoft.UI.Xaml.Data.ICustomProperty __result = default; PropertyInfo propertyInfo = target.GetType().GetProperty( name, @@ -431,24 +432,23 @@ static void GetCustomPropertyForJit(object target, string name, IntPtr* result) *result = MarshalInterface.FromManaged(__result); } - } - catch (Exception __exception__) - { - global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); - return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); - } - return 0; - } - - [UnmanagedCallersOnly] - private static unsafe int Do_Abi_GetIndexedProperty_1(IntPtr thisPtr, IntPtr name, global::ABI.System.Type type, IntPtr* result) - { - global::Microsoft.UI.Xaml.Data.ICustomProperty __result = default; - try - { - string _name = MarshalString.FromAbi(name); - Type _type = global::ABI.System.Type.FromAbi(type); - + } + catch (Exception __exception__) + { + global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); + return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); + } + return 0; + } + + [UnmanagedCallersOnly] + private static unsafe int Do_Abi_GetIndexedProperty_1(IntPtr thisPtr, IntPtr name, global::ABI.System.Type type, IntPtr* result) + { + global::Microsoft.UI.Xaml.Data.ICustomProperty __result = default; + try + { + Type _type = global::ABI.System.Type.FromAbi(type); + object target = global::WinRT.ComWrappersSupport.FindObject(thisPtr); if (target is global::Microsoft.UI.Xaml.Data.IBindableCustomPropertyImplementation bindableCustomPropertyImplementation) @@ -461,25 +461,29 @@ private static unsafe int Do_Abi_GetIndexedProperty_1(IntPtr thisPtr, IntPtr nam if (!RuntimeFeature.IsDynamicCodeCompiled) { throw new NotSupportedException( - $"ICustomProperty support used by XAML binding for '{target.GetType()}' requires the type to marked with 'WinRT.GeneratedBindableCustomPropertyAttribute'. " + + $"ICustomProperty support used by XAML binding for type '{target.GetType()}' (indexer with parameter of type '{_type}') requires the type to marked with 'WinRT.GeneratedBindableCustomPropertyAttribute'. " + $"If this is a built-in type or a type that can't be marked, a wrapper type should be used around it that is marked to enable this support."); } + // Intentionally declare this here to avoid marshalling this value entirely on AOT, + // as it's not needed. The indexer property is just matched by the parameter type. + string _name = MarshalString.FromAbi(name); + GetCustomPropertyForJit(target, _name, _type, result); [UnconditionalSuppressMessage("Trimming", "IL2075", Justification = "Fallback method for JIT environments that is not trim-safe by design.")] [MethodImpl(MethodImplOptions.NoInlining)] static void GetCustomPropertyForJit(object target, string name, Type type, IntPtr* result) { - global::Microsoft.UI.Xaml.Data.ICustomProperty __result = default; - - PropertyInfo propertyInfo = target.GetType().GetProperty( - name, - BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public, - null, // default binder - null, // ignore return type - new Type[] { type }, // indexed parameter type - null // ignore type modifier + global::Microsoft.UI.Xaml.Data.ICustomProperty __result = default; + + PropertyInfo propertyInfo = target.GetType().GetProperty( + name, + BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public, + null, // default binder + null, // ignore return type + new Type[] { type }, // indexed parameter type + null // ignore type modifier ); if (propertyInfo is not null) @@ -489,48 +493,48 @@ static void GetCustomPropertyForJit(object target, string name, Type type, IntPt *result = MarshalInterface.FromManaged(__result); } - } - catch (Exception __exception__) - { - global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); - return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); - } - return 0; - } - - [UnmanagedCallersOnly] - private static unsafe int Do_Abi_GetStringRepresentation_2(IntPtr thisPtr, IntPtr* result) - { - string __result = default; - try - { - __result = global::WinRT.ComWrappersSupport.FindObject(thisPtr).ToString(); - *result = MarshalString.FromManaged(__result); - } - catch (Exception __exception__) - { - global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); - return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); - } - return 0; - } - - [UnmanagedCallersOnly] - private static unsafe int Do_Abi_get_Type_3(IntPtr thisPtr, global::ABI.System.Type* value) - { - global::System.Type __value = default; - try - { - __value = global::WinRT.ComWrappersSupport.FindObject(thisPtr).GetType(); - *value = global::ABI.System.Type.FromManaged(__value); - - } - catch (Exception __exception__) - { - global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); - return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); - } - return 0; - } - } -} + } + catch (Exception __exception__) + { + global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); + return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); + } + return 0; + } + + [UnmanagedCallersOnly] + private static unsafe int Do_Abi_GetStringRepresentation_2(IntPtr thisPtr, IntPtr* result) + { + string __result = default; + try + { + __result = global::WinRT.ComWrappersSupport.FindObject(thisPtr).ToString(); + *result = MarshalString.FromManaged(__result); + } + catch (Exception __exception__) + { + global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); + return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); + } + return 0; + } + + [UnmanagedCallersOnly] + private static unsafe int Do_Abi_get_Type_3(IntPtr thisPtr, global::ABI.System.Type* value) + { + global::System.Type __value = default; + try + { + __value = global::WinRT.ComWrappersSupport.FindObject(thisPtr).GetType(); + *value = global::ABI.System.Type.FromManaged(__value); + + } + catch (Exception __exception__) + { + global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); + return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); + } + return 0; + } + } +}