-
Notifications
You must be signed in to change notification settings - Fork 124
Expand file tree
/
Copy pathProjections.CustomTypeMappings.EventHandler.cs
More file actions
211 lines (179 loc) · 9.16 KB
/
Projections.CustomTypeMappings.EventHandler.cs
File metadata and controls
211 lines (179 loc) · 9.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#if NET
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Numerics;
using System.Threading;
using System.Windows.Input;
using Microsoft.UI.Xaml.Interop;
using Windows.Foundation.Collections;
using static System.Runtime.InteropServices.ComWrappers;
#nullable enable
namespace WinRT
{
/// <inheritdoc cref="Projections"/>
partial class Projections
{
private static int _EventHandler;
private static int _NotifyCollectionChangedEventHandler;
private static int _PropertyChangedEventHandler;
/// <summary>
/// ABI interfaces for <see cref="EventHandler"/>, conditionally set from <see cref="RegisterEventHandlerMapping"/>
/// to avoid rooting <see cref="ABI.System.EventHandler"/> when the type mapping for this type isn't needed.
/// </summary>
private static ComInterfaceEntry[]? _AbiEventHandlerExposedInterfaces;
/// <summary>
/// ABI interfaces for <see cref="NotifyCollectionChangedEventHandler"/>, conditionally set from <see cref="RegisterNotifyCollectionChangedEventHandlerMapping"/>
/// to avoid rooting <see cref="ABI.System.Collections.Specialized.NotifyCollectionChangedEventHandler"/> when the type mapping for this type isn't needed.
/// </summary>
private static ComInterfaceEntry[]? _AbiNotifyCollectionChangedEventHandlerExposedInterfaces;
/// <summary>
/// ABI interfaces for <see cref="PropertyChangedEventHandler"/>, conditionally set from <see cref="RegisterPropertyChangedEventHandlerMapping"/>
/// to avoid rooting <see cref="ABI.System.ComponentModel.PropertyChangedEventHandler"/> when the type mapping for this type isn't needed.
/// </summary>
private static ComInterfaceEntry[]? _AbiPropertyChangedEventHandlerExposedInterfaces;
/// <summary>Registers the custom ABI type mapping for the <see cref="EventHandler"/> type.</summary>
public static void RegisterEventHandlerMapping()
{
if (FeatureSwitches.EnableDefaultCustomTypeMappings)
{
return;
}
if (Interlocked.CompareExchange(ref _EventHandler, 1, 0) == 1)
{
return;
}
RegisterCustomAbiTypeMapping(
typeof(EventHandler),
typeof(ABI.System.EventHandler));
_AbiEventHandlerExposedInterfaces = ABI.System.EventHandler.GetExposedInterfaces();
}
/// <summary>
/// Gets the ABI interfaces for <see cref="EventHandler"/>.
/// </summary>
/// <returns>The ABI interfaces for <see cref="EventHandler"/>.</returns>
/// <exception cref="NotSupportedException">Thrown if the type mapping is disabled.</exception>
internal static ComInterfaceEntry[] GetAbiEventHandlerExposedInterfaces()
{
if (FeatureSwitches.EnableDefaultCustomTypeMappings)
{
return ABI.System.EventHandler.GetExposedInterfaces();
}
ComInterfaceEntry[]? interfaces = _AbiEventHandlerExposedInterfaces;
if (interfaces is null)
{
throw new NotSupportedException(
"Support for type mapping for the 'EventHandler' type is currently disabled. " +
"To enable it, either make sure to not set the 'CsWinRTEnableCustomTypeMappings' property to 'false', " +
"or manually enable support for this specific type by calling 'Projections.RegisterEventHandlerMapping()'.");
}
return interfaces;
}
/// <summary>Registers the custom ABI type mapping for the <c>"Microsoft.UI.Xaml.Interop.NotifyCollectionChangedEventHandler"</c> WinRT type.</summary>
public static void RegisterNotifyCollectionChangedEventHandlerMapping()
{
if (FeatureSwitches.EnableDefaultCustomTypeMappings)
{
return;
}
if (Interlocked.CompareExchange(ref _NotifyCollectionChangedEventHandler, 1, 0) == 1)
{
return;
}
if (FeatureSwitches.UseWindowsUIXamlProjections)
{
RegisterCustomAbiTypeMapping(
typeof(NotifyCollectionChangedEventHandler),
typeof(ABI.System.Collections.Specialized.NotifyCollectionChangedEventHandler),
"Windows.UI.Xaml.Interop.NotifyCollectionChangedEventHandler",
isRuntimeClass: false);
}
else
{
RegisterCustomAbiTypeMapping(
typeof(NotifyCollectionChangedEventHandler),
typeof(ABI.System.Collections.Specialized.NotifyCollectionChangedEventHandler),
"Microsoft.UI.Xaml.Interop.NotifyCollectionChangedEventHandler",
isRuntimeClass: false);
}
_AbiNotifyCollectionChangedEventHandlerExposedInterfaces = ABI.System.Collections.Specialized.NotifyCollectionChangedEventHandler.GetExposedInterfaces();
}
/// <summary>
/// Gets the ABI interfaces for <see cref="NotifyCollectionChangedEventHandler"/>.
/// </summary>
/// <returns>The ABI interfaces for <see cref="NotifyCollectionChangedEventHandler"/>.</returns>
/// <exception cref="NotSupportedException">Thrown if the type mapping is disabled.</exception>
internal static ComInterfaceEntry[] GetAbiNotifyCollectionChangedEventHandlerExposedInterfaces()
{
if (FeatureSwitches.EnableDefaultCustomTypeMappings)
{
return ABI.System.Collections.Specialized.NotifyCollectionChangedEventHandler.GetExposedInterfaces();
}
ComInterfaceEntry[]? interfaces = _AbiNotifyCollectionChangedEventHandlerExposedInterfaces;
if (interfaces is null)
{
throw new NotSupportedException(
"Support for type mapping for the 'NotifyCollectionChangedEventHandler' type is currently disabled. " +
"To enable it, either make sure to not set the 'CsWinRTEnableCustomTypeMappings' property to 'false', " +
"or manually enable support for this specific type by calling 'Projections.RegisterNotifyCollectionChangedEventHandlerMapping()'.");
}
return interfaces;
}
/// <summary>Registers the custom ABI type mapping for the <c>"Microsoft.UI.Xaml.Data.PropertyChangedEventHandler"</c> WinRT type.</summary>
public static void RegisterPropertyChangedEventHandlerMapping()
{
if (FeatureSwitches.EnableDefaultCustomTypeMappings)
{
return;
}
if (Interlocked.CompareExchange(ref _PropertyChangedEventHandler, 1, 0) == 1)
{
return;
}
if (FeatureSwitches.UseWindowsUIXamlProjections)
{
RegisterCustomAbiTypeMapping(
typeof(PropertyChangedEventHandler),
typeof(ABI.System.ComponentModel.PropertyChangedEventHandler),
"Windows.UI.Xaml.Data.PropertyChangedEventHandler",
isRuntimeClass: false);
}
else
{
RegisterCustomAbiTypeMapping(
typeof(PropertyChangedEventHandler),
typeof(ABI.System.ComponentModel.PropertyChangedEventHandler),
"Microsoft.UI.Xaml.Data.PropertyChangedEventHandler",
isRuntimeClass: false);
}
_AbiPropertyChangedEventHandlerExposedInterfaces = ABI.System.ComponentModel.PropertyChangedEventHandler.GetExposedInterfaces();
}
/// <summary>
/// Gets the ABI interfaces for <see cref="PropertyChangedEventHandler"/>.
/// </summary>
/// <returns>The ABI interfaces for <see cref="PropertyChangedEventHandler"/>.</returns>
/// <exception cref="NotSupportedException">Thrown if the type mapping is disabled.</exception>
internal static ComInterfaceEntry[] GetAbiPropertyChangedEventHandlerExposedInterfaces()
{
if (FeatureSwitches.EnableDefaultCustomTypeMappings)
{
return ABI.System.ComponentModel.PropertyChangedEventHandler.GetExposedInterfaces();
}
ComInterfaceEntry[]? interfaces = _AbiPropertyChangedEventHandlerExposedInterfaces;
if (interfaces is null)
{
throw new NotSupportedException(
"Support for type mapping for the 'PropertyChangedEventHandler' type is currently disabled. " +
"To enable it, either make sure to not set the 'CsWinRTEnableCustomTypeMappings' property to 'false', " +
"or manually enable support for this specific type by calling 'Projections.RegisterPropertyChangedEventHandlerMapping()'.");
}
return interfaces;
}
}
}
#endif