-
Notifications
You must be signed in to change notification settings - Fork 124
Expand file tree
/
Copy pathBoolean.cs
More file actions
286 lines (254 loc) · 14.5 KB
/
Boolean.cs
File metadata and controls
286 lines (254 loc) · 14.5 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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Windows.Foundation;
using WindowsRuntime;
using WindowsRuntime.InteropServices;
using WindowsRuntime.InteropServices.Marshalling;
using static System.Runtime.InteropServices.ComWrappers;
#pragma warning disable IDE1006, CA1416
#pragma warning disable IL2026 // Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code
[assembly: TypeMap<WindowsRuntimeMetadataTypeMapGroup>(
value: "Boolean",
target: typeof(ABI.System.Boolean),
trimTarget: typeof(bool))]
[assembly: TypeMap<WindowsRuntimeComWrappersTypeMapGroup>(
value: "Windows.Foundation.IReference`1<Boolean>",
target: typeof(ABI.System.Boolean),
trimTarget: typeof(bool))]
#pragma warning restore IL2026 // Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code
[assembly: TypeMapAssociation<WindowsRuntimeComWrappersTypeMapGroup>(typeof(bool), typeof(ABI.System.Boolean))]
namespace ABI.System;
/// <summary>
/// ABI type for <see cref="bool"/>.
/// </summary>
[WindowsRuntimeMappedMetadata("Windows.Foundation.FoundationContract")]
[WindowsRuntimeClassName("Windows.Foundation.IReference`1<Boolean>")]
[WindowsRuntimeMetadataTypeName("Boolean")]
[WindowsRuntimeMappedType(typeof(bool))]
[WindowsRuntimeReferenceType(typeof(bool?))]
[BooleanComWrappersMarshaller]
file static class Boolean;
/// <summary>
/// Marshaller for <see cref="bool"/>.
/// </summary>
public static unsafe class BooleanMarshaller
{
/// <inheritdoc cref="WindowsRuntimeValueTypeMarshaller.BoxToUnmanaged{T}(T?, CreateComInterfaceFlags, in Guid)"/>
public static WindowsRuntimeObjectReferenceValue BoxToUnmanaged(bool? value)
{
return WindowsRuntimeValueTypeMarshaller.BoxToUnmanaged(value, CreateComInterfaceFlags.None, in WellKnownWindowsInterfaceIIDs.IID_IReferenceOfBool);
}
/// <inheritdoc cref="WindowsRuntimeValueTypeMarshaller.UnboxToManaged(void*)"/>
public static bool? UnboxToManaged(void* value)
{
return WindowsRuntimeValueTypeMarshaller.UnboxToManaged<bool>(value);
}
}
/// <summary>
/// The set of <see cref="ComInterfaceEntry"/> values for <see cref="bool"/>.
/// </summary>
file struct BooleanInterfaceEntries
{
public ComInterfaceEntry IReferenceOfBoolean;
public ComInterfaceEntry IPropertyValue;
public ComInterfaceEntry IStringable;
public ComInterfaceEntry IWeakReferenceSource;
public ComInterfaceEntry IMarshal;
public ComInterfaceEntry IAgileObject;
public ComInterfaceEntry IInspectable;
public ComInterfaceEntry IUnknown;
}
/// <summary>
/// The implementation of <see cref="BooleanInterfaceEntries"/>.
/// </summary>
file static class BooleanInterfaceEntriesImpl
{
/// <summary>
/// The <see cref="BooleanInterfaceEntries"/> value for <see cref="bool"/>.
/// </summary>
[FixedAddressValueType]
public static readonly BooleanInterfaceEntries Entries;
/// <summary>
/// Initializes <see cref="Entries"/>.
/// </summary>
static BooleanInterfaceEntriesImpl()
{
Entries.IReferenceOfBoolean.IID = WellKnownWindowsInterfaceIIDs.IID_IReferenceOfBool;
Entries.IReferenceOfBoolean.Vtable = BooleanReferenceImpl.Vtable;
Entries.IPropertyValue.IID = WellKnownWindowsInterfaceIIDs.IID_IPropertyValue;
Entries.IPropertyValue.Vtable = BooleanPropertyValueImpl.Vtable;
Entries.IStringable.IID = WellKnownWindowsInterfaceIIDs.IID_IStringable;
Entries.IStringable.Vtable = IStringableImpl.Vtable;
Entries.IWeakReferenceSource.IID = WellKnownWindowsInterfaceIIDs.IID_IWeakReferenceSource;
Entries.IWeakReferenceSource.Vtable = IWeakReferenceSourceImpl.Vtable;
Entries.IMarshal.IID = WellKnownWindowsInterfaceIIDs.IID_IMarshal;
Entries.IMarshal.Vtable = IMarshalImpl.Vtable;
Entries.IAgileObject.IID = WellKnownWindowsInterfaceIIDs.IID_IAgileObject;
Entries.IAgileObject.Vtable = IAgileObjectImpl.Vtable;
Entries.IInspectable.IID = WellKnownWindowsInterfaceIIDs.IID_IInspectable;
Entries.IInspectable.Vtable = IInspectableImpl.Vtable;
Entries.IUnknown.IID = WellKnownWindowsInterfaceIIDs.IID_IUnknown;
Entries.IUnknown.Vtable = IUnknownImpl.Vtable;
}
}
/// <summary>
/// A custom <see cref="WindowsRuntimeComWrappersMarshallerAttribute"/> implementation for <see cref="bool"/>.
/// </summary>
internal sealed unsafe class BooleanComWrappersMarshallerAttribute : WindowsRuntimeComWrappersMarshallerAttribute
{
/// <inheritdoc/>
public override void* GetOrCreateComInterfaceForObject(object value)
{
return WindowsRuntimeComWrappersMarshal.GetOrCreateComInterfaceForObject(value, CreateComInterfaceFlags.None);
}
/// <inheritdoc/>
public override ComInterfaceEntry* ComputeVtables(out int count)
{
count = sizeof(BooleanInterfaceEntries) / sizeof(ComInterfaceEntry);
return (ComInterfaceEntry*)Unsafe.AsPointer(in BooleanInterfaceEntriesImpl.Entries);
}
/// <inheritdoc/>
public override object CreateObject(void* value, out CreatedWrapperFlags wrapperFlags)
{
wrapperFlags = CreatedWrapperFlags.NonWrapping;
return WindowsRuntimeValueTypeMarshaller.UnboxToManagedUnsafe<bool>(value, in WellKnownWindowsInterfaceIIDs.IID_IReferenceOfBool);
}
}
/// <summary>
/// Binding type for the <c>IReference`1</c> implementation for <see cref="bool"/>.
/// </summary>
[StructLayout(LayoutKind.Sequential)]
file unsafe struct BooleanReferenceVftbl
{
public delegate* unmanaged[MemberFunction]<void*, Guid*, void**, HRESULT> QueryInterface;
public delegate* unmanaged[MemberFunction]<void*, uint> AddRef;
public delegate* unmanaged[MemberFunction]<void*, uint> Release;
public delegate* unmanaged[MemberFunction]<void*, uint*, Guid**, HRESULT> GetIids;
public delegate* unmanaged[MemberFunction]<void*, HSTRING*, HRESULT> GetRuntimeClassName;
public delegate* unmanaged[MemberFunction]<void*, TrustLevel*, HRESULT> GetTrustLevel;
public delegate* unmanaged[MemberFunction]<void*, bool*, HRESULT> get_Value;
}
/// <summary>
/// The <c>IReference`1</c> implementation for <see cref="bool"/>.
/// </summary>
file static unsafe class BooleanReferenceImpl
{
/// <summary>
/// The <see cref="BooleanReferenceVftbl"/> value for the managed <c>IReference`1</c> implementation.
/// </summary>
[FixedAddressValueType]
private static readonly BooleanReferenceVftbl Vftbl;
/// <summary>
/// Initializes <see cref="Vftbl"/>.
/// </summary>
static BooleanReferenceImpl()
{
*(IInspectableVftbl*)Unsafe.AsPointer(ref Vftbl) = *(IInspectableVftbl*)IInspectableImpl.Vtable;
Vftbl.get_Value = &get_Value;
}
/// <summary>
/// Gets a pointer to the managed <c>IReference`1</c> implementation.
/// </summary>
public static nint Vtable
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => (nint)Unsafe.AsPointer(in Vftbl);
}
/// <see href="https://learn.microsoft.com/uwp/api/windows.foundation.ireference-1.value"/>
[UnmanagedCallersOnly(CallConvs = [typeof(CallConvMemberFunction)])]
public static HRESULT get_Value(void* thisPtr, bool* result)
{
if (result is null)
{
return WellKnownErrorCodes.E_POINTER;
}
try
{
*result = (bool)ComInterfaceDispatch.GetInstance<object>((ComInterfaceDispatch*)thisPtr);
return WellKnownErrorCodes.S_OK;
}
catch (global::System.Exception e)
{
return RestrictedErrorInfoExceptionMarshaller.ConvertToUnmanaged(e);
}
}
}
/// <summary>
/// The <c>IPropertyValue</c> implementation for <see cref="bool"/>.
/// </summary>
file static unsafe class BooleanPropertyValueImpl
{
/// <summary>
/// The <see cref="IPropertyValueVftbl"/> value for the managed <c>IPropertyValue</c> implementation.
/// </summary>
[FixedAddressValueType]
private static readonly IPropertyValueVftbl Vftbl;
/// <summary>
/// Initializes <see cref="Vftbl"/>.
/// </summary>
static BooleanPropertyValueImpl()
{
*(IInspectableVftbl*)Unsafe.AsPointer(ref Vftbl) = *(IInspectableVftbl*)IInspectableImpl.Vtable;
Vftbl.get_Type = &get_Type;
Vftbl.get_IsNumericScalar = &IPropertyValueImpl.get_IsNumericScalarFalse;
Vftbl.GetUInt8 = &IPropertyValueImpl.ThrowStubForGetOverloads;
Vftbl.GetInt16 = &IPropertyValueImpl.ThrowStubForGetOverloads;
Vftbl.GetUInt16 = &IPropertyValueImpl.ThrowStubForGetOverloads;
Vftbl.GetInt32 = &IPropertyValueImpl.ThrowStubForGetOverloads;
Vftbl.GetUInt32 = &IPropertyValueImpl.ThrowStubForGetOverloads;
Vftbl.GetInt64 = &IPropertyValueImpl.ThrowStubForGetOverloads;
Vftbl.GetUInt64 = &IPropertyValueImpl.ThrowStubForGetOverloads;
Vftbl.GetSingle = &IPropertyValueImpl.ThrowStubForGetOverloads;
Vftbl.GetDouble = &IPropertyValueImpl.ThrowStubForGetOverloads;
Vftbl.GetChar16 = &IPropertyValueImpl.ThrowStubForGetOverloads;
Vftbl.GetBoolean = &BooleanReferenceImpl.get_Value;
Vftbl.GetString = &IPropertyValueImpl.ThrowStubForGetOverloads;
Vftbl.GetGuid = &IPropertyValueImpl.ThrowStubForGetOverloads;
Vftbl.GetDateTime = &IPropertyValueImpl.ThrowStubForGetOverloads;
Vftbl.GetTimeSpan = &IPropertyValueImpl.ThrowStubForGetOverloads;
Vftbl.GetPoint = &IPropertyValueImpl.ThrowStubForGetOverloads;
Vftbl.GetSize = &IPropertyValueImpl.ThrowStubForGetOverloads;
Vftbl.GetRect = &IPropertyValueImpl.ThrowStubForGetOverloads;
Vftbl.GetUInt8Array = (delegate* unmanaged[MemberFunction]<void*, uint*, byte**, HRESULT>)(delegate* unmanaged[MemberFunction]<void*, uint*, void**, HRESULT>)&IPropertyValueImpl.ThrowStubForGetArrayOverloads;
Vftbl.GetInt16Array = (delegate* unmanaged[MemberFunction]<void*, uint*, short**, HRESULT>)(delegate* unmanaged[MemberFunction]<void*, uint*, void**, HRESULT>)&IPropertyValueImpl.ThrowStubForGetArrayOverloads;
Vftbl.GetUInt16Array = (delegate* unmanaged[MemberFunction]<void*, uint*, ushort**, HRESULT>)(delegate* unmanaged[MemberFunction]<void*, uint*, void**, HRESULT>)&IPropertyValueImpl.ThrowStubForGetArrayOverloads;
Vftbl.GetInt32Array = (delegate* unmanaged[MemberFunction]<void*, uint*, int**, HRESULT>)(delegate* unmanaged[MemberFunction]<void*, uint*, void**, HRESULT>)&IPropertyValueImpl.ThrowStubForGetArrayOverloads;
Vftbl.GetUInt32Array = (delegate* unmanaged[MemberFunction]<void*, uint*, uint**, HRESULT>)(delegate* unmanaged[MemberFunction]<void*, uint*, void**, HRESULT>)&IPropertyValueImpl.ThrowStubForGetArrayOverloads;
Vftbl.GetInt64Array = (delegate* unmanaged[MemberFunction]<void*, uint*, long**, HRESULT>)(delegate* unmanaged[MemberFunction]<void*, uint*, void**, HRESULT>)&IPropertyValueImpl.ThrowStubForGetArrayOverloads;
Vftbl.GetUInt64Array = (delegate* unmanaged[MemberFunction]<void*, uint*, ulong**, HRESULT>)(delegate* unmanaged[MemberFunction]<void*, uint*, void**, HRESULT>)&IPropertyValueImpl.ThrowStubForGetArrayOverloads;
Vftbl.GetSingleArray = (delegate* unmanaged[MemberFunction]<void*, uint*, float**, HRESULT>)(delegate* unmanaged[MemberFunction]<void*, uint*, void**, HRESULT>)&IPropertyValueImpl.ThrowStubForGetArrayOverloads;
Vftbl.GetDoubleArray = (delegate* unmanaged[MemberFunction]<void*, uint*, double**, HRESULT>)(delegate* unmanaged[MemberFunction]<void*, uint*, void**, HRESULT>)&IPropertyValueImpl.ThrowStubForGetArrayOverloads;
Vftbl.GetChar16Array = (delegate* unmanaged[MemberFunction]<void*, uint*, char**, HRESULT>)(delegate* unmanaged[MemberFunction]<void*, uint*, void**, HRESULT>)&IPropertyValueImpl.ThrowStubForGetArrayOverloads;
Vftbl.GetBooleanArray = (delegate* unmanaged[MemberFunction]<void*, uint*, bool**, HRESULT>)(delegate* unmanaged[MemberFunction]<void*, uint*, void**, HRESULT>)&IPropertyValueImpl.ThrowStubForGetArrayOverloads;
Vftbl.GetStringArray = (delegate* unmanaged[MemberFunction]<void*, uint*, HSTRING**, HRESULT>)(delegate* unmanaged[MemberFunction]<void*, uint*, void**, HRESULT>)&IPropertyValueImpl.ThrowStubForGetArrayOverloads;
Vftbl.GetInspectableArray = (delegate* unmanaged[MemberFunction]<void*, uint*, void***, HRESULT>)(delegate* unmanaged[MemberFunction]<void*, uint*, void**, HRESULT>)&IPropertyValueImpl.ThrowStubForGetArrayOverloads;
Vftbl.GetGuidArray = (delegate* unmanaged[MemberFunction]<void*, uint*, Guid**, HRESULT>)(delegate* unmanaged[MemberFunction]<void*, uint*, void**, HRESULT>)&IPropertyValueImpl.ThrowStubForGetArrayOverloads;
Vftbl.GetDateTimeArray = (delegate* unmanaged[MemberFunction]<void*, uint*, DateTimeOffset**, HRESULT>)(delegate* unmanaged[MemberFunction]<void*, uint*, void**, HRESULT>)&IPropertyValueImpl.ThrowStubForGetArrayOverloads;
Vftbl.GetTimeSpanArray = (delegate* unmanaged[MemberFunction]<void*, uint*, TimeSpan**, HRESULT>)(delegate* unmanaged[MemberFunction]<void*, uint*, void**, HRESULT>)&IPropertyValueImpl.ThrowStubForGetArrayOverloads;
Vftbl.GetPointArray = (delegate* unmanaged[MemberFunction]<void*, uint*, Point**, HRESULT>)(delegate* unmanaged[MemberFunction]<void*, uint*, void**, HRESULT>)&IPropertyValueImpl.ThrowStubForGetArrayOverloads;
Vftbl.GetSizeArray = (delegate* unmanaged[MemberFunction]<void*, uint*, Size**, HRESULT>)(delegate* unmanaged[MemberFunction]<void*, uint*, void**, HRESULT>)&IPropertyValueImpl.ThrowStubForGetArrayOverloads;
Vftbl.GetRectArray = (delegate* unmanaged[MemberFunction]<void*, uint*, Rect**, HRESULT>)(delegate* unmanaged[MemberFunction]<void*, uint*, void**, HRESULT>)&IPropertyValueImpl.ThrowStubForGetArrayOverloads;
}
/// <summary>
/// Gets a pointer to the managed <c>IPropertyValue</c> implementation.
/// </summary>
public static nint Vtable
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => (nint)Unsafe.AsPointer(in Vftbl);
}
/// <see href="https://learn.microsoft.com/uwp/api/windows.foundation.ipropertyvalue.type"/>
[UnmanagedCallersOnly(CallConvs = [typeof(CallConvMemberFunction)])]
private static HRESULT get_Type(void* thisPtr, PropertyType* value)
{
if (value is null)
{
return WellKnownErrorCodes.E_POINTER;
}
*value = PropertyType.Boolean;
return WellKnownErrorCodes.S_OK;
}
}