From d14359289cace87707769119a01d038de9d9678f Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 30 Jan 2024 17:45:19 +0100 Subject: [PATCH 01/20] Add 'EnableDefaultCustomTypeMappings' switch --- nuget/Microsoft.Windows.CsWinRT.targets | 8 +++++++- .../Configuration/FeatureSwitches.cs | 19 +++++++++++++++++++ .../Configuration/ILLink.Substitutions.xml | 4 ++++ src/WinRT.Runtime/Projections.cs | 7 +++++++ 4 files changed, 37 insertions(+), 1 deletion(-) diff --git a/nuget/Microsoft.Windows.CsWinRT.targets b/nuget/Microsoft.Windows.CsWinRT.targets index 771534792..2a264e61d 100644 --- a/nuget/Microsoft.Windows.CsWinRT.targets +++ b/nuget/Microsoft.Windows.CsWinRT.targets @@ -234,10 +234,11 @@ $(CsWinRTInternalProjection) - + true false + true + diff --git a/src/WinRT.Runtime/Configuration/FeatureSwitches.cs b/src/WinRT.Runtime/Configuration/FeatureSwitches.cs index b0e547b85..100c9d3d3 100644 --- a/src/WinRT.Runtime/Configuration/FeatureSwitches.cs +++ b/src/WinRT.Runtime/Configuration/FeatureSwitches.cs @@ -31,6 +31,11 @@ internal static class FeatureSwitches /// private const string UseExceptionResourceKeysPropertyName = "CSWINRT_USE_EXCEPTION_RESOURCE_KEYS"; + /// + /// The configuration property name for . + /// + private const string EnableDefaultCustomTypeMappingsPropertyName = "CSWINRT_ENABLE_DEFAULT_CUSTOM_TYPE_MAPPINGS"; + /// /// The backing field for . /// @@ -41,6 +46,11 @@ internal static class FeatureSwitches /// private static int _useExceptionResourceKeys; + /// + /// The backing field for . + /// + private static int _enableDefaultCustomTypeMappings; + /// /// Gets a value indicating whether or not projections support for dynamic objects is enabled (defaults to ). /// @@ -59,6 +69,15 @@ public static bool UseExceptionResourceKeys get => GetConfigurationValue(UseExceptionResourceKeysPropertyName, ref _useExceptionResourceKeys); } + /// + /// Gets a value indicating whether or not should initialize all default type mappings automatically (defaults to ). + /// + public static bool EnableDefaultCustomTypeMappings + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => GetConfigurationValue(EnableDefaultCustomTypeMappingsPropertyName, ref _enableDefaultCustomTypeMappings); + } + /// /// Gets a configuration value for a specified property. /// diff --git a/src/WinRT.Runtime/Configuration/ILLink.Substitutions.xml b/src/WinRT.Runtime/Configuration/ILLink.Substitutions.xml index 6697c6f3f..556edc6a5 100644 --- a/src/WinRT.Runtime/Configuration/ILLink.Substitutions.xml +++ b/src/WinRT.Runtime/Configuration/ILLink.Substitutions.xml @@ -9,6 +9,10 @@ + + + + diff --git a/src/WinRT.Runtime/Projections.cs b/src/WinRT.Runtime/Projections.cs index 86ec108ef..7d7cbd7b9 100644 --- a/src/WinRT.Runtime/Projections.cs +++ b/src/WinRT.Runtime/Projections.cs @@ -37,6 +37,13 @@ static class Projections static Projections() { + // If default mappings are disabled, we avoid rooting everything by default. + // Developers will have to optionally opt-in into individual mappings later. + if (!FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + // This should be in sync with cswinrt/helpers.h and the reverse mapping from WinRT.SourceGenerator/WinRTTypeWriter.cs. RegisterCustomAbiTypeMappingNoLock(typeof(bool), typeof(ABI.System.Boolean), "Boolean"); RegisterCustomAbiTypeMappingNoLock(typeof(char), typeof(ABI.System.Char), "Char"); From 6ac1626f497c4b8e098cd001b690d88ca6d3b6a3 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 31 Jan 2024 00:54:47 +0100 Subject: [PATCH 02/20] Always register mappings for 'bool', 'char' --- src/WinRT.Runtime/Projections.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/WinRT.Runtime/Projections.cs b/src/WinRT.Runtime/Projections.cs index 7d7cbd7b9..04635322e 100644 --- a/src/WinRT.Runtime/Projections.cs +++ b/src/WinRT.Runtime/Projections.cs @@ -37,6 +37,11 @@ static class Projections static Projections() { + // We always register mappings for 'bool' and 'char' as they're primitive types. + // They're also very cheap anyway and commonly used, so this keeps things simpler. + RegisterCustomAbiTypeMappingNoLock(typeof(bool), typeof(ABI.System.Boolean), "Boolean"); + RegisterCustomAbiTypeMappingNoLock(typeof(char), typeof(ABI.System.Char), "Char"); + // If default mappings are disabled, we avoid rooting everything by default. // Developers will have to optionally opt-in into individual mappings later. if (!FeatureSwitches.EnableDefaultCustomTypeMappings) @@ -44,9 +49,7 @@ static Projections() return; } - // This should be in sync with cswinrt/helpers.h and the reverse mapping from WinRT.SourceGenerator/WinRTTypeWriter.cs. - RegisterCustomAbiTypeMappingNoLock(typeof(bool), typeof(ABI.System.Boolean), "Boolean"); - RegisterCustomAbiTypeMappingNoLock(typeof(char), typeof(ABI.System.Char), "Char"); + // This should be in sync with cswinrt/helpers.h and the reverse mapping from WinRT.SourceGenerator/WinRTTypeWriter.cs. RegisterCustomAbiTypeMappingNoLock(typeof(EventRegistrationToken), typeof(ABI.WinRT.EventRegistrationToken), "Windows.Foundation.EventRegistrationToken"); RegisterCustomAbiTypeMappingNoLock(typeof(Nullable<>), typeof(ABI.System.Nullable<>), "Windows.Foundation.IReference`1"); From 446b773613e17dc58485604146734cec8d258124 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 31 Jan 2024 02:20:02 +0100 Subject: [PATCH 03/20] Add public register methods for custom mappings --- .../Projections.CustomTypeMappings.cs | 331 ++++++++++++++++++ src/WinRT.Runtime/Projections.cs | 6 +- 2 files changed, 334 insertions(+), 3 deletions(-) create mode 100644 src/WinRT.Runtime/Projections.CustomTypeMappings.cs diff --git a/src/WinRT.Runtime/Projections.CustomTypeMappings.cs b/src/WinRT.Runtime/Projections.CustomTypeMappings.cs new file mode 100644 index 000000000..9832c2e7f --- /dev/null +++ b/src/WinRT.Runtime/Projections.CustomTypeMappings.cs @@ -0,0 +1,331 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.Specialized; +using System.ComponentModel; +using System.Numerics; +using System.Windows.Input; + +namespace WinRT +{ + partial class Projections + { + /// Registers the custom ABI type mapping for the type. + public static void RegisterEventRegistrationTokenMapping() => RegisterCustomAbiTypeMapping( + typeof(EventRegistrationToken), + typeof(ABI.WinRT.EventRegistrationToken), + "Windows.Foundation.EventRegistrationToken"); + + /// Registers the custom ABI type mapping for the type. + public static void RegisterNullableOpenGenericMapping() => RegisterCustomAbiTypeMapping( + typeof(Nullable<>), + typeof(ABI.System.Nullable<>), + "Windows.Foundation.IReference`1"); + + /// Registers the custom ABI type mapping for the of type. + public static void RegisterNullableIntMapping() => RegisterCustomAbiTypeMapping( + typeof(int?), + typeof(ABI.System.Nullable_int), + "Windows.Foundation.IReference`1"); + + /// Registers the custom ABI type mapping for the of type. + public static void RegisterNullableByteMapping() => RegisterCustomAbiTypeMapping( + typeof(byte?), + typeof(ABI.System.Nullable_byte), + "Windows.Foundation.IReference`1"); + + /// Registers the custom ABI type mapping for the of type. + public static void RegisterNullableSByteMapping() => RegisterCustomAbiTypeMapping( + typeof(sbyte?), + typeof(ABI.System.Nullable_sbyte), + "Windows.Foundation.IReference`1"); + + /// Registers the custom ABI type mapping for the of type. + public static void RegisterNullableShortMapping() => RegisterCustomAbiTypeMapping( + typeof(short?), + typeof(ABI.System.Nullable_short), + "Windows.Foundation.IReference`1"); + + /// Registers the custom ABI type mapping for the of type. + public static void RegisterNullableUShortMapping() => RegisterCustomAbiTypeMapping( + typeof(ushort?), + typeof(ABI.System.Nullable_ushort), + "Windows.Foundation.IReference`1"); + + /// Registers the custom ABI type mapping for the of type. + public static void RegisterNullableUIntMapping() => RegisterCustomAbiTypeMapping( + typeof(uint?), + typeof(ABI.System.Nullable_uint), + "Windows.Foundation.IReference`1"); + + /// Registers the custom ABI type mapping for the of type. + public static void RegisterNullableLongMapping() => RegisterCustomAbiTypeMapping( + typeof(long?), + typeof(ABI.System.Nullable_long), + "Windows.Foundation.IReference`1"); + + /// Registers the custom ABI type mapping for the of type. + public static void RegisterNullableULongMapping() => RegisterCustomAbiTypeMapping( + typeof(ulong?), + typeof(ABI.System.Nullable_ulong), + "Windows.Foundation.IReference`1"); + + /// Registers the custom ABI type mapping for the of type. + public static void RegisterNullableFloatMapping() => RegisterCustomAbiTypeMapping( + typeof(float?), + typeof(ABI.System.Nullable_float), + "Windows.Foundation.IReference`1"); + + /// Registers the custom ABI type mapping for the of type. + public static void RegisterNullableDoubleMapping() => RegisterCustomAbiTypeMapping( + typeof(double?), + typeof(ABI.System.Nullable_double), + "Windows.Foundation.IReference`1"); + + /// Registers the custom ABI type mapping for the of type. + public static void RegisterNullableCharMapping() => RegisterCustomAbiTypeMapping( + typeof(char?), + typeof(ABI.System.Nullable_char), + "Windows.Foundation.IReference`1"); + + /// Registers the custom ABI type mapping for the of type. + public static void RegisterNullableBoolMapping() => RegisterCustomAbiTypeMapping( + typeof(bool?), + typeof(ABI.System.Nullable_bool), + "Windows.Foundation.IReference`1"); + + /// Registers the custom ABI type mapping for the of type. + public static void RegisterNullableGuidMapping() => RegisterCustomAbiTypeMapping( + typeof(Guid?), + typeof(ABI.System.Nullable_guid), + "Windows.Foundation.IReference`1"); + + /// Registers the custom ABI type mapping for the of type. + public static void RegisterNullableDateTimeOffsetMapping() => RegisterCustomAbiTypeMapping( + typeof(DateTimeOffset?), + typeof(ABI.System.Nullable_DateTimeOffset), + "Windows.Foundation.IReference`1"); + + /// Registers the custom ABI type mapping for the of type. + public static void RegisterNullableTimeSpanMapping() => RegisterCustomAbiTypeMapping( + typeof(TimeSpan?), + typeof(ABI.System.Nullable_TimeSpan), + "Windows.Foundation.IReference`1"); + + /// Registers the custom ABI type mapping for the type. + public static void RegisterDateTimeOffsetMapping() => RegisterCustomAbiTypeMapping( + typeof(DateTimeOffset), + typeof(ABI.System.DateTimeOffset), + "Windows.Foundation.DateTime"); + + /// Registers the custom ABI type mapping for the type. + public static void RegisterExceptionMapping() => RegisterCustomAbiTypeMapping( + typeof(Exception), + typeof(ABI.System.Exception), + "Windows.Foundation.HResult"); + + /// Registers the custom ABI type mapping for the type. + public static void RegisterTimeSpanMapping() => RegisterCustomAbiTypeMapping( + typeof(TimeSpan), + typeof(ABI.System.TimeSpan), + "Windows.Foundation.TimeSpan"); + + /// Registers the custom ABI type mapping for the type. + public static void RegisterUriMapping() => RegisterCustomAbiTypeMapping( + typeof(Uri), + typeof(ABI.System.Uri), + "Windows.Foundation.Uri", isRuntimeClass: true); + + /// Registers the custom ABI type mapping for the type. + public static void RegisterDataErrorsChangedEventArgsMapping() => RegisterCustomAbiTypeMapping( + typeof(DataErrorsChangedEventArgs), + typeof(ABI.System.ComponentModel.DataErrorsChangedEventArgs), + "Microsoft.UI.Xaml.Data.DataErrorsChangedEventArgs", isRuntimeClass: true); + + /// Registers the custom ABI type mapping for the type. + public static void RegisterPropertyChangedEventArgsMapping() => RegisterCustomAbiTypeMapping( + typeof(PropertyChangedEventArgs), + typeof(ABI.System.ComponentModel.PropertyChangedEventArgs), + "Microsoft.UI.Xaml.Data.PropertyChangedEventArgs", isRuntimeClass: true); + + /// Registers the custom ABI type mapping for the type. + public static void RegisterPropertyChangedEventHandlerMapping() => RegisterCustomAbiTypeMapping( + typeof(PropertyChangedEventHandler), + typeof(ABI.System.ComponentModel.PropertyChangedEventHandler), + "Microsoft.UI.Xaml.Data.PropertyChangedEventHandler"); + + /// Registers the custom ABI type mapping for the type. + public static void RegisterINotifyDataErrorInfoMapping() => RegisterCustomAbiTypeMapping( + typeof(INotifyDataErrorInfo), + typeof(ABI.System.ComponentModel.INotifyDataErrorInfo), + "Microsoft.UI.Xaml.Data.INotifyDataErrorInfo"); + + /// Registers the custom ABI type mapping for the type. + public static void RegisterINotifyPropertyChangedMapping() => RegisterCustomAbiTypeMapping( + typeof(INotifyPropertyChanged), + typeof(ABI.System.ComponentModel.INotifyPropertyChanged), + "Microsoft.UI.Xaml.Data.INotifyPropertyChanged"); + + /// Registers the custom ABI type mapping for the type. + public static void RegisterICommandMapping() => RegisterCustomAbiTypeMapping( + typeof(ICommand), + typeof(ABI.System.Windows.Input.ICommand), + "Microsoft.UI.Xaml.Interop.ICommand"); + + /// Registers the custom ABI type mapping for the type. + public static void RegisterIServiceProviderMapping() => RegisterCustomAbiTypeMapping( + typeof(IServiceProvider), + typeof(ABI.System.IServiceProvider), + "Microsoft.UI.Xaml.IXamlServiceProvider"); + + /// Registers the custom ABI type mapping for the type. + public static void RegisterEventHandlerOpenGenericMapping() => RegisterCustomAbiTypeMapping( + typeof(EventHandler<>), + typeof(ABI.System.EventHandler<>), + "Windows.Foundation.EventHandler`1"); + + /// Registers the custom ABI type mapping for the type. + public static void RegisterKeyValuePairOpenGenericMapping() => RegisterCustomAbiTypeMapping( + typeof(KeyValuePair<,>), + typeof(ABI.System.Collections.Generic.KeyValuePair<,>), + "Windows.Foundation.Collections.IKeyValuePair`2"); + + /// Registers the custom ABI type mapping for the type. + public static void RegisterIEnumerableOpenGenericMapping() => RegisterCustomAbiTypeMapping( + typeof(IEnumerable<>), + typeof(ABI.System.Collections.Generic.IEnumerable<>), + "Windows.Foundation.Collections.IIterable`1"); + + /// Registers the custom ABI type mapping for the type. + public static void RegisterIEnumeratorOpenGenericMapping() => RegisterCustomAbiTypeMapping( + typeof(IEnumerator<>), + typeof(ABI.System.Collections.Generic.IEnumerator<>), + "Windows.Foundation.Collections.IIterator`1"); + + /// Registers the custom ABI type mapping for the type. + public static void RegisterIListOpenGenericMapping() => RegisterCustomAbiTypeMapping( + typeof(IList<>), + typeof(ABI.System.Collections.Generic.IList<>), + "Windows.Foundation.Collections.IVector`1"); + + /// Registers the custom ABI type mapping for the type. + public static void RegisterIReadOnlyListOpenGenericMapping() => RegisterCustomAbiTypeMapping( + typeof(IReadOnlyList<>), + typeof(ABI.System.Collections.Generic.IReadOnlyList<>), + "Windows.Foundation.Collections.IVectorView`1"); + + /// Registers the custom ABI type mapping for the type. + public static void RegisterIDictionaryOpenGenericMapping() => RegisterCustomAbiTypeMapping( + typeof(IDictionary<,>), + typeof(ABI.System.Collections.Generic.IDictionary<,>), + "Windows.Foundation.Collections.IMap`2"); + + /// Registers the custom ABI type mapping for the type. + public static void RegisterIReadOnlyDictionaryOpenGenericMapping() => RegisterCustomAbiTypeMapping( + typeof(IReadOnlyDictionary<,>), + typeof(ABI.System.Collections.Generic.IReadOnlyDictionary<,>), + "Windows.Foundation.Collections.IMapView`2"); + + /// Registers the custom ABI type mapping for the type. + public static void RegisterIDisposableMapping() => RegisterCustomAbiTypeMapping( + typeof(IDisposable), + typeof(ABI.System.IDisposable), + "Windows.Foundation.IClosable"); + + /// Registers the custom ABI type mapping for the type. + public static void RegisterIEnumerableMapping() => RegisterCustomAbiTypeMapping( + typeof(IEnumerable), + typeof(ABI.System.Collections.IEnumerable), + "Microsoft.UI.Xaml.Interop.IBindableIterable"); + + /// Registers the custom ABI type mapping for the type. + public static void RegisterIListMapping() => RegisterCustomAbiTypeMapping( + typeof(IList), + typeof(ABI.System.Collections.IList), + "Microsoft.UI.Xaml.Interop.IBindableVector"); + + /// Registers the custom ABI type mapping for the type. + public static void RegisterINotifyCollectionChangedMapping() => RegisterCustomAbiTypeMapping( + typeof(INotifyCollectionChanged), + typeof(ABI.System.Collections.Specialized.INotifyCollectionChanged), + "Microsoft.UI.Xaml.Interop.INotifyCollectionChanged"); + + /// Registers the custom ABI type mapping for the type. + public static void RegisterNotifyCollectionChangedActionMapping() => RegisterCustomAbiTypeMapping( + typeof(NotifyCollectionChangedAction), + typeof(ABI.System.Collections.Specialized.NotifyCollectionChangedAction), + "Microsoft.UI.Xaml.Interop.NotifyCollectionChangedAction"); + + /// Registers the custom ABI type mapping for the type. + public static void RegisterNotifyCollectionChangedEventArgsMapping() => RegisterCustomAbiTypeMapping( + typeof(NotifyCollectionChangedEventArgs), + typeof(ABI.System.Collections.Specialized.NotifyCollectionChangedEventArgs), + "Microsoft.UI.Xaml.Interop.NotifyCollectionChangedEventArgs", isRuntimeClass: true); + + /// Registers the custom ABI type mapping for the type. + public static void RegisterNotifyCollectionChangedEventHandlerMapping() => RegisterCustomAbiTypeMapping( + typeof(NotifyCollectionChangedEventHandler), + typeof(ABI.System.Collections.Specialized.NotifyCollectionChangedEventHandler), + "Microsoft.UI.Xaml.Interop.NotifyCollectionChangedEventHandler"); + + /// Registers the custom ABI type mapping for the type. + public static void RegisterMatrix3x2Mapping() => RegisterCustomAbiTypeMapping( + typeof(Matrix3x2), + typeof(ABI.System.Numerics.Matrix3x2), + "Windows.Foundation.Numerics.Matrix3x2"); + + /// Registers the custom ABI type mapping for the type. + public static void RegisterMatrix4x4Mapping() => RegisterCustomAbiTypeMapping( + typeof(Matrix4x4), + typeof(ABI.System.Numerics.Matrix4x4), + "Windows.Foundation.Numerics.Matrix4x4"); + + /// Registers the custom ABI type mapping for the type. + public static void RegisterPlaneMapping() => RegisterCustomAbiTypeMapping( + typeof(Plane), + typeof(ABI.System.Numerics.Plane), + "Windows.Foundation.Numerics.Plane"); + + /// Registers the custom ABI type mapping for the type. + public static void RegisterQuaternionMapping() => RegisterCustomAbiTypeMapping( + typeof(Quaternion), + typeof(ABI.System.Numerics.Quaternion), + "Windows.Foundation.Numerics.Quaternion"); + + /// Registers the custom ABI type mapping for the type. + public static void RegisterVector2Mapping() => RegisterCustomAbiTypeMapping( + typeof(Vector2), + typeof(ABI.System.Numerics.Vector2), + "Windows.Foundation.Numerics.Vector2"); + + /// Registers the custom ABI type mapping for the type. + public static void RegisterVector3Mapping() => RegisterCustomAbiTypeMapping( + typeof(Vector3), + typeof(ABI.System.Numerics.Vector3), + "Windows.Foundation.Numerics.Vector3"); + + /// Registers the custom ABI type mapping for the type. + public static void RegisterVector4Mapping() => RegisterCustomAbiTypeMapping( + typeof(Vector4), + typeof(ABI.System.Numerics.Vector4), + "Windows.Foundation.Numerics.Vector4"); + + /// Registers the custom ABI type mapping for the type. + public static void RegisterEventHandlerMapping() + { + rwlock.EnterWriteLock(); + + try + { + RegisterCustomAbiTypeMappingNoLock(typeof(EventHandler), typeof(ABI.System.EventHandler)); + } + finally + { + rwlock.ExitWriteLock(); + } + } + } +} \ No newline at end of file diff --git a/src/WinRT.Runtime/Projections.cs b/src/WinRT.Runtime/Projections.cs index 04635322e..38f67351d 100644 --- a/src/WinRT.Runtime/Projections.cs +++ b/src/WinRT.Runtime/Projections.cs @@ -24,7 +24,7 @@ namespace WinRT #else public #endif - static class Projections + static partial class Projections { private static readonly ReaderWriterLockSlim rwlock = new ReaderWriterLockSlim(); @@ -106,6 +106,8 @@ static Projections() RegisterCustomAbiTypeMappingNoLock(typeof(Vector3), typeof(ABI.System.Numerics.Vector3), "Windows.Foundation.Numerics.Vector3"); RegisterCustomAbiTypeMappingNoLock(typeof(Vector4), typeof(ABI.System.Numerics.Vector4), "Windows.Foundation.Numerics.Vector4"); + RegisterCustomAbiTypeMappingNoLock(typeof(EventHandler), typeof(ABI.System.EventHandler)); + // TODO: Ideally we should not need these CustomTypeToHelperTypeMappings.Add(typeof(IMap<,>), typeof(ABI.System.Collections.Generic.IDictionary<,>)); CustomTypeToHelperTypeMappings.Add(typeof(IVector<>), typeof(ABI.System.Collections.Generic.IList<>)); @@ -118,8 +120,6 @@ static Projections() CustomTypeToHelperTypeMappings.Add(typeof(IReadOnlyCollection<>), typeof(ABI.System.Collections.Generic.IReadOnlyCollection<>)); CustomTypeToHelperTypeMappings.Add(typeof(ICollection), typeof(ABI.System.Collections.ICollection)); #endif - RegisterCustomAbiTypeMappingNoLock(typeof(EventHandler), typeof(ABI.System.EventHandler)); - CustomTypeToAbiTypeNameMappings.Add(typeof(System.Type), "Windows.UI.Xaml.Interop.TypeName"); } From 7dde05d9fce4d82fc19d9b593e60ef28bda02079 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 31 Jan 2024 02:21:04 +0100 Subject: [PATCH 04/20] Always register type mapping for 'Type' --- src/WinRT.Runtime/Projections.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/WinRT.Runtime/Projections.cs b/src/WinRT.Runtime/Projections.cs index 38f67351d..bb669da91 100644 --- a/src/WinRT.Runtime/Projections.cs +++ b/src/WinRT.Runtime/Projections.cs @@ -42,6 +42,9 @@ static Projections() RegisterCustomAbiTypeMappingNoLock(typeof(bool), typeof(ABI.System.Boolean), "Boolean"); RegisterCustomAbiTypeMappingNoLock(typeof(char), typeof(ABI.System.Char), "Char"); + // Also always register Type, since it's "free" (no associated ABI type to root) + CustomTypeToAbiTypeNameMappings.Add(typeof(System.Type), "Windows.UI.Xaml.Interop.TypeName"); + // If default mappings are disabled, we avoid rooting everything by default. // Developers will have to optionally opt-in into individual mappings later. if (!FeatureSwitches.EnableDefaultCustomTypeMappings) @@ -120,7 +123,6 @@ static Projections() CustomTypeToHelperTypeMappings.Add(typeof(IReadOnlyCollection<>), typeof(ABI.System.Collections.Generic.IReadOnlyCollection<>)); CustomTypeToHelperTypeMappings.Add(typeof(ICollection), typeof(ABI.System.Collections.ICollection)); #endif - CustomTypeToAbiTypeNameMappings.Add(typeof(System.Type), "Windows.UI.Xaml.Interop.TypeName"); } public static void RegisterCustomAbiTypeMapping( From 10b44e8d43027140bed0e0a6d91dfcba82b9701a Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 31 Jan 2024 02:22:08 +0100 Subject: [PATCH 05/20] Minor code style tweaks --- src/WinRT.Runtime/Projections.cs | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/WinRT.Runtime/Projections.cs b/src/WinRT.Runtime/Projections.cs index bb669da91..8210b6fbb 100644 --- a/src/WinRT.Runtime/Projections.cs +++ b/src/WinRT.Runtime/Projections.cs @@ -56,21 +56,21 @@ static Projections() RegisterCustomAbiTypeMappingNoLock(typeof(EventRegistrationToken), typeof(ABI.WinRT.EventRegistrationToken), "Windows.Foundation.EventRegistrationToken"); RegisterCustomAbiTypeMappingNoLock(typeof(Nullable<>), typeof(ABI.System.Nullable<>), "Windows.Foundation.IReference`1"); - RegisterCustomAbiTypeMappingNoLock(typeof(Nullable), typeof(ABI.System.Nullable_int), "Windows.Foundation.IReference`1"); - RegisterCustomAbiTypeMappingNoLock(typeof(Nullable), typeof(ABI.System.Nullable_byte), "Windows.Foundation.IReference`1"); - RegisterCustomAbiTypeMappingNoLock(typeof(Nullable), typeof(ABI.System.Nullable_sbyte), "Windows.Foundation.IReference`1"); - RegisterCustomAbiTypeMappingNoLock(typeof(Nullable), typeof(ABI.System.Nullable_short), "Windows.Foundation.IReference`1"); - RegisterCustomAbiTypeMappingNoLock(typeof(Nullable), typeof(ABI.System.Nullable_ushort), "Windows.Foundation.IReference`1"); - RegisterCustomAbiTypeMappingNoLock(typeof(Nullable), typeof(ABI.System.Nullable_uint), "Windows.Foundation.IReference`1"); - RegisterCustomAbiTypeMappingNoLock(typeof(Nullable), typeof(ABI.System.Nullable_long), "Windows.Foundation.IReference`1"); - RegisterCustomAbiTypeMappingNoLock(typeof(Nullable), typeof(ABI.System.Nullable_ulong), "Windows.Foundation.IReference`1"); - RegisterCustomAbiTypeMappingNoLock(typeof(Nullable), typeof(ABI.System.Nullable_float), "Windows.Foundation.IReference`1"); - RegisterCustomAbiTypeMappingNoLock(typeof(Nullable), typeof(ABI.System.Nullable_double), "Windows.Foundation.IReference`1"); - RegisterCustomAbiTypeMappingNoLock(typeof(Nullable), typeof(ABI.System.Nullable_char), "Windows.Foundation.IReference`1"); - RegisterCustomAbiTypeMappingNoLock(typeof(Nullable), typeof(ABI.System.Nullable_bool), "Windows.Foundation.IReference`1"); - RegisterCustomAbiTypeMappingNoLock(typeof(Nullable), typeof(ABI.System.Nullable_guid), "Windows.Foundation.IReference`1"); - RegisterCustomAbiTypeMappingNoLock(typeof(Nullable), typeof(ABI.System.Nullable_DateTimeOffset), "Windows.Foundation.IReference`1"); - RegisterCustomAbiTypeMappingNoLock(typeof(Nullable), typeof(ABI.System.Nullable_TimeSpan), "Windows.Foundation.IReference`1"); + RegisterCustomAbiTypeMappingNoLock(typeof(int?), typeof(ABI.System.Nullable_int), "Windows.Foundation.IReference`1"); + RegisterCustomAbiTypeMappingNoLock(typeof(byte?), typeof(ABI.System.Nullable_byte), "Windows.Foundation.IReference`1"); + RegisterCustomAbiTypeMappingNoLock(typeof(sbyte?), typeof(ABI.System.Nullable_sbyte), "Windows.Foundation.IReference`1"); + RegisterCustomAbiTypeMappingNoLock(typeof(short?), typeof(ABI.System.Nullable_short), "Windows.Foundation.IReference`1"); + RegisterCustomAbiTypeMappingNoLock(typeof(ushort?), typeof(ABI.System.Nullable_ushort), "Windows.Foundation.IReference`1"); + RegisterCustomAbiTypeMappingNoLock(typeof(uint?), typeof(ABI.System.Nullable_uint), "Windows.Foundation.IReference`1"); + RegisterCustomAbiTypeMappingNoLock(typeof(long?), typeof(ABI.System.Nullable_long), "Windows.Foundation.IReference`1"); + RegisterCustomAbiTypeMappingNoLock(typeof(ulong?), typeof(ABI.System.Nullable_ulong), "Windows.Foundation.IReference`1"); + RegisterCustomAbiTypeMappingNoLock(typeof(float?), typeof(ABI.System.Nullable_float), "Windows.Foundation.IReference`1"); + RegisterCustomAbiTypeMappingNoLock(typeof(double?), typeof(ABI.System.Nullable_double), "Windows.Foundation.IReference`1"); + RegisterCustomAbiTypeMappingNoLock(typeof(char?), typeof(ABI.System.Nullable_char), "Windows.Foundation.IReference`1"); + RegisterCustomAbiTypeMappingNoLock(typeof(bool?), typeof(ABI.System.Nullable_bool), "Windows.Foundation.IReference`1"); + RegisterCustomAbiTypeMappingNoLock(typeof(Guid?), typeof(ABI.System.Nullable_guid), "Windows.Foundation.IReference`1"); + RegisterCustomAbiTypeMappingNoLock(typeof(DateTimeOffset?), typeof(ABI.System.Nullable_DateTimeOffset), "Windows.Foundation.IReference`1"); + RegisterCustomAbiTypeMappingNoLock(typeof(TimeSpan?), typeof(ABI.System.Nullable_TimeSpan), "Windows.Foundation.IReference`1"); RegisterCustomAbiTypeMappingNoLock(typeof(DateTimeOffset), typeof(ABI.System.DateTimeOffset), "Windows.Foundation.DateTime"); RegisterCustomAbiTypeMappingNoLock(typeof(Exception), typeof(ABI.System.Exception), "Windows.Foundation.HResult"); From 1bdb4c64fd5af109ec19c63db2fb83a0efdb0153 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 31 Jan 2024 02:25:10 +0100 Subject: [PATCH 06/20] Make RegisterCustomAbiTypeMapping private --- src/WinRT.Runtime/ApiCompatBaseline.txt | 3 ++- src/WinRT.Runtime/Projections.cs | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/WinRT.Runtime/ApiCompatBaseline.txt b/src/WinRT.Runtime/ApiCompatBaseline.txt index e73eb07dd..d9a3c2182 100644 --- a/src/WinRT.Runtime/ApiCompatBaseline.txt +++ b/src/WinRT.Runtime/ApiCompatBaseline.txt @@ -15,4 +15,5 @@ CannotMakeMemberNonVirtual : Member 'public System.Int32 WinRT.IObjectReference. MembersMustExist : Member 'protected System.Boolean System.Boolean WinRT.IObjectReference.disposed' does not exist in the implementation but it does exist in the contract. MembersMustExist : Member 'protected void WinRT.IObjectReference.Dispose(System.Boolean)' does not exist in the implementation but it does exist in the contract. CannotChangeAttribute : Attribute 'System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute' on 'ABI.System.Type.FromAbi(ABI.System.Type)' changed from '[UnconditionalSuppressMessageAttribute("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification="Any types which are trimmed are not used by managed user code and there is fallback logic to handle that.")]' in the contract to '[UnconditionalSuppressMessageAttribute("ReflectionAnalysis", "IL2057", Justification="Any types which are trimmed are not used by managed user code and there is fallback logic to handle that.")]' in the implementation. -Total Issues: 16 +MembersMustExist : Member 'public void WinRT.Projections.RegisterCustomAbiTypeMapping(System.Type, System.Type, System.String, System.Boolean)' does not exist in the implementation but it does exist in the contract. +Total Issues: 17 diff --git a/src/WinRT.Runtime/Projections.cs b/src/WinRT.Runtime/Projections.cs index 8210b6fbb..bf3e96b26 100644 --- a/src/WinRT.Runtime/Projections.cs +++ b/src/WinRT.Runtime/Projections.cs @@ -125,7 +125,7 @@ static Projections() #endif } - public static void RegisterCustomAbiTypeMapping( + private static void RegisterCustomAbiTypeMapping( Type publicType, #if NET [DynamicallyAccessedMembers( From e78c9fc7031e238ff9897fdfb7a615d4bd30a5c1 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 31 Jan 2024 02:34:30 +0100 Subject: [PATCH 07/20] Add public methods for custom helper type mappings --- .../Projections.CustomTypeMappings.cs | 42 +++++++++++++++ src/WinRT.Runtime/Projections.cs | 53 +++++++++++++++---- 2 files changed, 86 insertions(+), 9 deletions(-) diff --git a/src/WinRT.Runtime/Projections.CustomTypeMappings.cs b/src/WinRT.Runtime/Projections.CustomTypeMappings.cs index 9832c2e7f..4b88352b3 100644 --- a/src/WinRT.Runtime/Projections.CustomTypeMappings.cs +++ b/src/WinRT.Runtime/Projections.CustomTypeMappings.cs @@ -8,6 +8,8 @@ using System.ComponentModel; using System.Numerics; using System.Windows.Input; +using Microsoft.UI.Xaml.Interop; +using Windows.Foundation.Collections; namespace WinRT { @@ -313,6 +315,46 @@ public static void RegisterVector4Mapping() => RegisterCustomAbiTypeMapping( typeof(ABI.System.Numerics.Vector4), "Windows.Foundation.Numerics.Vector4"); + /// Registers the custom ABI type mapping for the type. + public static void RegisterIMapOpenGenericMapping() => RegisterCustomTypeToHelperTypeMapping( + typeof(IMap<,>), + typeof(ABI.System.Collections.Generic.IDictionary<,>)); + + /// Registers the custom ABI type mapping for the type. + public static void RegisterIVectorOpenGenericMapping() => RegisterCustomTypeToHelperTypeMapping( + typeof(IVector<>), + typeof(ABI.System.Collections.Generic.IList<>)); + + /// Registers the custom ABI type mapping for the type. + public static void RegisterIMapViewOpenGenericMapping() => RegisterCustomTypeToHelperTypeMapping( + typeof(IMapView<,>), + typeof(ABI.System.Collections.Generic.IReadOnlyDictionary<,>)); + + /// Registers the custom ABI type mapping for the type. + public static void RegisterIVectorViewOpenGenericMapping() => RegisterCustomTypeToHelperTypeMapping( + typeof(IVectorView<>), + typeof(ABI.System.Collections.Generic.IReadOnlyList<>)); + + /// Registers the custom ABI type mapping for the type. + public static void RegisterIBindableVectorMapping() => RegisterCustomTypeToHelperTypeMapping( + typeof(IBindableVector), + typeof(ABI.System.Collections.IList)); +#if NET + /// Registers the custom ABI type mapping for the type. + public static void RegisterICollectionOpenGenericMapping() => RegisterCustomTypeToHelperTypeMapping( + typeof(ICollection<>), + typeof(ABI.System.Collections.Generic.ICollection<>)); + + /// Registers the custom ABI type mapping for the type. + public static void RegisterIReadOnlyCollectionOpenGenericMapping() => RegisterCustomTypeToHelperTypeMapping( + typeof(IReadOnlyCollection<>), + typeof(ABI.System.Collections.Generic.IReadOnlyCollection<>)); + + /// Registers the custom ABI type mapping for the type. + public static void RegisterICollectionMapping() => RegisterCustomTypeToHelperTypeMapping( + typeof(ICollection), + typeof(ABI.System.Collections.ICollection)); +#endif /// Registers the custom ABI type mapping for the type. public static void RegisterEventHandlerMapping() { diff --git a/src/WinRT.Runtime/Projections.cs b/src/WinRT.Runtime/Projections.cs index bf3e96b26..12de30e1a 100644 --- a/src/WinRT.Runtime/Projections.cs +++ b/src/WinRT.Runtime/Projections.cs @@ -112,16 +112,16 @@ static Projections() RegisterCustomAbiTypeMappingNoLock(typeof(EventHandler), typeof(ABI.System.EventHandler)); // TODO: Ideally we should not need these - CustomTypeToHelperTypeMappings.Add(typeof(IMap<,>), typeof(ABI.System.Collections.Generic.IDictionary<,>)); - CustomTypeToHelperTypeMappings.Add(typeof(IVector<>), typeof(ABI.System.Collections.Generic.IList<>)); - CustomTypeToHelperTypeMappings.Add(typeof(IMapView<,>), typeof(ABI.System.Collections.Generic.IReadOnlyDictionary<,>)); - CustomTypeToHelperTypeMappings.Add(typeof(IVectorView<>), typeof(ABI.System.Collections.Generic.IReadOnlyList<>)); - CustomTypeToHelperTypeMappings.Add(typeof(Microsoft.UI.Xaml.Interop.IBindableVector), typeof(ABI.System.Collections.IList)); + RegisterCustomTypeToHelperTypeMappingNoLock(typeof(IMap<,>), typeof(ABI.System.Collections.Generic.IDictionary<,>)); + RegisterCustomTypeToHelperTypeMappingNoLock(typeof(IVector<>), typeof(ABI.System.Collections.Generic.IList<>)); + RegisterCustomTypeToHelperTypeMappingNoLock(typeof(IMapView<,>), typeof(ABI.System.Collections.Generic.IReadOnlyDictionary<,>)); + RegisterCustomTypeToHelperTypeMappingNoLock(typeof(IVectorView<>), typeof(ABI.System.Collections.Generic.IReadOnlyList<>)); + RegisterCustomTypeToHelperTypeMappingNoLock(typeof(Microsoft.UI.Xaml.Interop.IBindableVector), typeof(ABI.System.Collections.IList)); #if NET - CustomTypeToHelperTypeMappings.Add(typeof(ICollection<>), typeof(ABI.System.Collections.Generic.ICollection<>)); - CustomTypeToHelperTypeMappings.Add(typeof(IReadOnlyCollection<>), typeof(ABI.System.Collections.Generic.IReadOnlyCollection<>)); - CustomTypeToHelperTypeMappings.Add(typeof(ICollection), typeof(ABI.System.Collections.ICollection)); + RegisterCustomTypeToHelperTypeMappingNoLock(typeof(ICollection<>), typeof(ABI.System.Collections.Generic.ICollection<>)); + RegisterCustomTypeToHelperTypeMappingNoLock(typeof(IReadOnlyCollection<>), typeof(ABI.System.Collections.Generic.IReadOnlyCollection<>)); + RegisterCustomTypeToHelperTypeMappingNoLock(typeof(ICollection), typeof(ABI.System.Collections.ICollection)); #endif } @@ -148,6 +148,40 @@ private static void RegisterCustomAbiTypeMapping( } } + private static void RegisterCustomTypeToHelperTypeMapping( + Type publicType, +#if NET + [DynamicallyAccessedMembers( + DynamicallyAccessedMemberTypes.PublicMethods | + DynamicallyAccessedMemberTypes.PublicNestedTypes | + DynamicallyAccessedMemberTypes.PublicFields)] +#endif + Type helperType) + { + rwlock.EnterWriteLock(); + try + { + CustomTypeToHelperTypeMappings.Add(publicType, helperType); + } + finally + { + rwlock.ExitWriteLock(); + } + } + + private static void RegisterCustomTypeToHelperTypeMappingNoLock( + Type publicType, +#if NET + [DynamicallyAccessedMembers( + DynamicallyAccessedMemberTypes.PublicMethods | + DynamicallyAccessedMemberTypes.PublicNestedTypes | + DynamicallyAccessedMemberTypes.PublicFields)] +#endif + Type helperType) + { + CustomTypeToHelperTypeMappings.Add(publicType, helperType); + } + private static void RegisterCustomAbiTypeMappingNoLock( Type publicType, #if NET @@ -176,7 +210,8 @@ private static void RegisterCustomAbiTypeMappingNoLock( #if NET [DynamicallyAccessedMembers( DynamicallyAccessedMemberTypes.PublicMethods | - DynamicallyAccessedMemberTypes.PublicNestedTypes)] + DynamicallyAccessedMemberTypes.PublicNestedTypes | + DynamicallyAccessedMemberTypes.PublicFields)] #endif Type abiType) { From a104cc2e04d1c3915b227c1cf54584149302f36d Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 31 Jan 2024 02:36:21 +0100 Subject: [PATCH 08/20] Simplify type name --- src/WinRT.Runtime/Projections.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WinRT.Runtime/Projections.cs b/src/WinRT.Runtime/Projections.cs index 12de30e1a..02ab74ce2 100644 --- a/src/WinRT.Runtime/Projections.cs +++ b/src/WinRT.Runtime/Projections.cs @@ -43,7 +43,7 @@ static Projections() RegisterCustomAbiTypeMappingNoLock(typeof(char), typeof(ABI.System.Char), "Char"); // Also always register Type, since it's "free" (no associated ABI type to root) - CustomTypeToAbiTypeNameMappings.Add(typeof(System.Type), "Windows.UI.Xaml.Interop.TypeName"); + CustomTypeToAbiTypeNameMappings.Add(typeof(Type), "Windows.UI.Xaml.Interop.TypeName"); // If default mappings are disabled, we avoid rooting everything by default. // Developers will have to optionally opt-in into individual mappings later. From 14ce6e3d664727f0dc9997b56a750aba7281fc06 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 31 Jan 2024 15:01:01 +0100 Subject: [PATCH 09/20] Update MatchingRefApiCompatBaseline.txt --- .../MatchingRefApiCompatBaseline.txt | 61 ++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/src/WinRT.Runtime/MatchingRefApiCompatBaseline.txt b/src/WinRT.Runtime/MatchingRefApiCompatBaseline.txt index 025d85e37..1310b05b9 100644 --- a/src/WinRT.Runtime/MatchingRefApiCompatBaseline.txt +++ b/src/WinRT.Runtime/MatchingRefApiCompatBaseline.txt @@ -139,4 +139,63 @@ MembersMustExist : Member 'public WinRT.ObjectReference WinRT.ObjectReference TypesMustExist : Type 'WinRT.ActivationFactory' does not exist in the reference but it does exist in the implementation. CannotChangeAttribute : Attribute 'System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute' on 'ABI.System.Type.FromAbi(ABI.System.Type)' changed from '[UnconditionalSuppressMessageAttribute("ReflectionAnalysis", "IL2057", Justification="Any types which are trimmed are not used by managed user code and there is fallback logic to handle that.")]' in the implementation to '[UnconditionalSuppressMessageAttribute("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification="Any types which are trimmed are not used by managed user code and there is fallback logic to handle that.")]' in the reference. CannotRemoveAttribute : Attribute 'System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute' exists on 'WinRT.MarshalDelegate.FromAbi(System.IntPtr)' in the implementation but not the reference. -Total Issues: 140 +MembersMustExist : Member 'public void WinRT.Projections.RegisterDataErrorsChangedEventArgsMapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterDateTimeOffsetMapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterEventHandlerMapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterEventHandlerOpenGenericMapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterEventRegistrationTokenMapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterExceptionMapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterIBindableVectorMapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterICollectionMapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterICollectionOpenGenericMapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterICommandMapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterIDictionaryOpenGenericMapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterIDisposableMapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterIEnumerableMapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterIEnumerableOpenGenericMapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterIEnumeratorOpenGenericMapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterIListMapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterIListOpenGenericMapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterIMapOpenGenericMapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterIMapViewOpenGenericMapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterINotifyCollectionChangedMapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterINotifyDataErrorInfoMapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterINotifyPropertyChangedMapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterIReadOnlyCollectionOpenGenericMapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterIReadOnlyDictionaryOpenGenericMapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterIReadOnlyListOpenGenericMapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterIServiceProviderMapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterIVectorOpenGenericMapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterIVectorViewOpenGenericMapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterKeyValuePairOpenGenericMapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterMatrix3x2Mapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterMatrix4x4Mapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterNotifyCollectionChangedActionMapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterNotifyCollectionChangedEventArgsMapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterNotifyCollectionChangedEventHandlerMapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterNullableBoolMapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterNullableByteMapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterNullableCharMapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterNullableDateTimeOffsetMapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterNullableDoubleMapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterNullableFloatMapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterNullableGuidMapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterNullableIntMapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterNullableLongMapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterNullableOpenGenericMapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterNullableSByteMapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterNullableShortMapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterNullableTimeSpanMapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterNullableUIntMapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterNullableULongMapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterNullableUShortMapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterPlaneMapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterPropertyChangedEventArgsMapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterPropertyChangedEventHandlerMapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterQuaternionMapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterTimeSpanMapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterUriMapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterVector2Mapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterVector3Mapping()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public void WinRT.Projections.RegisterVector4Mapping()' does not exist in the reference but it does exist in the implementation. +Total Issues: 199 From cf964a26cb8fb0c42be99accc9f8ad37cc0105e3 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 31 Jan 2024 15:04:58 +0100 Subject: [PATCH 10/20] Add RegisterCustomAbiTypeMapping helper --- .../Projections.CustomTypeMappings.cs | 16 +++----------- src/WinRT.Runtime/Projections.cs | 21 +++++++++++++++++++ 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/WinRT.Runtime/Projections.CustomTypeMappings.cs b/src/WinRT.Runtime/Projections.CustomTypeMappings.cs index 4b88352b3..c6550acab 100644 --- a/src/WinRT.Runtime/Projections.CustomTypeMappings.cs +++ b/src/WinRT.Runtime/Projections.CustomTypeMappings.cs @@ -356,18 +356,8 @@ public static void RegisterICollectionMapping() => RegisterCustomTypeToHelperTyp typeof(ABI.System.Collections.ICollection)); #endif /// Registers the custom ABI type mapping for the type. - public static void RegisterEventHandlerMapping() - { - rwlock.EnterWriteLock(); - - try - { - RegisterCustomAbiTypeMappingNoLock(typeof(EventHandler), typeof(ABI.System.EventHandler)); - } - finally - { - rwlock.ExitWriteLock(); - } - } + public static void RegisterEventHandlerMapping() => RegisterCustomAbiTypeMapping( + typeof(EventHandler), + typeof(ABI.System.EventHandler)); } } \ No newline at end of file diff --git a/src/WinRT.Runtime/Projections.cs b/src/WinRT.Runtime/Projections.cs index 02ab74ce2..3759e90dc 100644 --- a/src/WinRT.Runtime/Projections.cs +++ b/src/WinRT.Runtime/Projections.cs @@ -205,6 +205,27 @@ private static void RegisterCustomAbiTypeMappingNoLock( } } + private static void RegisterCustomAbiTypeMapping( + Type publicType, +#if NET + [DynamicallyAccessedMembers( + DynamicallyAccessedMemberTypes.PublicMethods | + DynamicallyAccessedMemberTypes.PublicNestedTypes | + DynamicallyAccessedMemberTypes.PublicFields)] +#endif + Type abiType) + { + rwlock.EnterWriteLock(); + try + { + RegisterCustomAbiTypeMappingNoLock(publicType, abiType); + } + finally + { + rwlock.ExitWriteLock(); + } + } + private static void RegisterCustomAbiTypeMappingNoLock( Type publicType, #if NET From b4150e3a3f9cd68194138fbbbe60faed0499cbc8 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 31 Jan 2024 15:08:31 +0100 Subject: [PATCH 11/20] Disable 'EnableDefaultCustomTypeMappings' on NS2.0 --- ...TypeMappings.cs => Projections.CustomTypeMappings.net5.cs} | 4 ++-- src/WinRT.Runtime/Projections.cs | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) rename src/WinRT.Runtime/{Projections.CustomTypeMappings.cs => Projections.CustomTypeMappings.net5.cs} (99%) diff --git a/src/WinRT.Runtime/Projections.CustomTypeMappings.cs b/src/WinRT.Runtime/Projections.CustomTypeMappings.net5.cs similarity index 99% rename from src/WinRT.Runtime/Projections.CustomTypeMappings.cs rename to src/WinRT.Runtime/Projections.CustomTypeMappings.net5.cs index c6550acab..8d885080c 100644 --- a/src/WinRT.Runtime/Projections.CustomTypeMappings.cs +++ b/src/WinRT.Runtime/Projections.CustomTypeMappings.net5.cs @@ -339,7 +339,7 @@ public static void RegisterIVectorViewOpenGenericMapping() => RegisterCustomType public static void RegisterIBindableVectorMapping() => RegisterCustomTypeToHelperTypeMapping( typeof(IBindableVector), typeof(ABI.System.Collections.IList)); -#if NET + /// Registers the custom ABI type mapping for the type. public static void RegisterICollectionOpenGenericMapping() => RegisterCustomTypeToHelperTypeMapping( typeof(ICollection<>), @@ -354,7 +354,7 @@ public static void RegisterIReadOnlyCollectionOpenGenericMapping() => RegisterCu public static void RegisterICollectionMapping() => RegisterCustomTypeToHelperTypeMapping( typeof(ICollection), typeof(ABI.System.Collections.ICollection)); -#endif + /// Registers the custom ABI type mapping for the type. public static void RegisterEventHandlerMapping() => RegisterCustomAbiTypeMapping( typeof(EventHandler), diff --git a/src/WinRT.Runtime/Projections.cs b/src/WinRT.Runtime/Projections.cs index 3759e90dc..830374e1d 100644 --- a/src/WinRT.Runtime/Projections.cs +++ b/src/WinRT.Runtime/Projections.cs @@ -45,12 +45,16 @@ static Projections() // Also always register Type, since it's "free" (no associated ABI type to root) CustomTypeToAbiTypeNameMappings.Add(typeof(Type), "Windows.UI.Xaml.Interop.TypeName"); +#if NET // If default mappings are disabled, we avoid rooting everything by default. // Developers will have to optionally opt-in into individual mappings later. + // Only do this on modern .NET, because trimming isn't supported downlevel + // anyway. This also makes it simpler to expose all 'Register' methods. if (!FeatureSwitches.EnableDefaultCustomTypeMappings) { return; } +#endif // This should be in sync with cswinrt/helpers.h and the reverse mapping from WinRT.SourceGenerator/WinRTTypeWriter.cs. RegisterCustomAbiTypeMappingNoLock(typeof(EventRegistrationToken), typeof(ABI.WinRT.EventRegistrationToken), "Windows.Foundation.EventRegistrationToken"); From 1f809cb1f0c64c7049452d7b9cc005959bceba5c Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 31 Jan 2024 15:14:30 +0100 Subject: [PATCH 12/20] Add initial T4 configuration --- .../Projections.CustomTypeMappings.net5.g.cs | 1 + .../Projections.CustomTypeMappings.net5.tt | 3 +++ src/WinRT.Runtime/WinRT.Runtime.csproj | 23 +++++++++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 src/WinRT.Runtime/Projections.CustomTypeMappings.net5.g.cs create mode 100644 src/WinRT.Runtime/Projections.CustomTypeMappings.net5.tt diff --git a/src/WinRT.Runtime/Projections.CustomTypeMappings.net5.g.cs b/src/WinRT.Runtime/Projections.CustomTypeMappings.net5.g.cs new file mode 100644 index 000000000..5f282702b --- /dev/null +++ b/src/WinRT.Runtime/Projections.CustomTypeMappings.net5.g.cs @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/WinRT.Runtime/Projections.CustomTypeMappings.net5.tt b/src/WinRT.Runtime/Projections.CustomTypeMappings.net5.tt new file mode 100644 index 000000000..98e4eb52d --- /dev/null +++ b/src/WinRT.Runtime/Projections.CustomTypeMappings.net5.tt @@ -0,0 +1,3 @@ +<#@ template debug="false" hostspecific="false" language="C#" #> +<#@ assembly name="System.Core" #> +<#@ output extension=".g.cs"#> \ No newline at end of file diff --git a/src/WinRT.Runtime/WinRT.Runtime.csproj b/src/WinRT.Runtime/WinRT.Runtime.csproj index 7ac5d227f..0e0cc51c9 100644 --- a/src/WinRT.Runtime/WinRT.Runtime.csproj +++ b/src/WinRT.Runtime/WinRT.Runtime.csproj @@ -30,6 +30,19 @@ + + + + + %(Filename).g.cs + TextTemplatingFileGenerator + + + $([System.IO.Path]::GetFileNameWithoutExtension('%(Filename)')).tt + True + True + + @@ -65,6 +78,16 @@ + + + + + + + + + Projections.CustomTypeMappings.net5.g.cs + From ca509ab5099fc949bc9d46ec38e656154b77a8ff Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 31 Jan 2024 15:58:03 +0100 Subject: [PATCH 13/20] Move RegisterCustomAbiTypeMapping to T4 --- .../Projections.CustomTypeMappings.net5.cs | 311 +---------------- .../Projections.CustomTypeMappings.net5.g.cs | 319 +++++++++++++++++- .../Projections.CustomTypeMappings.net5.tt | 102 +++++- 3 files changed, 420 insertions(+), 312 deletions(-) diff --git a/src/WinRT.Runtime/Projections.CustomTypeMappings.net5.cs b/src/WinRT.Runtime/Projections.CustomTypeMappings.net5.cs index 8d885080c..538f35036 100644 --- a/src/WinRT.Runtime/Projections.CustomTypeMappings.net5.cs +++ b/src/WinRT.Runtime/Projections.CustomTypeMappings.net5.cs @@ -1,320 +1,16 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -using System; using System.Collections; using System.Collections.Generic; -using System.Collections.Specialized; -using System.ComponentModel; -using System.Numerics; -using System.Windows.Input; using Microsoft.UI.Xaml.Interop; using Windows.Foundation.Collections; namespace WinRT { + /// partial class Projections { - /// Registers the custom ABI type mapping for the type. - public static void RegisterEventRegistrationTokenMapping() => RegisterCustomAbiTypeMapping( - typeof(EventRegistrationToken), - typeof(ABI.WinRT.EventRegistrationToken), - "Windows.Foundation.EventRegistrationToken"); - - /// Registers the custom ABI type mapping for the type. - public static void RegisterNullableOpenGenericMapping() => RegisterCustomAbiTypeMapping( - typeof(Nullable<>), - typeof(ABI.System.Nullable<>), - "Windows.Foundation.IReference`1"); - - /// Registers the custom ABI type mapping for the of type. - public static void RegisterNullableIntMapping() => RegisterCustomAbiTypeMapping( - typeof(int?), - typeof(ABI.System.Nullable_int), - "Windows.Foundation.IReference`1"); - - /// Registers the custom ABI type mapping for the of type. - public static void RegisterNullableByteMapping() => RegisterCustomAbiTypeMapping( - typeof(byte?), - typeof(ABI.System.Nullable_byte), - "Windows.Foundation.IReference`1"); - - /// Registers the custom ABI type mapping for the of type. - public static void RegisterNullableSByteMapping() => RegisterCustomAbiTypeMapping( - typeof(sbyte?), - typeof(ABI.System.Nullable_sbyte), - "Windows.Foundation.IReference`1"); - - /// Registers the custom ABI type mapping for the of type. - public static void RegisterNullableShortMapping() => RegisterCustomAbiTypeMapping( - typeof(short?), - typeof(ABI.System.Nullable_short), - "Windows.Foundation.IReference`1"); - - /// Registers the custom ABI type mapping for the of type. - public static void RegisterNullableUShortMapping() => RegisterCustomAbiTypeMapping( - typeof(ushort?), - typeof(ABI.System.Nullable_ushort), - "Windows.Foundation.IReference`1"); - - /// Registers the custom ABI type mapping for the of type. - public static void RegisterNullableUIntMapping() => RegisterCustomAbiTypeMapping( - typeof(uint?), - typeof(ABI.System.Nullable_uint), - "Windows.Foundation.IReference`1"); - - /// Registers the custom ABI type mapping for the of type. - public static void RegisterNullableLongMapping() => RegisterCustomAbiTypeMapping( - typeof(long?), - typeof(ABI.System.Nullable_long), - "Windows.Foundation.IReference`1"); - - /// Registers the custom ABI type mapping for the of type. - public static void RegisterNullableULongMapping() => RegisterCustomAbiTypeMapping( - typeof(ulong?), - typeof(ABI.System.Nullable_ulong), - "Windows.Foundation.IReference`1"); - - /// Registers the custom ABI type mapping for the of type. - public static void RegisterNullableFloatMapping() => RegisterCustomAbiTypeMapping( - typeof(float?), - typeof(ABI.System.Nullable_float), - "Windows.Foundation.IReference`1"); - - /// Registers the custom ABI type mapping for the of type. - public static void RegisterNullableDoubleMapping() => RegisterCustomAbiTypeMapping( - typeof(double?), - typeof(ABI.System.Nullable_double), - "Windows.Foundation.IReference`1"); - - /// Registers the custom ABI type mapping for the of type. - public static void RegisterNullableCharMapping() => RegisterCustomAbiTypeMapping( - typeof(char?), - typeof(ABI.System.Nullable_char), - "Windows.Foundation.IReference`1"); - - /// Registers the custom ABI type mapping for the of type. - public static void RegisterNullableBoolMapping() => RegisterCustomAbiTypeMapping( - typeof(bool?), - typeof(ABI.System.Nullable_bool), - "Windows.Foundation.IReference`1"); - - /// Registers the custom ABI type mapping for the of type. - public static void RegisterNullableGuidMapping() => RegisterCustomAbiTypeMapping( - typeof(Guid?), - typeof(ABI.System.Nullable_guid), - "Windows.Foundation.IReference`1"); - - /// Registers the custom ABI type mapping for the of type. - public static void RegisterNullableDateTimeOffsetMapping() => RegisterCustomAbiTypeMapping( - typeof(DateTimeOffset?), - typeof(ABI.System.Nullable_DateTimeOffset), - "Windows.Foundation.IReference`1"); - - /// Registers the custom ABI type mapping for the of type. - public static void RegisterNullableTimeSpanMapping() => RegisterCustomAbiTypeMapping( - typeof(TimeSpan?), - typeof(ABI.System.Nullable_TimeSpan), - "Windows.Foundation.IReference`1"); - - /// Registers the custom ABI type mapping for the type. - public static void RegisterDateTimeOffsetMapping() => RegisterCustomAbiTypeMapping( - typeof(DateTimeOffset), - typeof(ABI.System.DateTimeOffset), - "Windows.Foundation.DateTime"); - - /// Registers the custom ABI type mapping for the type. - public static void RegisterExceptionMapping() => RegisterCustomAbiTypeMapping( - typeof(Exception), - typeof(ABI.System.Exception), - "Windows.Foundation.HResult"); - - /// Registers the custom ABI type mapping for the type. - public static void RegisterTimeSpanMapping() => RegisterCustomAbiTypeMapping( - typeof(TimeSpan), - typeof(ABI.System.TimeSpan), - "Windows.Foundation.TimeSpan"); - - /// Registers the custom ABI type mapping for the type. - public static void RegisterUriMapping() => RegisterCustomAbiTypeMapping( - typeof(Uri), - typeof(ABI.System.Uri), - "Windows.Foundation.Uri", isRuntimeClass: true); - - /// Registers the custom ABI type mapping for the type. - public static void RegisterDataErrorsChangedEventArgsMapping() => RegisterCustomAbiTypeMapping( - typeof(DataErrorsChangedEventArgs), - typeof(ABI.System.ComponentModel.DataErrorsChangedEventArgs), - "Microsoft.UI.Xaml.Data.DataErrorsChangedEventArgs", isRuntimeClass: true); - - /// Registers the custom ABI type mapping for the type. - public static void RegisterPropertyChangedEventArgsMapping() => RegisterCustomAbiTypeMapping( - typeof(PropertyChangedEventArgs), - typeof(ABI.System.ComponentModel.PropertyChangedEventArgs), - "Microsoft.UI.Xaml.Data.PropertyChangedEventArgs", isRuntimeClass: true); - - /// Registers the custom ABI type mapping for the type. - public static void RegisterPropertyChangedEventHandlerMapping() => RegisterCustomAbiTypeMapping( - typeof(PropertyChangedEventHandler), - typeof(ABI.System.ComponentModel.PropertyChangedEventHandler), - "Microsoft.UI.Xaml.Data.PropertyChangedEventHandler"); - - /// Registers the custom ABI type mapping for the type. - public static void RegisterINotifyDataErrorInfoMapping() => RegisterCustomAbiTypeMapping( - typeof(INotifyDataErrorInfo), - typeof(ABI.System.ComponentModel.INotifyDataErrorInfo), - "Microsoft.UI.Xaml.Data.INotifyDataErrorInfo"); - - /// Registers the custom ABI type mapping for the type. - public static void RegisterINotifyPropertyChangedMapping() => RegisterCustomAbiTypeMapping( - typeof(INotifyPropertyChanged), - typeof(ABI.System.ComponentModel.INotifyPropertyChanged), - "Microsoft.UI.Xaml.Data.INotifyPropertyChanged"); - - /// Registers the custom ABI type mapping for the type. - public static void RegisterICommandMapping() => RegisterCustomAbiTypeMapping( - typeof(ICommand), - typeof(ABI.System.Windows.Input.ICommand), - "Microsoft.UI.Xaml.Interop.ICommand"); - - /// Registers the custom ABI type mapping for the type. - public static void RegisterIServiceProviderMapping() => RegisterCustomAbiTypeMapping( - typeof(IServiceProvider), - typeof(ABI.System.IServiceProvider), - "Microsoft.UI.Xaml.IXamlServiceProvider"); - - /// Registers the custom ABI type mapping for the type. - public static void RegisterEventHandlerOpenGenericMapping() => RegisterCustomAbiTypeMapping( - typeof(EventHandler<>), - typeof(ABI.System.EventHandler<>), - "Windows.Foundation.EventHandler`1"); - - /// Registers the custom ABI type mapping for the type. - public static void RegisterKeyValuePairOpenGenericMapping() => RegisterCustomAbiTypeMapping( - typeof(KeyValuePair<,>), - typeof(ABI.System.Collections.Generic.KeyValuePair<,>), - "Windows.Foundation.Collections.IKeyValuePair`2"); - - /// Registers the custom ABI type mapping for the type. - public static void RegisterIEnumerableOpenGenericMapping() => RegisterCustomAbiTypeMapping( - typeof(IEnumerable<>), - typeof(ABI.System.Collections.Generic.IEnumerable<>), - "Windows.Foundation.Collections.IIterable`1"); - - /// Registers the custom ABI type mapping for the type. - public static void RegisterIEnumeratorOpenGenericMapping() => RegisterCustomAbiTypeMapping( - typeof(IEnumerator<>), - typeof(ABI.System.Collections.Generic.IEnumerator<>), - "Windows.Foundation.Collections.IIterator`1"); - - /// Registers the custom ABI type mapping for the type. - public static void RegisterIListOpenGenericMapping() => RegisterCustomAbiTypeMapping( - typeof(IList<>), - typeof(ABI.System.Collections.Generic.IList<>), - "Windows.Foundation.Collections.IVector`1"); - - /// Registers the custom ABI type mapping for the type. - public static void RegisterIReadOnlyListOpenGenericMapping() => RegisterCustomAbiTypeMapping( - typeof(IReadOnlyList<>), - typeof(ABI.System.Collections.Generic.IReadOnlyList<>), - "Windows.Foundation.Collections.IVectorView`1"); - - /// Registers the custom ABI type mapping for the type. - public static void RegisterIDictionaryOpenGenericMapping() => RegisterCustomAbiTypeMapping( - typeof(IDictionary<,>), - typeof(ABI.System.Collections.Generic.IDictionary<,>), - "Windows.Foundation.Collections.IMap`2"); - - /// Registers the custom ABI type mapping for the type. - public static void RegisterIReadOnlyDictionaryOpenGenericMapping() => RegisterCustomAbiTypeMapping( - typeof(IReadOnlyDictionary<,>), - typeof(ABI.System.Collections.Generic.IReadOnlyDictionary<,>), - "Windows.Foundation.Collections.IMapView`2"); - - /// Registers the custom ABI type mapping for the type. - public static void RegisterIDisposableMapping() => RegisterCustomAbiTypeMapping( - typeof(IDisposable), - typeof(ABI.System.IDisposable), - "Windows.Foundation.IClosable"); - - /// Registers the custom ABI type mapping for the type. - public static void RegisterIEnumerableMapping() => RegisterCustomAbiTypeMapping( - typeof(IEnumerable), - typeof(ABI.System.Collections.IEnumerable), - "Microsoft.UI.Xaml.Interop.IBindableIterable"); - - /// Registers the custom ABI type mapping for the type. - public static void RegisterIListMapping() => RegisterCustomAbiTypeMapping( - typeof(IList), - typeof(ABI.System.Collections.IList), - "Microsoft.UI.Xaml.Interop.IBindableVector"); - - /// Registers the custom ABI type mapping for the type. - public static void RegisterINotifyCollectionChangedMapping() => RegisterCustomAbiTypeMapping( - typeof(INotifyCollectionChanged), - typeof(ABI.System.Collections.Specialized.INotifyCollectionChanged), - "Microsoft.UI.Xaml.Interop.INotifyCollectionChanged"); - - /// Registers the custom ABI type mapping for the type. - public static void RegisterNotifyCollectionChangedActionMapping() => RegisterCustomAbiTypeMapping( - typeof(NotifyCollectionChangedAction), - typeof(ABI.System.Collections.Specialized.NotifyCollectionChangedAction), - "Microsoft.UI.Xaml.Interop.NotifyCollectionChangedAction"); - - /// Registers the custom ABI type mapping for the type. - public static void RegisterNotifyCollectionChangedEventArgsMapping() => RegisterCustomAbiTypeMapping( - typeof(NotifyCollectionChangedEventArgs), - typeof(ABI.System.Collections.Specialized.NotifyCollectionChangedEventArgs), - "Microsoft.UI.Xaml.Interop.NotifyCollectionChangedEventArgs", isRuntimeClass: true); - - /// Registers the custom ABI type mapping for the type. - public static void RegisterNotifyCollectionChangedEventHandlerMapping() => RegisterCustomAbiTypeMapping( - typeof(NotifyCollectionChangedEventHandler), - typeof(ABI.System.Collections.Specialized.NotifyCollectionChangedEventHandler), - "Microsoft.UI.Xaml.Interop.NotifyCollectionChangedEventHandler"); - - /// Registers the custom ABI type mapping for the type. - public static void RegisterMatrix3x2Mapping() => RegisterCustomAbiTypeMapping( - typeof(Matrix3x2), - typeof(ABI.System.Numerics.Matrix3x2), - "Windows.Foundation.Numerics.Matrix3x2"); - - /// Registers the custom ABI type mapping for the type. - public static void RegisterMatrix4x4Mapping() => RegisterCustomAbiTypeMapping( - typeof(Matrix4x4), - typeof(ABI.System.Numerics.Matrix4x4), - "Windows.Foundation.Numerics.Matrix4x4"); - - /// Registers the custom ABI type mapping for the type. - public static void RegisterPlaneMapping() => RegisterCustomAbiTypeMapping( - typeof(Plane), - typeof(ABI.System.Numerics.Plane), - "Windows.Foundation.Numerics.Plane"); - - /// Registers the custom ABI type mapping for the type. - public static void RegisterQuaternionMapping() => RegisterCustomAbiTypeMapping( - typeof(Quaternion), - typeof(ABI.System.Numerics.Quaternion), - "Windows.Foundation.Numerics.Quaternion"); - - /// Registers the custom ABI type mapping for the type. - public static void RegisterVector2Mapping() => RegisterCustomAbiTypeMapping( - typeof(Vector2), - typeof(ABI.System.Numerics.Vector2), - "Windows.Foundation.Numerics.Vector2"); - - /// Registers the custom ABI type mapping for the type. - public static void RegisterVector3Mapping() => RegisterCustomAbiTypeMapping( - typeof(Vector3), - typeof(ABI.System.Numerics.Vector3), - "Windows.Foundation.Numerics.Vector3"); - - /// Registers the custom ABI type mapping for the type. - public static void RegisterVector4Mapping() => RegisterCustomAbiTypeMapping( - typeof(Vector4), - typeof(ABI.System.Numerics.Vector4), - "Windows.Foundation.Numerics.Vector4"); - /// Registers the custom ABI type mapping for the type. public static void RegisterIMapOpenGenericMapping() => RegisterCustomTypeToHelperTypeMapping( typeof(IMap<,>), @@ -354,10 +50,5 @@ public static void RegisterIReadOnlyCollectionOpenGenericMapping() => RegisterCu public static void RegisterICollectionMapping() => RegisterCustomTypeToHelperTypeMapping( typeof(ICollection), typeof(ABI.System.Collections.ICollection)); - - /// Registers the custom ABI type mapping for the type. - public static void RegisterEventHandlerMapping() => RegisterCustomAbiTypeMapping( - typeof(EventHandler), - typeof(ABI.System.EventHandler)); } } \ No newline at end of file diff --git a/src/WinRT.Runtime/Projections.CustomTypeMappings.net5.g.cs b/src/WinRT.Runtime/Projections.CustomTypeMappings.net5.g.cs index 5f282702b..630f0d9d8 100644 --- a/src/WinRT.Runtime/Projections.CustomTypeMappings.net5.g.cs +++ b/src/WinRT.Runtime/Projections.CustomTypeMappings.net5.g.cs @@ -1 +1,318 @@ - \ No newline at end of file +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.Specialized; +using System.ComponentModel; +using System.Numerics; +using System.Windows.Input; +using Microsoft.UI.Xaml.Interop; +using Windows.Foundation.Collections; + +namespace WinRT +{ + /// + partial class Projections + { + /// Registers the custom ABI type mapping for the type. + public static void RegisterEventHandlerMapping() => RegisterCustomAbiTypeMapping( + typeof(EventHandler), + typeof(ABI.System.EventHandler)); + + /// Registers the custom ABI type mapping for the "Windows.Foundation.EventRegistrationToken" WinRT type. + public static void RegisterEventRegistrationTokenMapping() => RegisterCustomAbiTypeMapping( + typeof(EventRegistrationToken), + typeof(ABI.WinRT.EventRegistrationToken), + "Windows.Foundation.EventRegistrationToken"); + + /// Registers the custom ABI type mapping for the "Windows.Foundation.IReference`1" WinRT type. + public static void RegisterNullableOpenGenericMapping() => RegisterCustomAbiTypeMapping( + typeof(Nullable<>), + typeof(ABI.System.Nullable<>), + "Windows.Foundation.IReference`1"); + + /// Registers the custom ABI type mapping for the "Windows.Foundation.IReference`1" WinRT type. + public static void RegisterNullableIntMapping() => RegisterCustomAbiTypeMapping( + typeof(int?), + typeof(ABI.System.Nullable_int), + "Windows.Foundation.IReference`1"); + + /// Registers the custom ABI type mapping for the "Windows.Foundation.IReference`1" WinRT type. + public static void RegisterNullableByteMapping() => RegisterCustomAbiTypeMapping( + typeof(byte?), + typeof(ABI.System.Nullable_byte), + "Windows.Foundation.IReference`1"); + + /// Registers the custom ABI type mapping for the "Windows.Foundation.IReference`1" WinRT type. + public static void RegisterNullableSByteMapping() => RegisterCustomAbiTypeMapping( + typeof(sbyte?), + typeof(ABI.System.Nullable_sbyte), + "Windows.Foundation.IReference`1"); + + /// Registers the custom ABI type mapping for the "Windows.Foundation.IReference`1" WinRT type. + public static void RegisterNullableShortMapping() => RegisterCustomAbiTypeMapping( + typeof(short?), + typeof(ABI.System.Nullable_short), + "Windows.Foundation.IReference`1"); + + /// Registers the custom ABI type mapping for the "Windows.Foundation.IReference`1" WinRT type. + public static void RegisterNullableUShortMapping() => RegisterCustomAbiTypeMapping( + typeof(ushort?), + typeof(ABI.System.Nullable_ushort), + "Windows.Foundation.IReference`1"); + + /// Registers the custom ABI type mapping for the "Windows.Foundation.IReference`1" WinRT type. + public static void RegisterNullableUIntMapping() => RegisterCustomAbiTypeMapping( + typeof(uint?), + typeof(ABI.System.Nullable_uint), + "Windows.Foundation.IReference`1"); + + /// Registers the custom ABI type mapping for the "Windows.Foundation.IReference`1" WinRT type. + public static void RegisterNullableLongMapping() => RegisterCustomAbiTypeMapping( + typeof(long?), + typeof(ABI.System.Nullable_long), + "Windows.Foundation.IReference`1"); + + /// Registers the custom ABI type mapping for the "Windows.Foundation.IReference`1" WinRT type. + public static void RegisterNullableULongMapping() => RegisterCustomAbiTypeMapping( + typeof(ulong?), + typeof(ABI.System.Nullable_ulong), + "Windows.Foundation.IReference`1"); + + /// Registers the custom ABI type mapping for the "Windows.Foundation.IReference`1" WinRT type. + public static void RegisterNullableFloatMapping() => RegisterCustomAbiTypeMapping( + typeof(float?), + typeof(ABI.System.Nullable_float), + "Windows.Foundation.IReference`1"); + + /// Registers the custom ABI type mapping for the "Windows.Foundation.IReference`1" WinRT type. + public static void RegisterNullableDoubleMapping() => RegisterCustomAbiTypeMapping( + typeof(double?), + typeof(ABI.System.Nullable_double), + "Windows.Foundation.IReference`1"); + + /// Registers the custom ABI type mapping for the "Windows.Foundation.IReference`1" WinRT type. + public static void RegisterNullableCharMapping() => RegisterCustomAbiTypeMapping( + typeof(char?), + typeof(ABI.System.Nullable_char), + "Windows.Foundation.IReference`1"); + + /// Registers the custom ABI type mapping for the "Windows.Foundation.IReference`1" WinRT type. + public static void RegisterNullableBoolMapping() => RegisterCustomAbiTypeMapping( + typeof(bool?), + typeof(ABI.System.Nullable_bool), + "Windows.Foundation.IReference`1"); + + /// Registers the custom ABI type mapping for the "Windows.Foundation.IReference`1" WinRT type. + public static void RegisterNullableGuidMapping() => RegisterCustomAbiTypeMapping( + typeof(Guid?), + typeof(ABI.System.Nullable_guid), + "Windows.Foundation.IReference`1"); + + /// Registers the custom ABI type mapping for the "Windows.Foundation.IReference`1" WinRT type. + public static void RegisterNullableDateTimeOffsetMapping() => RegisterCustomAbiTypeMapping( + typeof(DateTimeOffset?), + typeof(ABI.System.Nullable_DateTimeOffset), + "Windows.Foundation.IReference`1"); + + /// Registers the custom ABI type mapping for the "Windows.Foundation.IReference`1" WinRT type. + public static void RegisterNullableTimeSpanMapping() => RegisterCustomAbiTypeMapping( + typeof(TimeSpan?), + typeof(ABI.System.Nullable_TimeSpan), + "Windows.Foundation.IReference`1"); + + /// Registers the custom ABI type mapping for the "Windows.Foundation.DateTime" WinRT type. + public static void RegisterDateTimeOffsetMapping() => RegisterCustomAbiTypeMapping( + typeof(DateTimeOffset), + typeof(ABI.System.DateTimeOffset), + "Windows.Foundation.DateTime"); + + /// Registers the custom ABI type mapping for the "Windows.Foundation.HResult" WinRT type. + public static void RegisterExceptionMapping() => RegisterCustomAbiTypeMapping( + typeof(Exception), + typeof(ABI.System.Exception), + "Windows.Foundation.HResult"); + + /// Registers the custom ABI type mapping for the "Windows.Foundation.TimeSpan" WinRT type. + public static void RegisterTimeSpanMapping() => RegisterCustomAbiTypeMapping( + typeof(TimeSpan), + typeof(ABI.System.TimeSpan), + "Windows.Foundation.TimeSpan"); + + /// Registers the custom ABI type mapping for the "Windows.Foundation.Uri" WinRT type. + public static void RegisterUriMapping() => RegisterCustomAbiTypeMapping( + typeof(Uri), + typeof(ABI.System.Uri), + "Windows.Foundation.Uri"); + + /// Registers the custom ABI type mapping for the "Microsoft.UI.Xaml.Data.DataErrorsChangedEventArgs" WinRT type. + public static void RegisterDataErrorsChangedEventArgsMapping() => RegisterCustomAbiTypeMapping( + typeof(DataErrorsChangedEventArgs), + typeof(ABI.System.ComponentModel.DataErrorsChangedEventArgs), + "Microsoft.UI.Xaml.Data.DataErrorsChangedEventArgs"); + + /// Registers the custom ABI type mapping for the "Microsoft.UI.Xaml.Data.PropertyChangedEventArgs" WinRT type. + public static void RegisterPropertyChangedEventArgsMapping() => RegisterCustomAbiTypeMapping( + typeof(PropertyChangedEventArgs), + typeof(ABI.System.ComponentModel.PropertyChangedEventArgs), + "Microsoft.UI.Xaml.Data.PropertyChangedEventArgs"); + + /// Registers the custom ABI type mapping for the "Microsoft.UI.Xaml.Data.PropertyChangedEventHandler" WinRT type. + public static void RegisterPropertyChangedEventHandlerMapping() => RegisterCustomAbiTypeMapping( + typeof(PropertyChangedEventHandler), + typeof(ABI.System.ComponentModel.PropertyChangedEventHandler), + "Microsoft.UI.Xaml.Data.PropertyChangedEventHandler"); + + /// Registers the custom ABI type mapping for the "Microsoft.UI.Xaml.Data.INotifyDataErrorInfo" WinRT type. + public static void RegisterINotifyDataErrorInfoMapping() => RegisterCustomAbiTypeMapping( + typeof(INotifyDataErrorInfo), + typeof(ABI.System.ComponentModel.INotifyDataErrorInfo), + "Microsoft.UI.Xaml.Data.INotifyDataErrorInfo"); + + /// Registers the custom ABI type mapping for the "Microsoft.UI.Xaml.Data.INotifyPropertyChanged" WinRT type. + public static void RegisterINotifyPropertyChangedMapping() => RegisterCustomAbiTypeMapping( + typeof(INotifyPropertyChanged), + typeof(ABI.System.ComponentModel.INotifyPropertyChanged), + "Microsoft.UI.Xaml.Data.INotifyPropertyChanged"); + + /// Registers the custom ABI type mapping for the "Microsoft.UI.Xaml.Interop.ICommand" WinRT type. + public static void RegisterICommandMapping() => RegisterCustomAbiTypeMapping( + typeof(ICommand), + typeof(ABI.System.Windows.Input.ICommand), + "Microsoft.UI.Xaml.Interop.ICommand"); + + /// Registers the custom ABI type mapping for the "Microsoft.UI.Xaml.IXamlServiceProvider" WinRT type. + public static void RegisterIServiceProviderMapping() => RegisterCustomAbiTypeMapping( + typeof(IServiceProvider), + typeof(ABI.System.IServiceProvider), + "Microsoft.UI.Xaml.IXamlServiceProvider"); + + /// Registers the custom ABI type mapping for the "Windows.Foundation.EventHandler`1" WinRT type. + public static void RegisterEventHandlerOpenGenericMapping() => RegisterCustomAbiTypeMapping( + typeof(EventHandler<>), + typeof(ABI.System.EventHandler<>), + "Windows.Foundation.EventHandler`1"); + + /// Registers the custom ABI type mapping for the "Windows.Foundation.Collections.IKeyValuePair`2" WinRT type. + public static void RegisterKeyValuePairOpenGenericMapping() => RegisterCustomAbiTypeMapping( + typeof(KeyValuePair<,>), + typeof(ABI.System.Collections.Generic.KeyValuePair<,>), + "Windows.Foundation.Collections.IKeyValuePair`2"); + + /// Registers the custom ABI type mapping for the "Windows.Foundation.Collections.IIterable`1" WinRT type. + public static void RegisterIEnumerableOpenGenericMapping() => RegisterCustomAbiTypeMapping( + typeof(IEnumerable<>), + typeof(ABI.System.Collections.Generic.IEnumerable<>), + "Windows.Foundation.Collections.IIterable`1"); + + /// Registers the custom ABI type mapping for the "Windows.Foundation.Collections.IIterator`1" WinRT type. + public static void RegisterIEnumeratorOpenGenericMapping() => RegisterCustomAbiTypeMapping( + typeof(IEnumerator<>), + typeof(ABI.System.Collections.Generic.IEnumerator<>), + "Windows.Foundation.Collections.IIterator`1"); + + /// Registers the custom ABI type mapping for the "Windows.Foundation.Collections.IVector`1" WinRT type. + public static void RegisterIListOpenGenericMapping() => RegisterCustomAbiTypeMapping( + typeof(IList<>), + typeof(ABI.System.Collections.Generic.IList<>), + "Windows.Foundation.Collections.IVector`1"); + + /// Registers the custom ABI type mapping for the "Windows.Foundation.Collections.IVectorView`1" WinRT type. + public static void RegisterIReadOnlyListOpenGenericMapping() => RegisterCustomAbiTypeMapping( + typeof(IReadOnlyList<>), + typeof(ABI.System.Collections.Generic.IReadOnlyList<>), + "Windows.Foundation.Collections.IVectorView`1"); + + /// Registers the custom ABI type mapping for the "Windows.Foundation.Collections.IMap`2" WinRT type. + public static void RegisterIDictionaryOpenGenericMapping() => RegisterCustomAbiTypeMapping( + typeof(IDictionary<,>), + typeof(ABI.System.Collections.Generic.IDictionary<,>), + "Windows.Foundation.Collections.IMap`2"); + + /// Registers the custom ABI type mapping for the "Windows.Foundation.Collections.IMapView`2" WinRT type. + public static void RegisterIReadOnlyDictionaryOpenGenericMapping() => RegisterCustomAbiTypeMapping( + typeof(IReadOnlyDictionary<,>), + typeof(ABI.System.Collections.Generic.IReadOnlyDictionary<,>), + "Windows.Foundation.Collections.IMapView`2"); + + /// Registers the custom ABI type mapping for the "Windows.Foundation.IClosable" WinRT type. + public static void RegisterIDisposableMapping() => RegisterCustomAbiTypeMapping( + typeof(IDisposable), + typeof(ABI.System.IDisposable), + "Windows.Foundation.IClosable"); + + /// Registers the custom ABI type mapping for the "Microsoft.UI.Xaml.Interop.IBindableIterable" WinRT type. + public static void RegisterIEnumerableMapping() => RegisterCustomAbiTypeMapping( + typeof(IEnumerable), + typeof(ABI.System.Collections.IEnumerable), + "Microsoft.UI.Xaml.Interop.IBindableIterable"); + + /// Registers the custom ABI type mapping for the "Microsoft.UI.Xaml.Interop.IBindableVector" WinRT type. + public static void RegisterIListMapping() => RegisterCustomAbiTypeMapping( + typeof(IList), + typeof(ABI.System.Collections.IList), + "Microsoft.UI.Xaml.Interop.IBindableVector"); + + /// Registers the custom ABI type mapping for the "Microsoft.UI.Xaml.Interop.INotifyCollectionChanged" WinRT type. + public static void RegisterINotifyCollectionChangedMapping() => RegisterCustomAbiTypeMapping( + typeof(INotifyCollectionChanged), + typeof(ABI.System.Collections.Specialized.INotifyCollectionChanged), + "Microsoft.UI.Xaml.Interop.INotifyCollectionChanged"); + + /// Registers the custom ABI type mapping for the "Microsoft.UI.Xaml.Interop.NotifyCollectionChangedEventArgs" WinRT type. + public static void RegisterNotifyCollectionChangedActionMapping() => RegisterCustomAbiTypeMapping( + typeof(NotifyCollectionChangedAction), + typeof(ABI.System.Collections.Specialized.NotifyCollectionChangedAction), + "Microsoft.UI.Xaml.Interop.NotifyCollectionChangedEventArgs"); + + /// Registers the custom ABI type mapping for the "Microsoft.UI.Xaml.Interop.NotifyCollectionChangedEventHandler" WinRT type. + public static void RegisterNotifyCollectionChangedEventHandlerMapping() => RegisterCustomAbiTypeMapping( + typeof(NotifyCollectionChangedEventHandler), + typeof(ABI.System.Collections.Specialized.NotifyCollectionChangedEventHandler), + "Microsoft.UI.Xaml.Interop.NotifyCollectionChangedEventHandler"); + + /// Registers the custom ABI type mapping for the "Windows.Foundation.Numerics.Matrix3x2" WinRT type. + public static void RegisterMatrix3x2Mapping() => RegisterCustomAbiTypeMapping( + typeof(Matrix3x2), + typeof(ABI.System.Numerics.Matrix3x2), + "Windows.Foundation.Numerics.Matrix3x2"); + + /// Registers the custom ABI type mapping for the "Windows.Foundation.Numerics.Matrix4x4" WinRT type. + public static void RegisterMatrix4x4Mapping() => RegisterCustomAbiTypeMapping( + typeof(Matrix4x4), + typeof(ABI.System.Numerics.Matrix4x4), + "Windows.Foundation.Numerics.Matrix4x4"); + + /// Registers the custom ABI type mapping for the "Windows.Foundation.Numerics.Plane" WinRT type. + public static void RegisterPlaneMapping() => RegisterCustomAbiTypeMapping( + typeof(Plane), + typeof(ABI.System.Numerics.Plane), + "Windows.Foundation.Numerics.Plane"); + + /// Registers the custom ABI type mapping for the "Windows.Foundation.Numerics.Quaternion" WinRT type. + public static void RegisterQuaternionMapping() => RegisterCustomAbiTypeMapping( + typeof(Quaternion), + typeof(ABI.System.Numerics.Quaternion), + "Windows.Foundation.Numerics.Quaternion"); + + /// Registers the custom ABI type mapping for the "Windows.Foundation.Numerics.Vector2" WinRT type. + public static void RegisterVector2Mapping() => RegisterCustomAbiTypeMapping( + typeof(Vector2), + typeof(ABI.System.Numerics.Vector2), + "Windows.Foundation.Numerics.Vector2"); + + /// Registers the custom ABI type mapping for the "Windows.Foundation.Numerics.Vector3" WinRT type. + public static void RegisterVector3Mapping() => RegisterCustomAbiTypeMapping( + typeof(Vector3), + typeof(ABI.System.Numerics.Vector3), + "Windows.Foundation.Numerics.Vector3"); + + /// Registers the custom ABI type mapping for the "Windows.Foundation.Numerics.Vector4" WinRT type. + public static void RegisterVector4Mapping() => RegisterCustomAbiTypeMapping( + typeof(Vector4), + typeof(ABI.System.Numerics.Vector4), + "Windows.Foundation.Numerics.Vector4"); + } +} \ No newline at end of file diff --git a/src/WinRT.Runtime/Projections.CustomTypeMappings.net5.tt b/src/WinRT.Runtime/Projections.CustomTypeMappings.net5.tt index 98e4eb52d..57451f74d 100644 --- a/src/WinRT.Runtime/Projections.CustomTypeMappings.net5.tt +++ b/src/WinRT.Runtime/Projections.CustomTypeMappings.net5.tt @@ -1,3 +1,103 @@ <#@ template debug="false" hostspecific="false" language="C#" #> <#@ assembly name="System.Core" #> -<#@ output extension=".g.cs"#> \ No newline at end of file +<#@ output extension=".g.cs"#> +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.Specialized; +using System.ComponentModel; +using System.Numerics; +using System.Windows.Input; +using Microsoft.UI.Xaml.Interop; +using Windows.Foundation.Collections; + +namespace WinRT +{ + /// + partial class Projections + { + /// Registers the custom ABI type mapping for the type. + public static void RegisterEventHandlerMapping() => RegisterCustomAbiTypeMapping( + typeof(EventHandler), + typeof(ABI.System.EventHandler)); +<# +// Types for 'RegisterCustomAbiTypeMapping' +foreach (var type in new (string Public, string Abi, string Name, string Hint, bool IsRuntimeClass)[] { + ("EventRegistrationToken", "ABI.WinRT.EventRegistrationToken", "Windows.Foundation.EventRegistrationToken", null, false), + ("Nullable<>", "ABI.System.Nullable<>", "Windows.Foundation.IReference`1", null, false), + ("int?", "ABI.System.Nullable_int", "Windows.Foundation.IReference`1", "NullableInt", false), + ("byte?", "ABI.System.Nullable_byte", "Windows.Foundation.IReference`1", "NullableByte", false), + ("sbyte?", "ABI.System.Nullable_sbyte", "Windows.Foundation.IReference`1", "NullableSByte", false), + ("short?", "ABI.System.Nullable_short", "Windows.Foundation.IReference`1", "NullableShort", false), + ("ushort?", "ABI.System.Nullable_ushort", "Windows.Foundation.IReference`1", "NullableUShort", false), + ("uint?", "ABI.System.Nullable_uint", "Windows.Foundation.IReference`1", "NullableUInt", false), + ("long?", "ABI.System.Nullable_long", "Windows.Foundation.IReference`1", "NullableLong", false), + ("ulong?", "ABI.System.Nullable_ulong", "Windows.Foundation.IReference`1", "NullableULong", false), + ("float?", "ABI.System.Nullable_float", "Windows.Foundation.IReference`1", "NullableFloat", false), + ("double?", "ABI.System.Nullable_double", "Windows.Foundation.IReference`1", "NullableDouble", false), + ("char?", "ABI.System.Nullable_char", "Windows.Foundation.IReference`1", "NullableChar", false), + ("bool?", "ABI.System.Nullable_bool", "Windows.Foundation.IReference`1", "NullableBool", false), + ("Guid?", "ABI.System.Nullable_guid", "Windows.Foundation.IReference`1", "NullableGuid", false), + ("DateTimeOffset?", "ABI.System.Nullable_DateTimeOffset", "Windows.Foundation.IReference`1", "NullableDateTimeOffset", false), + ("TimeSpan?", "ABI.System.Nullable_TimeSpan", "Windows.Foundation.IReference`1", "NullableTimeSpan", false), + ("DateTimeOffset", "ABI.System.DateTimeOffset", "Windows.Foundation.DateTime", null, false), + ("Exception", "ABI.System.Exception", "Windows.Foundation.HResult", null, false), + ("TimeSpan", "ABI.System.TimeSpan", "Windows.Foundation.TimeSpan", null, false), + ("Uri", "ABI.System.Uri", "Windows.Foundation.Uri", null, true), + ("DataErrorsChangedEventArgs", "ABI.System.ComponentModel.DataErrorsChangedEventArgs", "Microsoft.UI.Xaml.Data.DataErrorsChangedEventArgs", null, true), + ("PropertyChangedEventArgs", "ABI.System.ComponentModel.PropertyChangedEventArgs", "Microsoft.UI.Xaml.Data.PropertyChangedEventArgs", null, true), + ("PropertyChangedEventHandler", "ABI.System.ComponentModel.PropertyChangedEventHandler", "Microsoft.UI.Xaml.Data.PropertyChangedEventHandler", null, false), + ("INotifyDataErrorInfo", "ABI.System.ComponentModel.INotifyDataErrorInfo", "Microsoft.UI.Xaml.Data.INotifyDataErrorInfo", null, false), + ("INotifyPropertyChanged", "ABI.System.ComponentModel.INotifyPropertyChanged", "Microsoft.UI.Xaml.Data.INotifyPropertyChanged", null, false), + ("ICommand", "ABI.System.Windows.Input.ICommand", "Microsoft.UI.Xaml.Interop.ICommand", null, false), + ("IServiceProvider", "ABI.System.IServiceProvider", "Microsoft.UI.Xaml.IXamlServiceProvider", null, false), + ("EventHandler<>", "ABI.System.EventHandler<>", "Windows.Foundation.EventHandler`1", null, false), + ("KeyValuePair<,>", "ABI.System.Collections.Generic.KeyValuePair<,>", "Windows.Foundation.Collections.IKeyValuePair`2", null, false), + ("IEnumerable<>", "ABI.System.Collections.Generic.IEnumerable<>", "Windows.Foundation.Collections.IIterable`1", null, false), + ("IEnumerator<>", "ABI.System.Collections.Generic.IEnumerator<>", "Windows.Foundation.Collections.IIterator`1", null, false), + ("IList<>", "ABI.System.Collections.Generic.IList<>", "Windows.Foundation.Collections.IVector`1", null, false), + ("IReadOnlyList<>", "ABI.System.Collections.Generic.IReadOnlyList<>", "Windows.Foundation.Collections.IVectorView`1", null, false), + ("IDictionary<,>", "ABI.System.Collections.Generic.IDictionary<,>", "Windows.Foundation.Collections.IMap`2", null, false), + ("IReadOnlyDictionary<,>", "ABI.System.Collections.Generic.IReadOnlyDictionary<,>", "Windows.Foundation.Collections.IMapView`2", null, false), + ("IDisposable", "ABI.System.IDisposable", "Windows.Foundation.IClosable", null, false), + ("IEnumerable", "ABI.System.Collections.IEnumerable", "Microsoft.UI.Xaml.Interop.IBindableIterable", null, false), + ("IList", "ABI.System.Collections.IList", "Microsoft.UI.Xaml.Interop.IBindableVector", null, false), + ("INotifyCollectionChanged", "ABI.System.Collections.Specialized.INotifyCollectionChanged", "Microsoft.UI.Xaml.Interop.INotifyCollectionChanged", null, false), + ("NotifyCollectionChangedAction", "ABI.System.Collections.Specialized.NotifyCollectionChangedAction", "Microsoft.UI.Xaml.Interop.NotifyCollectionChangedEventArgs", null, true), + ("NotifyCollectionChangedEventHandler", "ABI.System.Collections.Specialized.NotifyCollectionChangedEventHandler", "Microsoft.UI.Xaml.Interop.NotifyCollectionChangedEventHandler", null, false), + ("Matrix3x2", "ABI.System.Numerics.Matrix3x2", "Windows.Foundation.Numerics.Matrix3x2", null, false), + ("Matrix4x4", "ABI.System.Numerics.Matrix4x4", "Windows.Foundation.Numerics.Matrix4x4", null, false), + ("Plane", "ABI.System.Numerics.Plane", "Windows.Foundation.Numerics.Plane", null, false), + ("Quaternion", "ABI.System.Numerics.Quaternion", "Windows.Foundation.Numerics.Quaternion", null, false), + ("Vector2", "ABI.System.Numerics.Vector2", "Windows.Foundation.Numerics.Vector2", null, false), + ("Vector3", "ABI.System.Numerics.Vector3", "Windows.Foundation.Numerics.Vector3", null, false), + ("Vector4", "ABI.System.Numerics.Vector4", "Windows.Foundation.Numerics.Vector4", null, false) }) +{ + var methodTypeName = type.Hint; + + // If the hint isn't available, automatically derive the name. For generic types, + // we strip the '<>' from the name and append "OpenGeneric" as a suffix. + if (methodTypeName == null) + { + methodTypeName = type.Public; + if (type.Name.Contains("`")) methodTypeName = methodTypeName.Substring(0, methodTypeName.IndexOf('<')); + if (type.Name.Contains("`")) methodTypeName += "OpenGeneric"; + } + + var methodFullName = $"Register{methodTypeName}Mapping"; + + WriteLine(""); +#> + /// Registers the custom ABI type mapping for the "<#=type.Name#>" WinRT type. + public static void <#=methodFullName#>() => RegisterCustomAbiTypeMapping( + typeof(<#=type.Public#>), + typeof(<#=type.Abi#>), + "<#=type.Name#>"); +<# +} +#> + } +} \ No newline at end of file From c52e2c683c5c74a55fc26a3633cf11873fb8ff30 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 31 Jan 2024 16:23:24 +0100 Subject: [PATCH 14/20] Fix bugs, set runtime class, include EventHandler --- .../Projections.CustomTypeMappings.net5.g.cs | 107 +++++++++--------- .../Projections.CustomTypeMappings.net5.tt | 31 +++-- 2 files changed, 74 insertions(+), 64 deletions(-) diff --git a/src/WinRT.Runtime/Projections.CustomTypeMappings.net5.g.cs b/src/WinRT.Runtime/Projections.CustomTypeMappings.net5.g.cs index 630f0d9d8..060878ec0 100644 --- a/src/WinRT.Runtime/Projections.CustomTypeMappings.net5.g.cs +++ b/src/WinRT.Runtime/Projections.CustomTypeMappings.net5.g.cs @@ -16,303 +16,304 @@ namespace WinRT /// partial class Projections { - /// Registers the custom ABI type mapping for the type. - public static void RegisterEventHandlerMapping() => RegisterCustomAbiTypeMapping( - typeof(EventHandler), - typeof(ABI.System.EventHandler)); /// Registers the custom ABI type mapping for the "Windows.Foundation.EventRegistrationToken" WinRT type. public static void RegisterEventRegistrationTokenMapping() => RegisterCustomAbiTypeMapping( typeof(EventRegistrationToken), typeof(ABI.WinRT.EventRegistrationToken), - "Windows.Foundation.EventRegistrationToken"); + "Windows.Foundation.EventRegistrationToken", isRuntimeClass: false); /// Registers the custom ABI type mapping for the "Windows.Foundation.IReference`1" WinRT type. public static void RegisterNullableOpenGenericMapping() => RegisterCustomAbiTypeMapping( typeof(Nullable<>), typeof(ABI.System.Nullable<>), - "Windows.Foundation.IReference`1"); + "Windows.Foundation.IReference`1", isRuntimeClass: false); /// Registers the custom ABI type mapping for the "Windows.Foundation.IReference`1" WinRT type. public static void RegisterNullableIntMapping() => RegisterCustomAbiTypeMapping( typeof(int?), typeof(ABI.System.Nullable_int), - "Windows.Foundation.IReference`1"); + "Windows.Foundation.IReference`1", isRuntimeClass: false); /// Registers the custom ABI type mapping for the "Windows.Foundation.IReference`1" WinRT type. public static void RegisterNullableByteMapping() => RegisterCustomAbiTypeMapping( typeof(byte?), typeof(ABI.System.Nullable_byte), - "Windows.Foundation.IReference`1"); + "Windows.Foundation.IReference`1", isRuntimeClass: false); /// Registers the custom ABI type mapping for the "Windows.Foundation.IReference`1" WinRT type. public static void RegisterNullableSByteMapping() => RegisterCustomAbiTypeMapping( typeof(sbyte?), typeof(ABI.System.Nullable_sbyte), - "Windows.Foundation.IReference`1"); + "Windows.Foundation.IReference`1", isRuntimeClass: false); /// Registers the custom ABI type mapping for the "Windows.Foundation.IReference`1" WinRT type. public static void RegisterNullableShortMapping() => RegisterCustomAbiTypeMapping( typeof(short?), typeof(ABI.System.Nullable_short), - "Windows.Foundation.IReference`1"); + "Windows.Foundation.IReference`1", isRuntimeClass: false); /// Registers the custom ABI type mapping for the "Windows.Foundation.IReference`1" WinRT type. public static void RegisterNullableUShortMapping() => RegisterCustomAbiTypeMapping( typeof(ushort?), typeof(ABI.System.Nullable_ushort), - "Windows.Foundation.IReference`1"); + "Windows.Foundation.IReference`1", isRuntimeClass: false); /// Registers the custom ABI type mapping for the "Windows.Foundation.IReference`1" WinRT type. public static void RegisterNullableUIntMapping() => RegisterCustomAbiTypeMapping( typeof(uint?), typeof(ABI.System.Nullable_uint), - "Windows.Foundation.IReference`1"); + "Windows.Foundation.IReference`1", isRuntimeClass: false); /// Registers the custom ABI type mapping for the "Windows.Foundation.IReference`1" WinRT type. public static void RegisterNullableLongMapping() => RegisterCustomAbiTypeMapping( typeof(long?), typeof(ABI.System.Nullable_long), - "Windows.Foundation.IReference`1"); + "Windows.Foundation.IReference`1", isRuntimeClass: false); /// Registers the custom ABI type mapping for the "Windows.Foundation.IReference`1" WinRT type. public static void RegisterNullableULongMapping() => RegisterCustomAbiTypeMapping( typeof(ulong?), typeof(ABI.System.Nullable_ulong), - "Windows.Foundation.IReference`1"); + "Windows.Foundation.IReference`1", isRuntimeClass: false); /// Registers the custom ABI type mapping for the "Windows.Foundation.IReference`1" WinRT type. public static void RegisterNullableFloatMapping() => RegisterCustomAbiTypeMapping( typeof(float?), typeof(ABI.System.Nullable_float), - "Windows.Foundation.IReference`1"); + "Windows.Foundation.IReference`1", isRuntimeClass: false); /// Registers the custom ABI type mapping for the "Windows.Foundation.IReference`1" WinRT type. public static void RegisterNullableDoubleMapping() => RegisterCustomAbiTypeMapping( typeof(double?), typeof(ABI.System.Nullable_double), - "Windows.Foundation.IReference`1"); + "Windows.Foundation.IReference`1", isRuntimeClass: false); /// Registers the custom ABI type mapping for the "Windows.Foundation.IReference`1" WinRT type. public static void RegisterNullableCharMapping() => RegisterCustomAbiTypeMapping( typeof(char?), typeof(ABI.System.Nullable_char), - "Windows.Foundation.IReference`1"); + "Windows.Foundation.IReference`1", isRuntimeClass: false); /// Registers the custom ABI type mapping for the "Windows.Foundation.IReference`1" WinRT type. public static void RegisterNullableBoolMapping() => RegisterCustomAbiTypeMapping( typeof(bool?), typeof(ABI.System.Nullable_bool), - "Windows.Foundation.IReference`1"); + "Windows.Foundation.IReference`1", isRuntimeClass: false); /// Registers the custom ABI type mapping for the "Windows.Foundation.IReference`1" WinRT type. public static void RegisterNullableGuidMapping() => RegisterCustomAbiTypeMapping( typeof(Guid?), typeof(ABI.System.Nullable_guid), - "Windows.Foundation.IReference`1"); + "Windows.Foundation.IReference`1", isRuntimeClass: false); /// Registers the custom ABI type mapping for the "Windows.Foundation.IReference`1" WinRT type. public static void RegisterNullableDateTimeOffsetMapping() => RegisterCustomAbiTypeMapping( typeof(DateTimeOffset?), typeof(ABI.System.Nullable_DateTimeOffset), - "Windows.Foundation.IReference`1"); + "Windows.Foundation.IReference`1", isRuntimeClass: false); /// Registers the custom ABI type mapping for the "Windows.Foundation.IReference`1" WinRT type. public static void RegisterNullableTimeSpanMapping() => RegisterCustomAbiTypeMapping( typeof(TimeSpan?), typeof(ABI.System.Nullable_TimeSpan), - "Windows.Foundation.IReference`1"); + "Windows.Foundation.IReference`1", isRuntimeClass: false); /// Registers the custom ABI type mapping for the "Windows.Foundation.DateTime" WinRT type. public static void RegisterDateTimeOffsetMapping() => RegisterCustomAbiTypeMapping( typeof(DateTimeOffset), typeof(ABI.System.DateTimeOffset), - "Windows.Foundation.DateTime"); + "Windows.Foundation.DateTime", isRuntimeClass: false); /// Registers the custom ABI type mapping for the "Windows.Foundation.HResult" WinRT type. public static void RegisterExceptionMapping() => RegisterCustomAbiTypeMapping( typeof(Exception), typeof(ABI.System.Exception), - "Windows.Foundation.HResult"); + "Windows.Foundation.HResult", isRuntimeClass: false); /// Registers the custom ABI type mapping for the "Windows.Foundation.TimeSpan" WinRT type. public static void RegisterTimeSpanMapping() => RegisterCustomAbiTypeMapping( typeof(TimeSpan), typeof(ABI.System.TimeSpan), - "Windows.Foundation.TimeSpan"); + "Windows.Foundation.TimeSpan", isRuntimeClass: false); /// Registers the custom ABI type mapping for the "Windows.Foundation.Uri" WinRT type. public static void RegisterUriMapping() => RegisterCustomAbiTypeMapping( typeof(Uri), typeof(ABI.System.Uri), - "Windows.Foundation.Uri"); + "Windows.Foundation.Uri", isRuntimeClass: true); /// Registers the custom ABI type mapping for the "Microsoft.UI.Xaml.Data.DataErrorsChangedEventArgs" WinRT type. public static void RegisterDataErrorsChangedEventArgsMapping() => RegisterCustomAbiTypeMapping( typeof(DataErrorsChangedEventArgs), typeof(ABI.System.ComponentModel.DataErrorsChangedEventArgs), - "Microsoft.UI.Xaml.Data.DataErrorsChangedEventArgs"); + "Microsoft.UI.Xaml.Data.DataErrorsChangedEventArgs", isRuntimeClass: true); /// Registers the custom ABI type mapping for the "Microsoft.UI.Xaml.Data.PropertyChangedEventArgs" WinRT type. public static void RegisterPropertyChangedEventArgsMapping() => RegisterCustomAbiTypeMapping( typeof(PropertyChangedEventArgs), typeof(ABI.System.ComponentModel.PropertyChangedEventArgs), - "Microsoft.UI.Xaml.Data.PropertyChangedEventArgs"); + "Microsoft.UI.Xaml.Data.PropertyChangedEventArgs", isRuntimeClass: true); /// Registers the custom ABI type mapping for the "Microsoft.UI.Xaml.Data.PropertyChangedEventHandler" WinRT type. public static void RegisterPropertyChangedEventHandlerMapping() => RegisterCustomAbiTypeMapping( typeof(PropertyChangedEventHandler), typeof(ABI.System.ComponentModel.PropertyChangedEventHandler), - "Microsoft.UI.Xaml.Data.PropertyChangedEventHandler"); + "Microsoft.UI.Xaml.Data.PropertyChangedEventHandler", isRuntimeClass: false); /// Registers the custom ABI type mapping for the "Microsoft.UI.Xaml.Data.INotifyDataErrorInfo" WinRT type. public static void RegisterINotifyDataErrorInfoMapping() => RegisterCustomAbiTypeMapping( typeof(INotifyDataErrorInfo), typeof(ABI.System.ComponentModel.INotifyDataErrorInfo), - "Microsoft.UI.Xaml.Data.INotifyDataErrorInfo"); + "Microsoft.UI.Xaml.Data.INotifyDataErrorInfo", isRuntimeClass: false); /// Registers the custom ABI type mapping for the "Microsoft.UI.Xaml.Data.INotifyPropertyChanged" WinRT type. public static void RegisterINotifyPropertyChangedMapping() => RegisterCustomAbiTypeMapping( typeof(INotifyPropertyChanged), typeof(ABI.System.ComponentModel.INotifyPropertyChanged), - "Microsoft.UI.Xaml.Data.INotifyPropertyChanged"); + "Microsoft.UI.Xaml.Data.INotifyPropertyChanged", isRuntimeClass: false); /// Registers the custom ABI type mapping for the "Microsoft.UI.Xaml.Interop.ICommand" WinRT type. public static void RegisterICommandMapping() => RegisterCustomAbiTypeMapping( typeof(ICommand), typeof(ABI.System.Windows.Input.ICommand), - "Microsoft.UI.Xaml.Interop.ICommand"); + "Microsoft.UI.Xaml.Interop.ICommand", isRuntimeClass: false); /// Registers the custom ABI type mapping for the "Microsoft.UI.Xaml.IXamlServiceProvider" WinRT type. public static void RegisterIServiceProviderMapping() => RegisterCustomAbiTypeMapping( typeof(IServiceProvider), typeof(ABI.System.IServiceProvider), - "Microsoft.UI.Xaml.IXamlServiceProvider"); + "Microsoft.UI.Xaml.IXamlServiceProvider", isRuntimeClass: false); /// Registers the custom ABI type mapping for the "Windows.Foundation.EventHandler`1" WinRT type. public static void RegisterEventHandlerOpenGenericMapping() => RegisterCustomAbiTypeMapping( typeof(EventHandler<>), typeof(ABI.System.EventHandler<>), - "Windows.Foundation.EventHandler`1"); + "Windows.Foundation.EventHandler`1", isRuntimeClass: false); /// Registers the custom ABI type mapping for the "Windows.Foundation.Collections.IKeyValuePair`2" WinRT type. public static void RegisterKeyValuePairOpenGenericMapping() => RegisterCustomAbiTypeMapping( typeof(KeyValuePair<,>), typeof(ABI.System.Collections.Generic.KeyValuePair<,>), - "Windows.Foundation.Collections.IKeyValuePair`2"); + "Windows.Foundation.Collections.IKeyValuePair`2", isRuntimeClass: false); /// Registers the custom ABI type mapping for the "Windows.Foundation.Collections.IIterable`1" WinRT type. public static void RegisterIEnumerableOpenGenericMapping() => RegisterCustomAbiTypeMapping( typeof(IEnumerable<>), typeof(ABI.System.Collections.Generic.IEnumerable<>), - "Windows.Foundation.Collections.IIterable`1"); + "Windows.Foundation.Collections.IIterable`1", isRuntimeClass: false); /// Registers the custom ABI type mapping for the "Windows.Foundation.Collections.IIterator`1" WinRT type. public static void RegisterIEnumeratorOpenGenericMapping() => RegisterCustomAbiTypeMapping( typeof(IEnumerator<>), typeof(ABI.System.Collections.Generic.IEnumerator<>), - "Windows.Foundation.Collections.IIterator`1"); + "Windows.Foundation.Collections.IIterator`1", isRuntimeClass: false); /// Registers the custom ABI type mapping for the "Windows.Foundation.Collections.IVector`1" WinRT type. public static void RegisterIListOpenGenericMapping() => RegisterCustomAbiTypeMapping( typeof(IList<>), typeof(ABI.System.Collections.Generic.IList<>), - "Windows.Foundation.Collections.IVector`1"); + "Windows.Foundation.Collections.IVector`1", isRuntimeClass: false); /// Registers the custom ABI type mapping for the "Windows.Foundation.Collections.IVectorView`1" WinRT type. public static void RegisterIReadOnlyListOpenGenericMapping() => RegisterCustomAbiTypeMapping( typeof(IReadOnlyList<>), typeof(ABI.System.Collections.Generic.IReadOnlyList<>), - "Windows.Foundation.Collections.IVectorView`1"); + "Windows.Foundation.Collections.IVectorView`1", isRuntimeClass: false); /// Registers the custom ABI type mapping for the "Windows.Foundation.Collections.IMap`2" WinRT type. public static void RegisterIDictionaryOpenGenericMapping() => RegisterCustomAbiTypeMapping( typeof(IDictionary<,>), typeof(ABI.System.Collections.Generic.IDictionary<,>), - "Windows.Foundation.Collections.IMap`2"); + "Windows.Foundation.Collections.IMap`2", isRuntimeClass: false); /// Registers the custom ABI type mapping for the "Windows.Foundation.Collections.IMapView`2" WinRT type. public static void RegisterIReadOnlyDictionaryOpenGenericMapping() => RegisterCustomAbiTypeMapping( typeof(IReadOnlyDictionary<,>), typeof(ABI.System.Collections.Generic.IReadOnlyDictionary<,>), - "Windows.Foundation.Collections.IMapView`2"); + "Windows.Foundation.Collections.IMapView`2", isRuntimeClass: false); /// Registers the custom ABI type mapping for the "Windows.Foundation.IClosable" WinRT type. public static void RegisterIDisposableMapping() => RegisterCustomAbiTypeMapping( typeof(IDisposable), typeof(ABI.System.IDisposable), - "Windows.Foundation.IClosable"); + "Windows.Foundation.IClosable", isRuntimeClass: false); /// Registers the custom ABI type mapping for the "Microsoft.UI.Xaml.Interop.IBindableIterable" WinRT type. public static void RegisterIEnumerableMapping() => RegisterCustomAbiTypeMapping( typeof(IEnumerable), typeof(ABI.System.Collections.IEnumerable), - "Microsoft.UI.Xaml.Interop.IBindableIterable"); + "Microsoft.UI.Xaml.Interop.IBindableIterable", isRuntimeClass: false); /// Registers the custom ABI type mapping for the "Microsoft.UI.Xaml.Interop.IBindableVector" WinRT type. public static void RegisterIListMapping() => RegisterCustomAbiTypeMapping( typeof(IList), typeof(ABI.System.Collections.IList), - "Microsoft.UI.Xaml.Interop.IBindableVector"); + "Microsoft.UI.Xaml.Interop.IBindableVector", isRuntimeClass: false); /// Registers the custom ABI type mapping for the "Microsoft.UI.Xaml.Interop.INotifyCollectionChanged" WinRT type. public static void RegisterINotifyCollectionChangedMapping() => RegisterCustomAbiTypeMapping( typeof(INotifyCollectionChanged), typeof(ABI.System.Collections.Specialized.INotifyCollectionChanged), - "Microsoft.UI.Xaml.Interop.INotifyCollectionChanged"); + "Microsoft.UI.Xaml.Interop.INotifyCollectionChanged", isRuntimeClass: false); /// Registers the custom ABI type mapping for the "Microsoft.UI.Xaml.Interop.NotifyCollectionChangedEventArgs" WinRT type. public static void RegisterNotifyCollectionChangedActionMapping() => RegisterCustomAbiTypeMapping( typeof(NotifyCollectionChangedAction), typeof(ABI.System.Collections.Specialized.NotifyCollectionChangedAction), - "Microsoft.UI.Xaml.Interop.NotifyCollectionChangedEventArgs"); + "Microsoft.UI.Xaml.Interop.NotifyCollectionChangedEventArgs", isRuntimeClass: true); /// Registers the custom ABI type mapping for the "Microsoft.UI.Xaml.Interop.NotifyCollectionChangedEventHandler" WinRT type. public static void RegisterNotifyCollectionChangedEventHandlerMapping() => RegisterCustomAbiTypeMapping( typeof(NotifyCollectionChangedEventHandler), typeof(ABI.System.Collections.Specialized.NotifyCollectionChangedEventHandler), - "Microsoft.UI.Xaml.Interop.NotifyCollectionChangedEventHandler"); + "Microsoft.UI.Xaml.Interop.NotifyCollectionChangedEventHandler", isRuntimeClass: false); /// Registers the custom ABI type mapping for the "Windows.Foundation.Numerics.Matrix3x2" WinRT type. public static void RegisterMatrix3x2Mapping() => RegisterCustomAbiTypeMapping( typeof(Matrix3x2), typeof(ABI.System.Numerics.Matrix3x2), - "Windows.Foundation.Numerics.Matrix3x2"); + "Windows.Foundation.Numerics.Matrix3x2", isRuntimeClass: false); /// Registers the custom ABI type mapping for the "Windows.Foundation.Numerics.Matrix4x4" WinRT type. public static void RegisterMatrix4x4Mapping() => RegisterCustomAbiTypeMapping( typeof(Matrix4x4), typeof(ABI.System.Numerics.Matrix4x4), - "Windows.Foundation.Numerics.Matrix4x4"); + "Windows.Foundation.Numerics.Matrix4x4", isRuntimeClass: false); /// Registers the custom ABI type mapping for the "Windows.Foundation.Numerics.Plane" WinRT type. public static void RegisterPlaneMapping() => RegisterCustomAbiTypeMapping( typeof(Plane), typeof(ABI.System.Numerics.Plane), - "Windows.Foundation.Numerics.Plane"); + "Windows.Foundation.Numerics.Plane", isRuntimeClass: false); /// Registers the custom ABI type mapping for the "Windows.Foundation.Numerics.Quaternion" WinRT type. public static void RegisterQuaternionMapping() => RegisterCustomAbiTypeMapping( typeof(Quaternion), typeof(ABI.System.Numerics.Quaternion), - "Windows.Foundation.Numerics.Quaternion"); + "Windows.Foundation.Numerics.Quaternion", isRuntimeClass: false); /// Registers the custom ABI type mapping for the "Windows.Foundation.Numerics.Vector2" WinRT type. public static void RegisterVector2Mapping() => RegisterCustomAbiTypeMapping( typeof(Vector2), typeof(ABI.System.Numerics.Vector2), - "Windows.Foundation.Numerics.Vector2"); + "Windows.Foundation.Numerics.Vector2", isRuntimeClass: false); /// Registers the custom ABI type mapping for the "Windows.Foundation.Numerics.Vector3" WinRT type. public static void RegisterVector3Mapping() => RegisterCustomAbiTypeMapping( typeof(Vector3), typeof(ABI.System.Numerics.Vector3), - "Windows.Foundation.Numerics.Vector3"); + "Windows.Foundation.Numerics.Vector3", isRuntimeClass: false); /// Registers the custom ABI type mapping for the "Windows.Foundation.Numerics.Vector4" WinRT type. public static void RegisterVector4Mapping() => RegisterCustomAbiTypeMapping( typeof(Vector4), typeof(ABI.System.Numerics.Vector4), - "Windows.Foundation.Numerics.Vector4"); + "Windows.Foundation.Numerics.Vector4", isRuntimeClass: false); + + /// Registers the custom ABI type mapping for the type. + public static void RegisterEventHandlerMapping() => RegisterCustomAbiTypeMapping( + typeof(EventHandler), + typeof(ABI.System.EventHandler)); } } \ No newline at end of file diff --git a/src/WinRT.Runtime/Projections.CustomTypeMappings.net5.tt b/src/WinRT.Runtime/Projections.CustomTypeMappings.net5.tt index 57451f74d..0b0bb6d92 100644 --- a/src/WinRT.Runtime/Projections.CustomTypeMappings.net5.tt +++ b/src/WinRT.Runtime/Projections.CustomTypeMappings.net5.tt @@ -19,10 +19,6 @@ namespace WinRT /// partial class Projections { - /// Registers the custom ABI type mapping for the type. - public static void RegisterEventHandlerMapping() => RegisterCustomAbiTypeMapping( - typeof(EventHandler), - typeof(ABI.System.EventHandler)); <# // Types for 'RegisterCustomAbiTypeMapping' foreach (var type in new (string Public, string Abi, string Name, string Hint, bool IsRuntimeClass)[] { @@ -74,29 +70,42 @@ foreach (var type in new (string Public, string Abi, string Name, string Hint, b ("Quaternion", "ABI.System.Numerics.Quaternion", "Windows.Foundation.Numerics.Quaternion", null, false), ("Vector2", "ABI.System.Numerics.Vector2", "Windows.Foundation.Numerics.Vector2", null, false), ("Vector3", "ABI.System.Numerics.Vector3", "Windows.Foundation.Numerics.Vector3", null, false), - ("Vector4", "ABI.System.Numerics.Vector4", "Windows.Foundation.Numerics.Vector4", null, false) }) + ("Vector4", "ABI.System.Numerics.Vector4", "Windows.Foundation.Numerics.Vector4", null, false), + ("EventHandler", "ABI.System.EventHandler", null, null, false) }) { - var methodTypeName = type.Hint; + var methodTypeName = type.Hint ?? type.Public; // If the hint isn't available, automatically derive the name. For generic types, // we strip the '<>' from the name and append "OpenGeneric" as a suffix. - if (methodTypeName == null) + if (type.Hint == null) { - methodTypeName = type.Public; - if (type.Name.Contains("`")) methodTypeName = methodTypeName.Substring(0, methodTypeName.IndexOf('<')); - if (type.Name.Contains("`")) methodTypeName += "OpenGeneric"; + if (type.Public.Contains("<")) methodTypeName = methodTypeName.Substring(0, methodTypeName.IndexOf('<')); + if (type.Public.Contains("<")) methodTypeName += "OpenGeneric"; } var methodFullName = $"Register{methodTypeName}Mapping"; WriteLine(""); + + if (type.Name != null) + { #> /// Registers the custom ABI type mapping for the "<#=type.Name#>" WinRT type. public static void <#=methodFullName#>() => RegisterCustomAbiTypeMapping( typeof(<#=type.Public#>), typeof(<#=type.Abi#>), - "<#=type.Name#>"); + "<#=type.Name#>", isRuntimeClass: <#=type.IsRuntimeClass.ToString().ToLowerInvariant()#>); <# + } + else + { +#> + /// Registers the custom ABI type mapping for the type. + public static void <#=methodFullName#>() => RegisterCustomAbiTypeMapping( + typeof(<#=type.Public#>), + typeof(<#=type.Abi#>)); +<# + } } #> } From bbc3b0bdc621fca21197f4f24aaa35a2e07ac947 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 31 Jan 2024 16:25:20 +0100 Subject: [PATCH 15/20] Refactor generated method name logic --- .../Projections.CustomTypeMappings.net5.tt | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/WinRT.Runtime/Projections.CustomTypeMappings.net5.tt b/src/WinRT.Runtime/Projections.CustomTypeMappings.net5.tt index 0b0bb6d92..d8e50fb27 100644 --- a/src/WinRT.Runtime/Projections.CustomTypeMappings.net5.tt +++ b/src/WinRT.Runtime/Projections.CustomTypeMappings.net5.tt @@ -20,6 +20,22 @@ namespace WinRT partial class Projections { <# +// Helper method to get the generated method name +static string GetMethodName(string name, string hint) +{ + var methodTypeName = hint ?? name; + + // If the hint isn't available, automatically derive the name. For generic types, + // we strip the '<>' from the name and append "OpenGeneric" as a suffix. + if (hint == null) + { + if (name.Contains("<")) methodTypeName = methodTypeName.Substring(0, methodTypeName.IndexOf('<')); + if (name.Contains("<")) methodTypeName += "OpenGeneric"; + } + + return $"Register{methodTypeName}Mapping"; +} + // Types for 'RegisterCustomAbiTypeMapping' foreach (var type in new (string Public, string Abi, string Name, string Hint, bool IsRuntimeClass)[] { ("EventRegistrationToken", "ABI.WinRT.EventRegistrationToken", "Windows.Foundation.EventRegistrationToken", null, false), @@ -73,25 +89,13 @@ foreach (var type in new (string Public, string Abi, string Name, string Hint, b ("Vector4", "ABI.System.Numerics.Vector4", "Windows.Foundation.Numerics.Vector4", null, false), ("EventHandler", "ABI.System.EventHandler", null, null, false) }) { - var methodTypeName = type.Hint ?? type.Public; - - // If the hint isn't available, automatically derive the name. For generic types, - // we strip the '<>' from the name and append "OpenGeneric" as a suffix. - if (type.Hint == null) - { - if (type.Public.Contains("<")) methodTypeName = methodTypeName.Substring(0, methodTypeName.IndexOf('<')); - if (type.Public.Contains("<")) methodTypeName += "OpenGeneric"; - } - - var methodFullName = $"Register{methodTypeName}Mapping"; - WriteLine(""); if (type.Name != null) { #> /// Registers the custom ABI type mapping for the "<#=type.Name#>" WinRT type. - public static void <#=methodFullName#>() => RegisterCustomAbiTypeMapping( + public static void <#=GetMethodName(type.Public, type.Hint)#>() => RegisterCustomAbiTypeMapping( typeof(<#=type.Public#>), typeof(<#=type.Abi#>), "<#=type.Name#>", isRuntimeClass: <#=type.IsRuntimeClass.ToString().ToLowerInvariant()#>); @@ -101,7 +105,7 @@ foreach (var type in new (string Public, string Abi, string Name, string Hint, b { #> /// Registers the custom ABI type mapping for the type. - public static void <#=methodFullName#>() => RegisterCustomAbiTypeMapping( + public static void <#=GetMethodName(type.Public, type.Hint)#>() => RegisterCustomAbiTypeMapping( typeof(<#=type.Public#>), typeof(<#=type.Abi#>)); <# From 13efd95243a6c0eeabb1cbe515d69124978b5ab1 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 31 Jan 2024 16:39:23 +0100 Subject: [PATCH 16/20] Switch RegisterCustomTypeToHelperTypeMapping too --- ...cs => Projections.CustomTypeMappings.g.cs} | 46 +++++++++++++++- .../Projections.CustomTypeMappings.net5.cs | 54 ------------------- ...5.tt => Projections.CustomTypeMappings.tt} | 31 ++++++++++- src/WinRT.Runtime/WinRT.Runtime.csproj | 5 -- 4 files changed, 75 insertions(+), 61 deletions(-) rename src/WinRT.Runtime/{Projections.CustomTypeMappings.net5.g.cs => Projections.CustomTypeMappings.g.cs} (88%) delete mode 100644 src/WinRT.Runtime/Projections.CustomTypeMappings.net5.cs rename src/WinRT.Runtime/{Projections.CustomTypeMappings.net5.tt => Projections.CustomTypeMappings.tt} (86%) diff --git a/src/WinRT.Runtime/Projections.CustomTypeMappings.net5.g.cs b/src/WinRT.Runtime/Projections.CustomTypeMappings.g.cs similarity index 88% rename from src/WinRT.Runtime/Projections.CustomTypeMappings.net5.g.cs rename to src/WinRT.Runtime/Projections.CustomTypeMappings.g.cs index 060878ec0..0969e1ea8 100644 --- a/src/WinRT.Runtime/Projections.CustomTypeMappings.net5.g.cs +++ b/src/WinRT.Runtime/Projections.CustomTypeMappings.g.cs @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +#if NET + using System; using System.Collections; using System.Collections.Generic; @@ -315,5 +317,47 @@ public static void RegisterVector4Mapping() => RegisterCustomAbiTypeMapping( public static void RegisterEventHandlerMapping() => RegisterCustomAbiTypeMapping( typeof(EventHandler), typeof(ABI.System.EventHandler)); + + /// Registers the custom ABI type mapping for the type. + public static void RegisterIMapOpenGenericMapping() => RegisterCustomTypeToHelperTypeMapping( + typeof(IMap<,>), + typeof(ABI.System.Collections.Generic.IDictionary<,>)); + + /// Registers the custom ABI type mapping for the type. + public static void RegisterIVectorOpenGenericMapping() => RegisterCustomTypeToHelperTypeMapping( + typeof(IVector<>), + typeof(ABI.System.Collections.Generic.IList<>)); + + /// Registers the custom ABI type mapping for the type. + public static void RegisterIMapViewOpenGenericMapping() => RegisterCustomTypeToHelperTypeMapping( + typeof(IMapView<,>), + typeof(ABI.System.Collections.Generic.IReadOnlyDictionary<,>)); + + /// Registers the custom ABI type mapping for the type. + public static void RegisterIVectorViewOpenGenericMapping() => RegisterCustomTypeToHelperTypeMapping( + typeof(IVectorView<>), + typeof(ABI.System.Collections.Generic.IReadOnlyList<>)); + + /// Registers the custom ABI type mapping for the type. + public static void RegisterIBindableVectorMapping() => RegisterCustomTypeToHelperTypeMapping( + typeof(IBindableVector), + typeof(ABI.System.Collections.IList)); + + /// Registers the custom ABI type mapping for the type. + public static void RegisterICollectionOpenGenericMapping() => RegisterCustomTypeToHelperTypeMapping( + typeof(ICollection<>), + typeof(ABI.System.Collections.Generic.ICollection<>)); + + /// Registers the custom ABI type mapping for the type. + public static void RegisterIReadOnlyCollectionOpenGenericMapping() => RegisterCustomTypeToHelperTypeMapping( + typeof(IReadOnlyCollection<>), + typeof(ABI.System.Collections.Generic.IReadOnlyCollection<>)); + + /// Registers the custom ABI type mapping for the type. + public static void RegisterICollectionMapping() => RegisterCustomTypeToHelperTypeMapping( + typeof(ICollection), + typeof(ABI.System.Collections.ICollection)); } -} \ No newline at end of file +} + +#endif \ No newline at end of file diff --git a/src/WinRT.Runtime/Projections.CustomTypeMappings.net5.cs b/src/WinRT.Runtime/Projections.CustomTypeMappings.net5.cs deleted file mode 100644 index 538f35036..000000000 --- a/src/WinRT.Runtime/Projections.CustomTypeMappings.net5.cs +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -using System.Collections; -using System.Collections.Generic; -using Microsoft.UI.Xaml.Interop; -using Windows.Foundation.Collections; - -namespace WinRT -{ - /// - partial class Projections - { - /// Registers the custom ABI type mapping for the type. - public static void RegisterIMapOpenGenericMapping() => RegisterCustomTypeToHelperTypeMapping( - typeof(IMap<,>), - typeof(ABI.System.Collections.Generic.IDictionary<,>)); - - /// Registers the custom ABI type mapping for the type. - public static void RegisterIVectorOpenGenericMapping() => RegisterCustomTypeToHelperTypeMapping( - typeof(IVector<>), - typeof(ABI.System.Collections.Generic.IList<>)); - - /// Registers the custom ABI type mapping for the type. - public static void RegisterIMapViewOpenGenericMapping() => RegisterCustomTypeToHelperTypeMapping( - typeof(IMapView<,>), - typeof(ABI.System.Collections.Generic.IReadOnlyDictionary<,>)); - - /// Registers the custom ABI type mapping for the type. - public static void RegisterIVectorViewOpenGenericMapping() => RegisterCustomTypeToHelperTypeMapping( - typeof(IVectorView<>), - typeof(ABI.System.Collections.Generic.IReadOnlyList<>)); - - /// Registers the custom ABI type mapping for the type. - public static void RegisterIBindableVectorMapping() => RegisterCustomTypeToHelperTypeMapping( - typeof(IBindableVector), - typeof(ABI.System.Collections.IList)); - - /// Registers the custom ABI type mapping for the type. - public static void RegisterICollectionOpenGenericMapping() => RegisterCustomTypeToHelperTypeMapping( - typeof(ICollection<>), - typeof(ABI.System.Collections.Generic.ICollection<>)); - - /// Registers the custom ABI type mapping for the type. - public static void RegisterIReadOnlyCollectionOpenGenericMapping() => RegisterCustomTypeToHelperTypeMapping( - typeof(IReadOnlyCollection<>), - typeof(ABI.System.Collections.Generic.IReadOnlyCollection<>)); - - /// Registers the custom ABI type mapping for the type. - public static void RegisterICollectionMapping() => RegisterCustomTypeToHelperTypeMapping( - typeof(ICollection), - typeof(ABI.System.Collections.ICollection)); - } -} \ No newline at end of file diff --git a/src/WinRT.Runtime/Projections.CustomTypeMappings.net5.tt b/src/WinRT.Runtime/Projections.CustomTypeMappings.tt similarity index 86% rename from src/WinRT.Runtime/Projections.CustomTypeMappings.net5.tt rename to src/WinRT.Runtime/Projections.CustomTypeMappings.tt index d8e50fb27..b967128d1 100644 --- a/src/WinRT.Runtime/Projections.CustomTypeMappings.net5.tt +++ b/src/WinRT.Runtime/Projections.CustomTypeMappings.tt @@ -4,6 +4,8 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +#if NET + using System; using System.Collections; using System.Collections.Generic; @@ -111,6 +113,33 @@ foreach (var type in new (string Public, string Abi, string Name, string Hint, b <# } } + +// Types for 'RegisterCustomTypeToHelperTypeMapping' +foreach (var type in new (string Public, string Helper)[] { + ("IMap<,>", "ABI.System.Collections.Generic.IDictionary<,>"), + ("IVector<>", "ABI.System.Collections.Generic.IList<>"), + ("IMapView<,>", "ABI.System.Collections.Generic.IReadOnlyDictionary<,>"), + ("IVectorView<>", "ABI.System.Collections.Generic.IReadOnlyList<>"), + ("IBindableVector", "ABI.System.Collections.IList"), + ("ICollection<>", "ABI.System.Collections.Generic.ICollection<>"), + ("IReadOnlyCollection<>", "ABI.System.Collections.Generic.IReadOnlyCollection<>"), + ("ICollection", "ABI.System.Collections.ICollection") }) +{ + string xmlName = type.Public; + + if (type.Public.EndsWith("<>")) xmlName = $"{xmlName.Substring(0, xmlName.IndexOf('<'))}{{T}}"; + if (type.Public.EndsWith("<,>")) xmlName = $"{xmlName.Substring(0, xmlName.IndexOf('<'))}{{K, V}}"; + + WriteLine(""); +#> + /// Registers the custom ABI type mapping for the type. + public static void <#=GetMethodName(type.Public, null)#>() => RegisterCustomTypeToHelperTypeMapping( + typeof(<#=type.Public#>), + typeof(<#=type.Helper#>)); +<# +} #> } -} \ No newline at end of file +} + +#endif \ No newline at end of file diff --git a/src/WinRT.Runtime/WinRT.Runtime.csproj b/src/WinRT.Runtime/WinRT.Runtime.csproj index 0e0cc51c9..f2836b8ec 100644 --- a/src/WinRT.Runtime/WinRT.Runtime.csproj +++ b/src/WinRT.Runtime/WinRT.Runtime.csproj @@ -84,11 +84,6 @@ - - - Projections.CustomTypeMappings.net5.g.cs - - From 2344c9d27b19cdc4f01b57e1fdbb126eb7896303 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 31 Jan 2024 16:41:20 +0100 Subject: [PATCH 17/20] Minor code refactoring to TT file --- .../Projections.CustomTypeMappings.tt | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/src/WinRT.Runtime/Projections.CustomTypeMappings.tt b/src/WinRT.Runtime/Projections.CustomTypeMappings.tt index b967128d1..b8d744c3d 100644 --- a/src/WinRT.Runtime/Projections.CustomTypeMappings.tt +++ b/src/WinRT.Runtime/Projections.CustomTypeMappings.tt @@ -39,7 +39,8 @@ static string GetMethodName(string name, string hint) } // Types for 'RegisterCustomAbiTypeMapping' -foreach (var type in new (string Public, string Abi, string Name, string Hint, bool IsRuntimeClass)[] { +var registerCustomAbiTypeMappings = new (string Public, string Abi, string Name, string Hint, bool IsRuntimeClass)[] +{ ("EventRegistrationToken", "ABI.WinRT.EventRegistrationToken", "Windows.Foundation.EventRegistrationToken", null, false), ("Nullable<>", "ABI.System.Nullable<>", "Windows.Foundation.IReference`1", null, false), ("int?", "ABI.System.Nullable_int", "Windows.Foundation.IReference`1", "NullableInt", false), @@ -89,7 +90,24 @@ foreach (var type in new (string Public, string Abi, string Name, string Hint, b ("Vector2", "ABI.System.Numerics.Vector2", "Windows.Foundation.Numerics.Vector2", null, false), ("Vector3", "ABI.System.Numerics.Vector3", "Windows.Foundation.Numerics.Vector3", null, false), ("Vector4", "ABI.System.Numerics.Vector4", "Windows.Foundation.Numerics.Vector4", null, false), - ("EventHandler", "ABI.System.EventHandler", null, null, false) }) + ("EventHandler", "ABI.System.EventHandler", null, null, false) +}; + +// Types for 'RegisterCustomTypeToHelperTypeMapping' +var registerCustomTypeToHelperTypeMapping = new (string Public, string Helper)[] +{ + ("IMap<,>", "ABI.System.Collections.Generic.IDictionary<,>"), + ("IVector<>", "ABI.System.Collections.Generic.IList<>"), + ("IMapView<,>", "ABI.System.Collections.Generic.IReadOnlyDictionary<,>"), + ("IVectorView<>", "ABI.System.Collections.Generic.IReadOnlyList<>"), + ("IBindableVector", "ABI.System.Collections.IList"), + ("ICollection<>", "ABI.System.Collections.Generic.ICollection<>"), + ("IReadOnlyCollection<>", "ABI.System.Collections.Generic.IReadOnlyCollection<>"), + ("ICollection", "ABI.System.Collections.ICollection") +}; + +// 'RegisterCustomAbiTypeMapping' methods +foreach (var type in registerCustomAbiTypeMappings) { WriteLine(""); @@ -114,16 +132,8 @@ foreach (var type in new (string Public, string Abi, string Name, string Hint, b } } -// Types for 'RegisterCustomTypeToHelperTypeMapping' -foreach (var type in new (string Public, string Helper)[] { - ("IMap<,>", "ABI.System.Collections.Generic.IDictionary<,>"), - ("IVector<>", "ABI.System.Collections.Generic.IList<>"), - ("IMapView<,>", "ABI.System.Collections.Generic.IReadOnlyDictionary<,>"), - ("IVectorView<>", "ABI.System.Collections.Generic.IReadOnlyList<>"), - ("IBindableVector", "ABI.System.Collections.IList"), - ("ICollection<>", "ABI.System.Collections.Generic.ICollection<>"), - ("IReadOnlyCollection<>", "ABI.System.Collections.Generic.IReadOnlyCollection<>"), - ("ICollection", "ABI.System.Collections.ICollection") }) +// 'RegisterCustomTypeToHelperTypeMapping' methods +foreach (var type in registerCustomTypeToHelperTypeMapping) { string xmlName = type.Public; From db7f46e8f9a585fdecda6a8bcb80b082a460c370 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 31 Jan 2024 16:48:55 +0100 Subject: [PATCH 18/20] Add missing mapped type --- src/WinRT.Runtime/Projections.CustomTypeMappings.g.cs | 6 ++++++ src/WinRT.Runtime/Projections.CustomTypeMappings.tt | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/WinRT.Runtime/Projections.CustomTypeMappings.g.cs b/src/WinRT.Runtime/Projections.CustomTypeMappings.g.cs index 0969e1ea8..47c35a903 100644 --- a/src/WinRT.Runtime/Projections.CustomTypeMappings.g.cs +++ b/src/WinRT.Runtime/Projections.CustomTypeMappings.g.cs @@ -263,6 +263,12 @@ public static void RegisterINotifyCollectionChangedMapping() => RegisterCustomAb public static void RegisterNotifyCollectionChangedActionMapping() => RegisterCustomAbiTypeMapping( typeof(NotifyCollectionChangedAction), typeof(ABI.System.Collections.Specialized.NotifyCollectionChangedAction), + "Microsoft.UI.Xaml.Interop.NotifyCollectionChangedEventArgs", isRuntimeClass: false); + + /// Registers the custom ABI type mapping for the "Microsoft.UI.Xaml.Interop.NotifyCollectionChangedEventArgs" WinRT type. + public static void RegisterNotifyCollectionChangedEventArgsMapping() => RegisterCustomAbiTypeMapping( + typeof(NotifyCollectionChangedEventArgs), + typeof(ABI.System.Collections.Specialized.NotifyCollectionChangedEventArgs), "Microsoft.UI.Xaml.Interop.NotifyCollectionChangedEventArgs", isRuntimeClass: true); /// Registers the custom ABI type mapping for the "Microsoft.UI.Xaml.Interop.NotifyCollectionChangedEventHandler" WinRT type. diff --git a/src/WinRT.Runtime/Projections.CustomTypeMappings.tt b/src/WinRT.Runtime/Projections.CustomTypeMappings.tt index b8d744c3d..2b7b16c3a 100644 --- a/src/WinRT.Runtime/Projections.CustomTypeMappings.tt +++ b/src/WinRT.Runtime/Projections.CustomTypeMappings.tt @@ -81,7 +81,8 @@ var registerCustomAbiTypeMappings = new (string Public, string Abi, string Name, ("IEnumerable", "ABI.System.Collections.IEnumerable", "Microsoft.UI.Xaml.Interop.IBindableIterable", null, false), ("IList", "ABI.System.Collections.IList", "Microsoft.UI.Xaml.Interop.IBindableVector", null, false), ("INotifyCollectionChanged", "ABI.System.Collections.Specialized.INotifyCollectionChanged", "Microsoft.UI.Xaml.Interop.INotifyCollectionChanged", null, false), - ("NotifyCollectionChangedAction", "ABI.System.Collections.Specialized.NotifyCollectionChangedAction", "Microsoft.UI.Xaml.Interop.NotifyCollectionChangedEventArgs", null, true), + ("NotifyCollectionChangedAction", "ABI.System.Collections.Specialized.NotifyCollectionChangedAction", "Microsoft.UI.Xaml.Interop.NotifyCollectionChangedEventArgs", null, false), + ("NotifyCollectionChangedEventArgs", "ABI.System.Collections.Specialized.NotifyCollectionChangedEventArgs", "Microsoft.UI.Xaml.Interop.NotifyCollectionChangedEventArgs", null, true), ("NotifyCollectionChangedEventHandler", "ABI.System.Collections.Specialized.NotifyCollectionChangedEventHandler", "Microsoft.UI.Xaml.Interop.NotifyCollectionChangedEventHandler", null, false), ("Matrix3x2", "ABI.System.Numerics.Matrix3x2", "Windows.Foundation.Numerics.Matrix3x2", null, false), ("Matrix4x4", "ABI.System.Numerics.Matrix4x4", "Windows.Foundation.Numerics.Matrix4x4", null, false), From 334876552c50824fc715dff7514dc890ab5bd8ed Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 31 Jan 2024 16:56:43 +0100 Subject: [PATCH 19/20] Generate guard statements for each method --- .../Projections.CustomTypeMappings.g.cs | 1331 ++++++++++++++--- .../Projections.CustomTypeMappings.tt | 76 +- 2 files changed, 1170 insertions(+), 237 deletions(-) diff --git a/src/WinRT.Runtime/Projections.CustomTypeMappings.g.cs b/src/WinRT.Runtime/Projections.CustomTypeMappings.g.cs index 47c35a903..9adaedf07 100644 --- a/src/WinRT.Runtime/Projections.CustomTypeMappings.g.cs +++ b/src/WinRT.Runtime/Projections.CustomTypeMappings.g.cs @@ -9,6 +9,7 @@ using System.Collections.Specialized; using System.ComponentModel; using System.Numerics; +using System.Threading; using System.Windows.Input; using Microsoft.UI.Xaml.Interop; using Windows.Foundation.Collections; @@ -18,351 +19,1227 @@ namespace WinRT /// partial class Projections { + private static int _EventRegistrationToken; + private static int _Nullable__; + private static int _int_; + private static int _byte_; + private static int _sbyte_; + private static int _short_; + private static int _ushort_; + private static int _uint_; + private static int _long_; + private static int _ulong_; + private static int _float_; + private static int _double_; + private static int _char_; + private static int _bool_; + private static int _Guid_; + private static int _DateTimeOffset_; + private static int _TimeSpan_; + private static int _DateTimeOffset; + private static int _Exception; + private static int _TimeSpan; + private static int _Uri; + private static int _DataErrorsChangedEventArgs; + private static int _PropertyChangedEventArgs; + private static int _PropertyChangedEventHandler; + private static int _INotifyDataErrorInfo; + private static int _INotifyPropertyChanged; + private static int _ICommand; + private static int _IServiceProvider; + private static int _EventHandler__; + private static int _KeyValuePair___; + private static int _IEnumerable__; + private static int _IEnumerator__; + private static int _IList__; + private static int _IReadOnlyList__; + private static int _IDictionary___; + private static int _IReadOnlyDictionary___; + private static int _IDisposable; + private static int _IEnumerable; + private static int _IList; + private static int _INotifyCollectionChanged; + private static int _NotifyCollectionChangedAction; + private static int _NotifyCollectionChangedEventArgs; + private static int _NotifyCollectionChangedEventHandler; + private static int _Matrix3x2; + private static int _Matrix4x4; + private static int _Plane; + private static int _Quaternion; + private static int _Vector2; + private static int _Vector3; + private static int _Vector4; + private static int _EventHandler; + private static int _IMap___; + private static int _IVector__; + private static int _IMapView___; + private static int _IVectorView__; + private static int _IBindableVector; + private static int _ICollection__; + private static int _IReadOnlyCollection__; + private static int _ICollection; /// Registers the custom ABI type mapping for the "Windows.Foundation.EventRegistrationToken" WinRT type. - public static void RegisterEventRegistrationTokenMapping() => RegisterCustomAbiTypeMapping( - typeof(EventRegistrationToken), - typeof(ABI.WinRT.EventRegistrationToken), - "Windows.Foundation.EventRegistrationToken", isRuntimeClass: false); + public static void RegisterEventRegistrationTokenMapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _EventRegistrationToken, 1, 0) == 1) + { + return; + } + + RegisterCustomAbiTypeMapping( + typeof(EventRegistrationToken), + typeof(ABI.WinRT.EventRegistrationToken), + "Windows.Foundation.EventRegistrationToken", + isRuntimeClass: false); + } /// Registers the custom ABI type mapping for the "Windows.Foundation.IReference`1" WinRT type. - public static void RegisterNullableOpenGenericMapping() => RegisterCustomAbiTypeMapping( - typeof(Nullable<>), - typeof(ABI.System.Nullable<>), - "Windows.Foundation.IReference`1", isRuntimeClass: false); + public static void RegisterNullableOpenGenericMapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _Nullable__, 1, 0) == 1) + { + return; + } + + RegisterCustomAbiTypeMapping( + typeof(Nullable<>), + typeof(ABI.System.Nullable<>), + "Windows.Foundation.IReference`1", + isRuntimeClass: false); + } /// Registers the custom ABI type mapping for the "Windows.Foundation.IReference`1" WinRT type. - public static void RegisterNullableIntMapping() => RegisterCustomAbiTypeMapping( - typeof(int?), - typeof(ABI.System.Nullable_int), - "Windows.Foundation.IReference`1", isRuntimeClass: false); + public static void RegisterNullableIntMapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _int_, 1, 0) == 1) + { + return; + } + + RegisterCustomAbiTypeMapping( + typeof(int?), + typeof(ABI.System.Nullable_int), + "Windows.Foundation.IReference`1", + isRuntimeClass: false); + } /// Registers the custom ABI type mapping for the "Windows.Foundation.IReference`1" WinRT type. - public static void RegisterNullableByteMapping() => RegisterCustomAbiTypeMapping( - typeof(byte?), - typeof(ABI.System.Nullable_byte), - "Windows.Foundation.IReference`1", isRuntimeClass: false); + public static void RegisterNullableByteMapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _byte_, 1, 0) == 1) + { + return; + } + + RegisterCustomAbiTypeMapping( + typeof(byte?), + typeof(ABI.System.Nullable_byte), + "Windows.Foundation.IReference`1", + isRuntimeClass: false); + } /// Registers the custom ABI type mapping for the "Windows.Foundation.IReference`1" WinRT type. - public static void RegisterNullableSByteMapping() => RegisterCustomAbiTypeMapping( - typeof(sbyte?), - typeof(ABI.System.Nullable_sbyte), - "Windows.Foundation.IReference`1", isRuntimeClass: false); + public static void RegisterNullableSByteMapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _sbyte_, 1, 0) == 1) + { + return; + } + + RegisterCustomAbiTypeMapping( + typeof(sbyte?), + typeof(ABI.System.Nullable_sbyte), + "Windows.Foundation.IReference`1", + isRuntimeClass: false); + } /// Registers the custom ABI type mapping for the "Windows.Foundation.IReference`1" WinRT type. - public static void RegisterNullableShortMapping() => RegisterCustomAbiTypeMapping( - typeof(short?), - typeof(ABI.System.Nullable_short), - "Windows.Foundation.IReference`1", isRuntimeClass: false); + public static void RegisterNullableShortMapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _short_, 1, 0) == 1) + { + return; + } + + RegisterCustomAbiTypeMapping( + typeof(short?), + typeof(ABI.System.Nullable_short), + "Windows.Foundation.IReference`1", + isRuntimeClass: false); + } /// Registers the custom ABI type mapping for the "Windows.Foundation.IReference`1" WinRT type. - public static void RegisterNullableUShortMapping() => RegisterCustomAbiTypeMapping( - typeof(ushort?), - typeof(ABI.System.Nullable_ushort), - "Windows.Foundation.IReference`1", isRuntimeClass: false); + public static void RegisterNullableUShortMapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _ushort_, 1, 0) == 1) + { + return; + } + + RegisterCustomAbiTypeMapping( + typeof(ushort?), + typeof(ABI.System.Nullable_ushort), + "Windows.Foundation.IReference`1", + isRuntimeClass: false); + } /// Registers the custom ABI type mapping for the "Windows.Foundation.IReference`1" WinRT type. - public static void RegisterNullableUIntMapping() => RegisterCustomAbiTypeMapping( - typeof(uint?), - typeof(ABI.System.Nullable_uint), - "Windows.Foundation.IReference`1", isRuntimeClass: false); + public static void RegisterNullableUIntMapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _uint_, 1, 0) == 1) + { + return; + } + + RegisterCustomAbiTypeMapping( + typeof(uint?), + typeof(ABI.System.Nullable_uint), + "Windows.Foundation.IReference`1", + isRuntimeClass: false); + } /// Registers the custom ABI type mapping for the "Windows.Foundation.IReference`1" WinRT type. - public static void RegisterNullableLongMapping() => RegisterCustomAbiTypeMapping( - typeof(long?), - typeof(ABI.System.Nullable_long), - "Windows.Foundation.IReference`1", isRuntimeClass: false); + public static void RegisterNullableLongMapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _long_, 1, 0) == 1) + { + return; + } + + RegisterCustomAbiTypeMapping( + typeof(long?), + typeof(ABI.System.Nullable_long), + "Windows.Foundation.IReference`1", + isRuntimeClass: false); + } /// Registers the custom ABI type mapping for the "Windows.Foundation.IReference`1" WinRT type. - public static void RegisterNullableULongMapping() => RegisterCustomAbiTypeMapping( - typeof(ulong?), - typeof(ABI.System.Nullable_ulong), - "Windows.Foundation.IReference`1", isRuntimeClass: false); + public static void RegisterNullableULongMapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _ulong_, 1, 0) == 1) + { + return; + } + + RegisterCustomAbiTypeMapping( + typeof(ulong?), + typeof(ABI.System.Nullable_ulong), + "Windows.Foundation.IReference`1", + isRuntimeClass: false); + } /// Registers the custom ABI type mapping for the "Windows.Foundation.IReference`1" WinRT type. - public static void RegisterNullableFloatMapping() => RegisterCustomAbiTypeMapping( - typeof(float?), - typeof(ABI.System.Nullable_float), - "Windows.Foundation.IReference`1", isRuntimeClass: false); + public static void RegisterNullableFloatMapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _float_, 1, 0) == 1) + { + return; + } + + RegisterCustomAbiTypeMapping( + typeof(float?), + typeof(ABI.System.Nullable_float), + "Windows.Foundation.IReference`1", + isRuntimeClass: false); + } /// Registers the custom ABI type mapping for the "Windows.Foundation.IReference`1" WinRT type. - public static void RegisterNullableDoubleMapping() => RegisterCustomAbiTypeMapping( - typeof(double?), - typeof(ABI.System.Nullable_double), - "Windows.Foundation.IReference`1", isRuntimeClass: false); + public static void RegisterNullableDoubleMapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _double_, 1, 0) == 1) + { + return; + } + + RegisterCustomAbiTypeMapping( + typeof(double?), + typeof(ABI.System.Nullable_double), + "Windows.Foundation.IReference`1", + isRuntimeClass: false); + } /// Registers the custom ABI type mapping for the "Windows.Foundation.IReference`1" WinRT type. - public static void RegisterNullableCharMapping() => RegisterCustomAbiTypeMapping( - typeof(char?), - typeof(ABI.System.Nullable_char), - "Windows.Foundation.IReference`1", isRuntimeClass: false); + public static void RegisterNullableCharMapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _char_, 1, 0) == 1) + { + return; + } + + RegisterCustomAbiTypeMapping( + typeof(char?), + typeof(ABI.System.Nullable_char), + "Windows.Foundation.IReference`1", + isRuntimeClass: false); + } /// Registers the custom ABI type mapping for the "Windows.Foundation.IReference`1" WinRT type. - public static void RegisterNullableBoolMapping() => RegisterCustomAbiTypeMapping( - typeof(bool?), - typeof(ABI.System.Nullable_bool), - "Windows.Foundation.IReference`1", isRuntimeClass: false); + public static void RegisterNullableBoolMapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _bool_, 1, 0) == 1) + { + return; + } + + RegisterCustomAbiTypeMapping( + typeof(bool?), + typeof(ABI.System.Nullable_bool), + "Windows.Foundation.IReference`1", + isRuntimeClass: false); + } /// Registers the custom ABI type mapping for the "Windows.Foundation.IReference`1" WinRT type. - public static void RegisterNullableGuidMapping() => RegisterCustomAbiTypeMapping( - typeof(Guid?), - typeof(ABI.System.Nullable_guid), - "Windows.Foundation.IReference`1", isRuntimeClass: false); + public static void RegisterNullableGuidMapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _Guid_, 1, 0) == 1) + { + return; + } + + RegisterCustomAbiTypeMapping( + typeof(Guid?), + typeof(ABI.System.Nullable_guid), + "Windows.Foundation.IReference`1", + isRuntimeClass: false); + } /// Registers the custom ABI type mapping for the "Windows.Foundation.IReference`1" WinRT type. - public static void RegisterNullableDateTimeOffsetMapping() => RegisterCustomAbiTypeMapping( - typeof(DateTimeOffset?), - typeof(ABI.System.Nullable_DateTimeOffset), - "Windows.Foundation.IReference`1", isRuntimeClass: false); + public static void RegisterNullableDateTimeOffsetMapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _DateTimeOffset_, 1, 0) == 1) + { + return; + } + + RegisterCustomAbiTypeMapping( + typeof(DateTimeOffset?), + typeof(ABI.System.Nullable_DateTimeOffset), + "Windows.Foundation.IReference`1", + isRuntimeClass: false); + } /// Registers the custom ABI type mapping for the "Windows.Foundation.IReference`1" WinRT type. - public static void RegisterNullableTimeSpanMapping() => RegisterCustomAbiTypeMapping( - typeof(TimeSpan?), - typeof(ABI.System.Nullable_TimeSpan), - "Windows.Foundation.IReference`1", isRuntimeClass: false); + public static void RegisterNullableTimeSpanMapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _TimeSpan_, 1, 0) == 1) + { + return; + } + + RegisterCustomAbiTypeMapping( + typeof(TimeSpan?), + typeof(ABI.System.Nullable_TimeSpan), + "Windows.Foundation.IReference`1", + isRuntimeClass: false); + } /// Registers the custom ABI type mapping for the "Windows.Foundation.DateTime" WinRT type. - public static void RegisterDateTimeOffsetMapping() => RegisterCustomAbiTypeMapping( - typeof(DateTimeOffset), - typeof(ABI.System.DateTimeOffset), - "Windows.Foundation.DateTime", isRuntimeClass: false); + public static void RegisterDateTimeOffsetMapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _DateTimeOffset, 1, 0) == 1) + { + return; + } + + RegisterCustomAbiTypeMapping( + typeof(DateTimeOffset), + typeof(ABI.System.DateTimeOffset), + "Windows.Foundation.DateTime", + isRuntimeClass: false); + } /// Registers the custom ABI type mapping for the "Windows.Foundation.HResult" WinRT type. - public static void RegisterExceptionMapping() => RegisterCustomAbiTypeMapping( - typeof(Exception), - typeof(ABI.System.Exception), - "Windows.Foundation.HResult", isRuntimeClass: false); + public static void RegisterExceptionMapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _Exception, 1, 0) == 1) + { + return; + } + + RegisterCustomAbiTypeMapping( + typeof(Exception), + typeof(ABI.System.Exception), + "Windows.Foundation.HResult", + isRuntimeClass: false); + } /// Registers the custom ABI type mapping for the "Windows.Foundation.TimeSpan" WinRT type. - public static void RegisterTimeSpanMapping() => RegisterCustomAbiTypeMapping( - typeof(TimeSpan), - typeof(ABI.System.TimeSpan), - "Windows.Foundation.TimeSpan", isRuntimeClass: false); + public static void RegisterTimeSpanMapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _TimeSpan, 1, 0) == 1) + { + return; + } + + RegisterCustomAbiTypeMapping( + typeof(TimeSpan), + typeof(ABI.System.TimeSpan), + "Windows.Foundation.TimeSpan", + isRuntimeClass: false); + } /// Registers the custom ABI type mapping for the "Windows.Foundation.Uri" WinRT type. - public static void RegisterUriMapping() => RegisterCustomAbiTypeMapping( - typeof(Uri), - typeof(ABI.System.Uri), - "Windows.Foundation.Uri", isRuntimeClass: true); + public static void RegisterUriMapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _Uri, 1, 0) == 1) + { + return; + } + + RegisterCustomAbiTypeMapping( + typeof(Uri), + typeof(ABI.System.Uri), + "Windows.Foundation.Uri", + isRuntimeClass: true); + } /// Registers the custom ABI type mapping for the "Microsoft.UI.Xaml.Data.DataErrorsChangedEventArgs" WinRT type. - public static void RegisterDataErrorsChangedEventArgsMapping() => RegisterCustomAbiTypeMapping( - typeof(DataErrorsChangedEventArgs), - typeof(ABI.System.ComponentModel.DataErrorsChangedEventArgs), - "Microsoft.UI.Xaml.Data.DataErrorsChangedEventArgs", isRuntimeClass: true); + public static void RegisterDataErrorsChangedEventArgsMapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _DataErrorsChangedEventArgs, 1, 0) == 1) + { + return; + } + + RegisterCustomAbiTypeMapping( + typeof(DataErrorsChangedEventArgs), + typeof(ABI.System.ComponentModel.DataErrorsChangedEventArgs), + "Microsoft.UI.Xaml.Data.DataErrorsChangedEventArgs", + isRuntimeClass: true); + } /// Registers the custom ABI type mapping for the "Microsoft.UI.Xaml.Data.PropertyChangedEventArgs" WinRT type. - public static void RegisterPropertyChangedEventArgsMapping() => RegisterCustomAbiTypeMapping( - typeof(PropertyChangedEventArgs), - typeof(ABI.System.ComponentModel.PropertyChangedEventArgs), - "Microsoft.UI.Xaml.Data.PropertyChangedEventArgs", isRuntimeClass: true); + public static void RegisterPropertyChangedEventArgsMapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _PropertyChangedEventArgs, 1, 0) == 1) + { + return; + } + + RegisterCustomAbiTypeMapping( + typeof(PropertyChangedEventArgs), + typeof(ABI.System.ComponentModel.PropertyChangedEventArgs), + "Microsoft.UI.Xaml.Data.PropertyChangedEventArgs", + isRuntimeClass: true); + } /// Registers the custom ABI type mapping for the "Microsoft.UI.Xaml.Data.PropertyChangedEventHandler" WinRT type. - public static void RegisterPropertyChangedEventHandlerMapping() => RegisterCustomAbiTypeMapping( - typeof(PropertyChangedEventHandler), - typeof(ABI.System.ComponentModel.PropertyChangedEventHandler), - "Microsoft.UI.Xaml.Data.PropertyChangedEventHandler", isRuntimeClass: false); + public static void RegisterPropertyChangedEventHandlerMapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _PropertyChangedEventHandler, 1, 0) == 1) + { + return; + } + + RegisterCustomAbiTypeMapping( + typeof(PropertyChangedEventHandler), + typeof(ABI.System.ComponentModel.PropertyChangedEventHandler), + "Microsoft.UI.Xaml.Data.PropertyChangedEventHandler", + isRuntimeClass: false); + } /// Registers the custom ABI type mapping for the "Microsoft.UI.Xaml.Data.INotifyDataErrorInfo" WinRT type. - public static void RegisterINotifyDataErrorInfoMapping() => RegisterCustomAbiTypeMapping( - typeof(INotifyDataErrorInfo), - typeof(ABI.System.ComponentModel.INotifyDataErrorInfo), - "Microsoft.UI.Xaml.Data.INotifyDataErrorInfo", isRuntimeClass: false); + public static void RegisterINotifyDataErrorInfoMapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _INotifyDataErrorInfo, 1, 0) == 1) + { + return; + } + + RegisterCustomAbiTypeMapping( + typeof(INotifyDataErrorInfo), + typeof(ABI.System.ComponentModel.INotifyDataErrorInfo), + "Microsoft.UI.Xaml.Data.INotifyDataErrorInfo", + isRuntimeClass: false); + } /// Registers the custom ABI type mapping for the "Microsoft.UI.Xaml.Data.INotifyPropertyChanged" WinRT type. - public static void RegisterINotifyPropertyChangedMapping() => RegisterCustomAbiTypeMapping( - typeof(INotifyPropertyChanged), - typeof(ABI.System.ComponentModel.INotifyPropertyChanged), - "Microsoft.UI.Xaml.Data.INotifyPropertyChanged", isRuntimeClass: false); + public static void RegisterINotifyPropertyChangedMapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _INotifyPropertyChanged, 1, 0) == 1) + { + return; + } + + RegisterCustomAbiTypeMapping( + typeof(INotifyPropertyChanged), + typeof(ABI.System.ComponentModel.INotifyPropertyChanged), + "Microsoft.UI.Xaml.Data.INotifyPropertyChanged", + isRuntimeClass: false); + } /// Registers the custom ABI type mapping for the "Microsoft.UI.Xaml.Interop.ICommand" WinRT type. - public static void RegisterICommandMapping() => RegisterCustomAbiTypeMapping( - typeof(ICommand), - typeof(ABI.System.Windows.Input.ICommand), - "Microsoft.UI.Xaml.Interop.ICommand", isRuntimeClass: false); + public static void RegisterICommandMapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _ICommand, 1, 0) == 1) + { + return; + } + + RegisterCustomAbiTypeMapping( + typeof(ICommand), + typeof(ABI.System.Windows.Input.ICommand), + "Microsoft.UI.Xaml.Interop.ICommand", + isRuntimeClass: false); + } /// Registers the custom ABI type mapping for the "Microsoft.UI.Xaml.IXamlServiceProvider" WinRT type. - public static void RegisterIServiceProviderMapping() => RegisterCustomAbiTypeMapping( - typeof(IServiceProvider), - typeof(ABI.System.IServiceProvider), - "Microsoft.UI.Xaml.IXamlServiceProvider", isRuntimeClass: false); + public static void RegisterIServiceProviderMapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _IServiceProvider, 1, 0) == 1) + { + return; + } + + RegisterCustomAbiTypeMapping( + typeof(IServiceProvider), + typeof(ABI.System.IServiceProvider), + "Microsoft.UI.Xaml.IXamlServiceProvider", + isRuntimeClass: false); + } /// Registers the custom ABI type mapping for the "Windows.Foundation.EventHandler`1" WinRT type. - public static void RegisterEventHandlerOpenGenericMapping() => RegisterCustomAbiTypeMapping( - typeof(EventHandler<>), - typeof(ABI.System.EventHandler<>), - "Windows.Foundation.EventHandler`1", isRuntimeClass: false); + public static void RegisterEventHandlerOpenGenericMapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _EventHandler__, 1, 0) == 1) + { + return; + } + + RegisterCustomAbiTypeMapping( + typeof(EventHandler<>), + typeof(ABI.System.EventHandler<>), + "Windows.Foundation.EventHandler`1", + isRuntimeClass: false); + } /// Registers the custom ABI type mapping for the "Windows.Foundation.Collections.IKeyValuePair`2" WinRT type. - public static void RegisterKeyValuePairOpenGenericMapping() => RegisterCustomAbiTypeMapping( - typeof(KeyValuePair<,>), - typeof(ABI.System.Collections.Generic.KeyValuePair<,>), - "Windows.Foundation.Collections.IKeyValuePair`2", isRuntimeClass: false); + public static void RegisterKeyValuePairOpenGenericMapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _KeyValuePair___, 1, 0) == 1) + { + return; + } + + RegisterCustomAbiTypeMapping( + typeof(KeyValuePair<,>), + typeof(ABI.System.Collections.Generic.KeyValuePair<,>), + "Windows.Foundation.Collections.IKeyValuePair`2", + isRuntimeClass: false); + } /// Registers the custom ABI type mapping for the "Windows.Foundation.Collections.IIterable`1" WinRT type. - public static void RegisterIEnumerableOpenGenericMapping() => RegisterCustomAbiTypeMapping( - typeof(IEnumerable<>), - typeof(ABI.System.Collections.Generic.IEnumerable<>), - "Windows.Foundation.Collections.IIterable`1", isRuntimeClass: false); + public static void RegisterIEnumerableOpenGenericMapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _IEnumerable__, 1, 0) == 1) + { + return; + } + + RegisterCustomAbiTypeMapping( + typeof(IEnumerable<>), + typeof(ABI.System.Collections.Generic.IEnumerable<>), + "Windows.Foundation.Collections.IIterable`1", + isRuntimeClass: false); + } /// Registers the custom ABI type mapping for the "Windows.Foundation.Collections.IIterator`1" WinRT type. - public static void RegisterIEnumeratorOpenGenericMapping() => RegisterCustomAbiTypeMapping( - typeof(IEnumerator<>), - typeof(ABI.System.Collections.Generic.IEnumerator<>), - "Windows.Foundation.Collections.IIterator`1", isRuntimeClass: false); + public static void RegisterIEnumeratorOpenGenericMapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _IEnumerator__, 1, 0) == 1) + { + return; + } + + RegisterCustomAbiTypeMapping( + typeof(IEnumerator<>), + typeof(ABI.System.Collections.Generic.IEnumerator<>), + "Windows.Foundation.Collections.IIterator`1", + isRuntimeClass: false); + } /// Registers the custom ABI type mapping for the "Windows.Foundation.Collections.IVector`1" WinRT type. - public static void RegisterIListOpenGenericMapping() => RegisterCustomAbiTypeMapping( - typeof(IList<>), - typeof(ABI.System.Collections.Generic.IList<>), - "Windows.Foundation.Collections.IVector`1", isRuntimeClass: false); + public static void RegisterIListOpenGenericMapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _IList__, 1, 0) == 1) + { + return; + } + + RegisterCustomAbiTypeMapping( + typeof(IList<>), + typeof(ABI.System.Collections.Generic.IList<>), + "Windows.Foundation.Collections.IVector`1", + isRuntimeClass: false); + } /// Registers the custom ABI type mapping for the "Windows.Foundation.Collections.IVectorView`1" WinRT type. - public static void RegisterIReadOnlyListOpenGenericMapping() => RegisterCustomAbiTypeMapping( - typeof(IReadOnlyList<>), - typeof(ABI.System.Collections.Generic.IReadOnlyList<>), - "Windows.Foundation.Collections.IVectorView`1", isRuntimeClass: false); + public static void RegisterIReadOnlyListOpenGenericMapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _IReadOnlyList__, 1, 0) == 1) + { + return; + } + + RegisterCustomAbiTypeMapping( + typeof(IReadOnlyList<>), + typeof(ABI.System.Collections.Generic.IReadOnlyList<>), + "Windows.Foundation.Collections.IVectorView`1", + isRuntimeClass: false); + } /// Registers the custom ABI type mapping for the "Windows.Foundation.Collections.IMap`2" WinRT type. - public static void RegisterIDictionaryOpenGenericMapping() => RegisterCustomAbiTypeMapping( - typeof(IDictionary<,>), - typeof(ABI.System.Collections.Generic.IDictionary<,>), - "Windows.Foundation.Collections.IMap`2", isRuntimeClass: false); + public static void RegisterIDictionaryOpenGenericMapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _IDictionary___, 1, 0) == 1) + { + return; + } + + RegisterCustomAbiTypeMapping( + typeof(IDictionary<,>), + typeof(ABI.System.Collections.Generic.IDictionary<,>), + "Windows.Foundation.Collections.IMap`2", + isRuntimeClass: false); + } /// Registers the custom ABI type mapping for the "Windows.Foundation.Collections.IMapView`2" WinRT type. - public static void RegisterIReadOnlyDictionaryOpenGenericMapping() => RegisterCustomAbiTypeMapping( - typeof(IReadOnlyDictionary<,>), - typeof(ABI.System.Collections.Generic.IReadOnlyDictionary<,>), - "Windows.Foundation.Collections.IMapView`2", isRuntimeClass: false); + public static void RegisterIReadOnlyDictionaryOpenGenericMapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _IReadOnlyDictionary___, 1, 0) == 1) + { + return; + } + + RegisterCustomAbiTypeMapping( + typeof(IReadOnlyDictionary<,>), + typeof(ABI.System.Collections.Generic.IReadOnlyDictionary<,>), + "Windows.Foundation.Collections.IMapView`2", + isRuntimeClass: false); + } /// Registers the custom ABI type mapping for the "Windows.Foundation.IClosable" WinRT type. - public static void RegisterIDisposableMapping() => RegisterCustomAbiTypeMapping( - typeof(IDisposable), - typeof(ABI.System.IDisposable), - "Windows.Foundation.IClosable", isRuntimeClass: false); + public static void RegisterIDisposableMapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _IDisposable, 1, 0) == 1) + { + return; + } + + RegisterCustomAbiTypeMapping( + typeof(IDisposable), + typeof(ABI.System.IDisposable), + "Windows.Foundation.IClosable", + isRuntimeClass: false); + } /// Registers the custom ABI type mapping for the "Microsoft.UI.Xaml.Interop.IBindableIterable" WinRT type. - public static void RegisterIEnumerableMapping() => RegisterCustomAbiTypeMapping( - typeof(IEnumerable), - typeof(ABI.System.Collections.IEnumerable), - "Microsoft.UI.Xaml.Interop.IBindableIterable", isRuntimeClass: false); + public static void RegisterIEnumerableMapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _IEnumerable, 1, 0) == 1) + { + return; + } + + RegisterCustomAbiTypeMapping( + typeof(IEnumerable), + typeof(ABI.System.Collections.IEnumerable), + "Microsoft.UI.Xaml.Interop.IBindableIterable", + isRuntimeClass: false); + } /// Registers the custom ABI type mapping for the "Microsoft.UI.Xaml.Interop.IBindableVector" WinRT type. - public static void RegisterIListMapping() => RegisterCustomAbiTypeMapping( - typeof(IList), - typeof(ABI.System.Collections.IList), - "Microsoft.UI.Xaml.Interop.IBindableVector", isRuntimeClass: false); + public static void RegisterIListMapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _IList, 1, 0) == 1) + { + return; + } + + RegisterCustomAbiTypeMapping( + typeof(IList), + typeof(ABI.System.Collections.IList), + "Microsoft.UI.Xaml.Interop.IBindableVector", + isRuntimeClass: false); + } /// Registers the custom ABI type mapping for the "Microsoft.UI.Xaml.Interop.INotifyCollectionChanged" WinRT type. - public static void RegisterINotifyCollectionChangedMapping() => RegisterCustomAbiTypeMapping( - typeof(INotifyCollectionChanged), - typeof(ABI.System.Collections.Specialized.INotifyCollectionChanged), - "Microsoft.UI.Xaml.Interop.INotifyCollectionChanged", isRuntimeClass: false); + public static void RegisterINotifyCollectionChangedMapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _INotifyCollectionChanged, 1, 0) == 1) + { + return; + } + + RegisterCustomAbiTypeMapping( + typeof(INotifyCollectionChanged), + typeof(ABI.System.Collections.Specialized.INotifyCollectionChanged), + "Microsoft.UI.Xaml.Interop.INotifyCollectionChanged", + isRuntimeClass: false); + } /// Registers the custom ABI type mapping for the "Microsoft.UI.Xaml.Interop.NotifyCollectionChangedEventArgs" WinRT type. - public static void RegisterNotifyCollectionChangedActionMapping() => RegisterCustomAbiTypeMapping( - typeof(NotifyCollectionChangedAction), - typeof(ABI.System.Collections.Specialized.NotifyCollectionChangedAction), - "Microsoft.UI.Xaml.Interop.NotifyCollectionChangedEventArgs", isRuntimeClass: false); + public static void RegisterNotifyCollectionChangedActionMapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _NotifyCollectionChangedAction, 1, 0) == 1) + { + return; + } + + RegisterCustomAbiTypeMapping( + typeof(NotifyCollectionChangedAction), + typeof(ABI.System.Collections.Specialized.NotifyCollectionChangedAction), + "Microsoft.UI.Xaml.Interop.NotifyCollectionChangedEventArgs", + isRuntimeClass: false); + } /// Registers the custom ABI type mapping for the "Microsoft.UI.Xaml.Interop.NotifyCollectionChangedEventArgs" WinRT type. - public static void RegisterNotifyCollectionChangedEventArgsMapping() => RegisterCustomAbiTypeMapping( - typeof(NotifyCollectionChangedEventArgs), - typeof(ABI.System.Collections.Specialized.NotifyCollectionChangedEventArgs), - "Microsoft.UI.Xaml.Interop.NotifyCollectionChangedEventArgs", isRuntimeClass: true); + public static void RegisterNotifyCollectionChangedEventArgsMapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _NotifyCollectionChangedEventArgs, 1, 0) == 1) + { + return; + } + + RegisterCustomAbiTypeMapping( + typeof(NotifyCollectionChangedEventArgs), + typeof(ABI.System.Collections.Specialized.NotifyCollectionChangedEventArgs), + "Microsoft.UI.Xaml.Interop.NotifyCollectionChangedEventArgs", + isRuntimeClass: true); + } /// Registers the custom ABI type mapping for the "Microsoft.UI.Xaml.Interop.NotifyCollectionChangedEventHandler" WinRT type. - public static void RegisterNotifyCollectionChangedEventHandlerMapping() => RegisterCustomAbiTypeMapping( - typeof(NotifyCollectionChangedEventHandler), - typeof(ABI.System.Collections.Specialized.NotifyCollectionChangedEventHandler), - "Microsoft.UI.Xaml.Interop.NotifyCollectionChangedEventHandler", isRuntimeClass: false); + public static void RegisterNotifyCollectionChangedEventHandlerMapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _NotifyCollectionChangedEventHandler, 1, 0) == 1) + { + return; + } + + RegisterCustomAbiTypeMapping( + typeof(NotifyCollectionChangedEventHandler), + typeof(ABI.System.Collections.Specialized.NotifyCollectionChangedEventHandler), + "Microsoft.UI.Xaml.Interop.NotifyCollectionChangedEventHandler", + isRuntimeClass: false); + } /// Registers the custom ABI type mapping for the "Windows.Foundation.Numerics.Matrix3x2" WinRT type. - public static void RegisterMatrix3x2Mapping() => RegisterCustomAbiTypeMapping( - typeof(Matrix3x2), - typeof(ABI.System.Numerics.Matrix3x2), - "Windows.Foundation.Numerics.Matrix3x2", isRuntimeClass: false); + public static void RegisterMatrix3x2Mapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _Matrix3x2, 1, 0) == 1) + { + return; + } + + RegisterCustomAbiTypeMapping( + typeof(Matrix3x2), + typeof(ABI.System.Numerics.Matrix3x2), + "Windows.Foundation.Numerics.Matrix3x2", + isRuntimeClass: false); + } /// Registers the custom ABI type mapping for the "Windows.Foundation.Numerics.Matrix4x4" WinRT type. - public static void RegisterMatrix4x4Mapping() => RegisterCustomAbiTypeMapping( - typeof(Matrix4x4), - typeof(ABI.System.Numerics.Matrix4x4), - "Windows.Foundation.Numerics.Matrix4x4", isRuntimeClass: false); + public static void RegisterMatrix4x4Mapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _Matrix4x4, 1, 0) == 1) + { + return; + } + + RegisterCustomAbiTypeMapping( + typeof(Matrix4x4), + typeof(ABI.System.Numerics.Matrix4x4), + "Windows.Foundation.Numerics.Matrix4x4", + isRuntimeClass: false); + } /// Registers the custom ABI type mapping for the "Windows.Foundation.Numerics.Plane" WinRT type. - public static void RegisterPlaneMapping() => RegisterCustomAbiTypeMapping( - typeof(Plane), - typeof(ABI.System.Numerics.Plane), - "Windows.Foundation.Numerics.Plane", isRuntimeClass: false); + public static void RegisterPlaneMapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _Plane, 1, 0) == 1) + { + return; + } + + RegisterCustomAbiTypeMapping( + typeof(Plane), + typeof(ABI.System.Numerics.Plane), + "Windows.Foundation.Numerics.Plane", + isRuntimeClass: false); + } /// Registers the custom ABI type mapping for the "Windows.Foundation.Numerics.Quaternion" WinRT type. - public static void RegisterQuaternionMapping() => RegisterCustomAbiTypeMapping( - typeof(Quaternion), - typeof(ABI.System.Numerics.Quaternion), - "Windows.Foundation.Numerics.Quaternion", isRuntimeClass: false); + public static void RegisterQuaternionMapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _Quaternion, 1, 0) == 1) + { + return; + } + + RegisterCustomAbiTypeMapping( + typeof(Quaternion), + typeof(ABI.System.Numerics.Quaternion), + "Windows.Foundation.Numerics.Quaternion", + isRuntimeClass: false); + } /// Registers the custom ABI type mapping for the "Windows.Foundation.Numerics.Vector2" WinRT type. - public static void RegisterVector2Mapping() => RegisterCustomAbiTypeMapping( - typeof(Vector2), - typeof(ABI.System.Numerics.Vector2), - "Windows.Foundation.Numerics.Vector2", isRuntimeClass: false); + public static void RegisterVector2Mapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _Vector2, 1, 0) == 1) + { + return; + } + + RegisterCustomAbiTypeMapping( + typeof(Vector2), + typeof(ABI.System.Numerics.Vector2), + "Windows.Foundation.Numerics.Vector2", + isRuntimeClass: false); + } /// Registers the custom ABI type mapping for the "Windows.Foundation.Numerics.Vector3" WinRT type. - public static void RegisterVector3Mapping() => RegisterCustomAbiTypeMapping( - typeof(Vector3), - typeof(ABI.System.Numerics.Vector3), - "Windows.Foundation.Numerics.Vector3", isRuntimeClass: false); + public static void RegisterVector3Mapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _Vector3, 1, 0) == 1) + { + return; + } + + RegisterCustomAbiTypeMapping( + typeof(Vector3), + typeof(ABI.System.Numerics.Vector3), + "Windows.Foundation.Numerics.Vector3", + isRuntimeClass: false); + } /// Registers the custom ABI type mapping for the "Windows.Foundation.Numerics.Vector4" WinRT type. - public static void RegisterVector4Mapping() => RegisterCustomAbiTypeMapping( - typeof(Vector4), - typeof(ABI.System.Numerics.Vector4), - "Windows.Foundation.Numerics.Vector4", isRuntimeClass: false); + public static void RegisterVector4Mapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _Vector4, 1, 0) == 1) + { + return; + } + + RegisterCustomAbiTypeMapping( + typeof(Vector4), + typeof(ABI.System.Numerics.Vector4), + "Windows.Foundation.Numerics.Vector4", + isRuntimeClass: false); + } /// Registers the custom ABI type mapping for the type. - public static void RegisterEventHandlerMapping() => RegisterCustomAbiTypeMapping( - typeof(EventHandler), - typeof(ABI.System.EventHandler)); + public static void RegisterEventHandlerMapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _EventHandler, 1, 0) == 1) + { + return; + } + + RegisterCustomAbiTypeMapping( + typeof(EventHandler), + typeof(ABI.System.EventHandler)); + } /// Registers the custom ABI type mapping for the type. - public static void RegisterIMapOpenGenericMapping() => RegisterCustomTypeToHelperTypeMapping( - typeof(IMap<,>), - typeof(ABI.System.Collections.Generic.IDictionary<,>)); + public static void RegisterIMapOpenGenericMapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _IMap___, 1, 0) == 1) + { + return; + } + + RegisterCustomTypeToHelperTypeMapping( + typeof(IMap<,>), + typeof(ABI.System.Collections.Generic.IDictionary<,>)); + } /// Registers the custom ABI type mapping for the type. - public static void RegisterIVectorOpenGenericMapping() => RegisterCustomTypeToHelperTypeMapping( - typeof(IVector<>), - typeof(ABI.System.Collections.Generic.IList<>)); + public static void RegisterIVectorOpenGenericMapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _IVector__, 1, 0) == 1) + { + return; + } + + RegisterCustomTypeToHelperTypeMapping( + typeof(IVector<>), + typeof(ABI.System.Collections.Generic.IList<>)); + } /// Registers the custom ABI type mapping for the type. - public static void RegisterIMapViewOpenGenericMapping() => RegisterCustomTypeToHelperTypeMapping( - typeof(IMapView<,>), - typeof(ABI.System.Collections.Generic.IReadOnlyDictionary<,>)); + public static void RegisterIMapViewOpenGenericMapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _IMapView___, 1, 0) == 1) + { + return; + } + + RegisterCustomTypeToHelperTypeMapping( + typeof(IMapView<,>), + typeof(ABI.System.Collections.Generic.IReadOnlyDictionary<,>)); + } /// Registers the custom ABI type mapping for the type. - public static void RegisterIVectorViewOpenGenericMapping() => RegisterCustomTypeToHelperTypeMapping( - typeof(IVectorView<>), - typeof(ABI.System.Collections.Generic.IReadOnlyList<>)); + public static void RegisterIVectorViewOpenGenericMapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _IVectorView__, 1, 0) == 1) + { + return; + } + + RegisterCustomTypeToHelperTypeMapping( + typeof(IVectorView<>), + typeof(ABI.System.Collections.Generic.IReadOnlyList<>)); + } /// Registers the custom ABI type mapping for the type. - public static void RegisterIBindableVectorMapping() => RegisterCustomTypeToHelperTypeMapping( - typeof(IBindableVector), - typeof(ABI.System.Collections.IList)); + public static void RegisterIBindableVectorMapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _IBindableVector, 1, 0) == 1) + { + return; + } + + RegisterCustomTypeToHelperTypeMapping( + typeof(IBindableVector), + typeof(ABI.System.Collections.IList)); + } /// Registers the custom ABI type mapping for the type. - public static void RegisterICollectionOpenGenericMapping() => RegisterCustomTypeToHelperTypeMapping( - typeof(ICollection<>), - typeof(ABI.System.Collections.Generic.ICollection<>)); + public static void RegisterICollectionOpenGenericMapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _ICollection__, 1, 0) == 1) + { + return; + } + + RegisterCustomTypeToHelperTypeMapping( + typeof(ICollection<>), + typeof(ABI.System.Collections.Generic.ICollection<>)); + } /// Registers the custom ABI type mapping for the type. - public static void RegisterIReadOnlyCollectionOpenGenericMapping() => RegisterCustomTypeToHelperTypeMapping( - typeof(IReadOnlyCollection<>), - typeof(ABI.System.Collections.Generic.IReadOnlyCollection<>)); + public static void RegisterIReadOnlyCollectionOpenGenericMapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _IReadOnlyCollection__, 1, 0) == 1) + { + return; + } + + RegisterCustomTypeToHelperTypeMapping( + typeof(IReadOnlyCollection<>), + typeof(ABI.System.Collections.Generic.IReadOnlyCollection<>)); + } /// Registers the custom ABI type mapping for the type. - public static void RegisterICollectionMapping() => RegisterCustomTypeToHelperTypeMapping( - typeof(ICollection), - typeof(ABI.System.Collections.ICollection)); + public static void RegisterICollectionMapping() + { + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _ICollection, 1, 0) == 1) + { + return; + } + + RegisterCustomTypeToHelperTypeMapping( + typeof(ICollection), + typeof(ABI.System.Collections.ICollection)); + } } } diff --git a/src/WinRT.Runtime/Projections.CustomTypeMappings.tt b/src/WinRT.Runtime/Projections.CustomTypeMappings.tt index 2b7b16c3a..6c3c03f38 100644 --- a/src/WinRT.Runtime/Projections.CustomTypeMappings.tt +++ b/src/WinRT.Runtime/Projections.CustomTypeMappings.tt @@ -1,5 +1,7 @@ <#@ template debug="false" hostspecific="false" language="C#" #> <#@ assembly name="System.Core" #> +<#@ import namespace="System.Linq" #> +<#@ import namespace="System.Text.RegularExpressions" #> <#@ output extension=".g.cs"#> // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. @@ -12,6 +14,7 @@ using System.Collections.Generic; using System.Collections.Specialized; using System.ComponentModel; using System.Numerics; +using System.Threading; using System.Windows.Input; using Microsoft.UI.Xaml.Interop; using Windows.Foundation.Collections; @@ -38,6 +41,23 @@ static string GetMethodName(string name, string hint) return $"Register{methodTypeName}Mapping"; } +// Helper to write the guard statements for a given method. +// We need two extra indents as these are inside each method. +void WriteGuardStatements(string name) +{ +#> + if (FeatureSwitches.EnableDefaultCustomTypeMappings) + { + return; + } + + if (Interlocked.CompareExchange(ref _<#=Regex.Replace(name, "[?<>,]", "_")#>, 1, 0) == 1) + { + return; + } +<# +} + // Types for 'RegisterCustomAbiTypeMapping' var registerCustomAbiTypeMappings = new (string Public, string Abi, string Name, string Hint, bool IsRuntimeClass)[] { @@ -107,6 +127,20 @@ var registerCustomTypeToHelperTypeMapping = new (string Public, string Helper)[] ("ICollection", "ABI.System.Collections.ICollection") }; +// Declare all fields +foreach (string fieldName in + registerCustomAbiTypeMappings + .Select(t => t.Public) + .Concat( + registerCustomTypeToHelperTypeMapping + .Select(t => t.Public)) + .Select(s => Regex.Replace(s, "[?<>,]", "_"))) +{ +#> + private static int _<#=fieldName#>; +<# +} + // 'RegisterCustomAbiTypeMapping' methods foreach (var type in registerCustomAbiTypeMappings) { @@ -116,19 +150,34 @@ foreach (var type in registerCustomAbiTypeMappings) { #> /// Registers the custom ABI type mapping for the "<#=type.Name#>" WinRT type. - public static void <#=GetMethodName(type.Public, type.Hint)#>() => RegisterCustomAbiTypeMapping( - typeof(<#=type.Public#>), - typeof(<#=type.Abi#>), - "<#=type.Name#>", isRuntimeClass: <#=type.IsRuntimeClass.ToString().ToLowerInvariant()#>); + public static void <#=GetMethodName(type.Public, type.Hint)#>() + { +<# + WriteGuardStatements(type.Public); +#> + + RegisterCustomAbiTypeMapping( + typeof(<#=type.Public#>), + typeof(<#=type.Abi#>), + "<#=type.Name#>", + isRuntimeClass: <#=type.IsRuntimeClass.ToString().ToLowerInvariant()#>); + } <# } else { #> /// Registers the custom ABI type mapping for the type. - public static void <#=GetMethodName(type.Public, type.Hint)#>() => RegisterCustomAbiTypeMapping( - typeof(<#=type.Public#>), - typeof(<#=type.Abi#>)); + public static void <#=GetMethodName(type.Public, type.Hint)#>() + { +<# + WriteGuardStatements(type.Public); +#> + + RegisterCustomAbiTypeMapping( + typeof(<#=type.Public#>), + typeof(<#=type.Abi#>)); + } <# } } @@ -144,9 +193,16 @@ foreach (var type in registerCustomTypeToHelperTypeMapping) WriteLine(""); #> /// Registers the custom ABI type mapping for the type. - public static void <#=GetMethodName(type.Public, null)#>() => RegisterCustomTypeToHelperTypeMapping( - typeof(<#=type.Public#>), - typeof(<#=type.Helper#>)); + public static void <#=GetMethodName(type.Public, null)#>() + { +<# + WriteGuardStatements(type.Public); +#> + + RegisterCustomTypeToHelperTypeMapping( + typeof(<#=type.Public#>), + typeof(<#=type.Helper#>)); + } <# } #> From 2413d8ed1fd6034238be93057240d79caee4e6b6 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Fri, 2 Feb 2024 11:02:07 +0100 Subject: [PATCH 20/20] Fix NotifyCollectionChangedAction runtime class name --- src/WinRT.Runtime/Projections.CustomTypeMappings.g.cs | 4 ++-- src/WinRT.Runtime/Projections.CustomTypeMappings.tt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/WinRT.Runtime/Projections.CustomTypeMappings.g.cs b/src/WinRT.Runtime/Projections.CustomTypeMappings.g.cs index 9adaedf07..67eeec67b 100644 --- a/src/WinRT.Runtime/Projections.CustomTypeMappings.g.cs +++ b/src/WinRT.Runtime/Projections.CustomTypeMappings.g.cs @@ -879,7 +879,7 @@ public static void RegisterINotifyCollectionChangedMapping() isRuntimeClass: false); } - /// Registers the custom ABI type mapping for the "Microsoft.UI.Xaml.Interop.NotifyCollectionChangedEventArgs" WinRT type. + /// Registers the custom ABI type mapping for the "Microsoft.UI.Xaml.Interop.NotifyCollectionChangedAction" WinRT type. public static void RegisterNotifyCollectionChangedActionMapping() { if (FeatureSwitches.EnableDefaultCustomTypeMappings) @@ -895,7 +895,7 @@ public static void RegisterNotifyCollectionChangedActionMapping() RegisterCustomAbiTypeMapping( typeof(NotifyCollectionChangedAction), typeof(ABI.System.Collections.Specialized.NotifyCollectionChangedAction), - "Microsoft.UI.Xaml.Interop.NotifyCollectionChangedEventArgs", + "Microsoft.UI.Xaml.Interop.NotifyCollectionChangedAction", isRuntimeClass: false); } diff --git a/src/WinRT.Runtime/Projections.CustomTypeMappings.tt b/src/WinRT.Runtime/Projections.CustomTypeMappings.tt index 6c3c03f38..9d6db48f8 100644 --- a/src/WinRT.Runtime/Projections.CustomTypeMappings.tt +++ b/src/WinRT.Runtime/Projections.CustomTypeMappings.tt @@ -101,7 +101,7 @@ var registerCustomAbiTypeMappings = new (string Public, string Abi, string Name, ("IEnumerable", "ABI.System.Collections.IEnumerable", "Microsoft.UI.Xaml.Interop.IBindableIterable", null, false), ("IList", "ABI.System.Collections.IList", "Microsoft.UI.Xaml.Interop.IBindableVector", null, false), ("INotifyCollectionChanged", "ABI.System.Collections.Specialized.INotifyCollectionChanged", "Microsoft.UI.Xaml.Interop.INotifyCollectionChanged", null, false), - ("NotifyCollectionChangedAction", "ABI.System.Collections.Specialized.NotifyCollectionChangedAction", "Microsoft.UI.Xaml.Interop.NotifyCollectionChangedEventArgs", null, false), + ("NotifyCollectionChangedAction", "ABI.System.Collections.Specialized.NotifyCollectionChangedAction", "Microsoft.UI.Xaml.Interop.NotifyCollectionChangedAction", null, false), ("NotifyCollectionChangedEventArgs", "ABI.System.Collections.Specialized.NotifyCollectionChangedEventArgs", "Microsoft.UI.Xaml.Interop.NotifyCollectionChangedEventArgs", null, true), ("NotifyCollectionChangedEventHandler", "ABI.System.Collections.Specialized.NotifyCollectionChangedEventHandler", "Microsoft.UI.Xaml.Interop.NotifyCollectionChangedEventHandler", null, false), ("Matrix3x2", "ABI.System.Numerics.Matrix3x2", "Windows.Foundation.Numerics.Matrix3x2", null, false),