-
Notifications
You must be signed in to change notification settings - Fork 127
Expand file tree
/
Copy pathInteropGeneratorDiscoveryState.cs
More file actions
576 lines (465 loc) · 24.9 KB
/
Copy pathInteropGeneratorDiscoveryState.cs
File metadata and controls
576 lines (465 loc) · 24.9 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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using AsmResolver.DotNet;
using AsmResolver.DotNet.Signatures;
using WindowsRuntime.Generator;
using WindowsRuntime.InteropGenerator.Errors;
using WindowsRuntime.InteropGenerator.Models;
namespace WindowsRuntime.InteropGenerator.Generation;
/// <summary>
/// Global state tracking type for <see cref="InteropGenerator"/>, specifically for the discovery phase.
/// </summary>
internal sealed class InteropGeneratorDiscoveryState
{
/// <summary>Backing field for <see cref="Modules"/>.</summary>
private readonly ConcurrentDictionary<string, ModuleDefinition> _modules = [];
/// <summary>Backing field for <see cref="WindowsRuntimeSdkProjectionModule"/>.</summary>
private ModuleDefinition? _windowsRuntimeSdkProjectionModule;
/// <summary>Backing field for <see cref="WindowsRuntimeSdkXamlProjectionModule"/>.</summary>
private ModuleDefinition? _windowsRuntimeSdkXamlProjectionModule;
/// <summary>Backing field for <see cref="WindowsRuntimeProjectionModule"/>.</summary>
private ModuleDefinition? _windowsRuntimeProjectionModule;
/// <summary>Backing field for <see cref="WindowsRuntimeComponentModule"/>.</summary>
private ModuleDefinition? _windowsRuntimeComponentModule;
/// <summary>Backing field for <see cref="TypeHierarchyEntries"/>.</summary>
private readonly ConcurrentDictionary<string, string> _typeHierarchyEntries = [];
/// <summary>Backing field for <see cref="IEnumerator1Types"/>.</summary>
private readonly ConcurrentDictionary<GenericInstanceTypeSignature, byte> _ienumerator1Types = new(SignatureComparer.IgnoreVersion);
/// <summary>Backing field for <see cref="IEnumerable1Types"/>.</summary>
private readonly ConcurrentDictionary<GenericInstanceTypeSignature, byte> _ienumerable1Types = new(SignatureComparer.IgnoreVersion);
/// <summary>Backing field for <see cref="IList1Types"/>.</summary>
private readonly ConcurrentDictionary<GenericInstanceTypeSignature, byte> _ilist1Types = new(SignatureComparer.IgnoreVersion);
/// <summary>Backing field for <see cref="IReadOnlyList1Types"/>.</summary>
private readonly ConcurrentDictionary<GenericInstanceTypeSignature, byte> _ireadOnlyList1Types = new(SignatureComparer.IgnoreVersion);
/// <summary>Backing field for <see cref="IDictionary2Types"/>.</summary>
private readonly ConcurrentDictionary<GenericInstanceTypeSignature, byte> _idictionary2Types = new(SignatureComparer.IgnoreVersion);
/// <summary>Backing field for <see cref="IReadOnlyDictionary2Types"/>.</summary>
private readonly ConcurrentDictionary<GenericInstanceTypeSignature, byte> _ireadOnlyDictionary2Types = new(SignatureComparer.IgnoreVersion);
/// <summary>Backing field for <see cref="IObservableVector1Types"/>.</summary>
private readonly ConcurrentDictionary<GenericInstanceTypeSignature, byte> _iobservableVector1Types = new(SignatureComparer.IgnoreVersion);
/// <summary>Backing field for <see cref="IObservableMap2Types"/>.</summary>
private readonly ConcurrentDictionary<GenericInstanceTypeSignature, byte> _iobservableMap2Types = new(SignatureComparer.IgnoreVersion);
/// <summary>Backing field for <see cref="IMapChangedEventArgs1Types"/>.</summary>
private readonly ConcurrentDictionary<GenericInstanceTypeSignature, byte> _imapChangedEventArgs1Types = new(SignatureComparer.IgnoreVersion);
/// <summary>Backing field for <see cref="IAsyncActionWithProgress1Types"/>.</summary>
private readonly ConcurrentDictionary<GenericInstanceTypeSignature, byte> _iasyncActionWithProgress1Types = new(SignatureComparer.IgnoreVersion);
/// <summary>Backing field for <see cref="IAsyncOperation1Types"/>.</summary>
private readonly ConcurrentDictionary<GenericInstanceTypeSignature, byte> _iasyncOperation1Types = new(SignatureComparer.IgnoreVersion);
/// <summary>Backing field for <see cref="IAsyncOperationWithProgress2Types"/>.</summary>
private readonly ConcurrentDictionary<GenericInstanceTypeSignature, byte> _iasyncOperationWithProgress2Types = new(SignatureComparer.IgnoreVersion);
/// <summary>Backing field for <see cref="GenericDelegateTypes"/>.</summary>
private readonly ConcurrentDictionary<GenericInstanceTypeSignature, byte> _genericDelegateTypes = new(SignatureComparer.IgnoreVersion);
/// <summary>Backing field for <see cref="KeyValuePairTypes"/>.</summary>
private readonly ConcurrentDictionary<GenericInstanceTypeSignature, byte> _keyValuePairTypes = new(SignatureComparer.IgnoreVersion);
/// <summary>Backing field to support <see cref="TryMarkUserDefinedType"/>.</summary>
private readonly ConcurrentDictionary<TypeSignature, byte> _markedUserDefinedTypes = new(SignatureComparer.IgnoreVersion);
/// <summary>Backing field to support <see cref="TryMarkSzArrayType"/>.</summary>
private readonly ConcurrentDictionary<TypeSignature, byte> _markedSzArrayTypes = new(SignatureComparer.IgnoreVersion);
/// <summary>Backing field to support <see cref="TryMarkWindowsRuntimeGenericInterfaceTypeInstance"/>.</summary>
private readonly ConcurrentDictionary<TypeSignature, byte> _markedWindowsRuntimeGenericInterfaceTypeInstances = new(SignatureComparer.IgnoreVersion);
/// <summary>Backing field for <see cref="UserDefinedAndVtableTypes"/>.</summary>
private readonly ConcurrentDictionary<TypeSignature, TypeSignatureEquatableSet> _userDefinedTypes = new(SignatureComparer.IgnoreVersion);
/// <summary>Backing field for <see cref="SzArrayAndVtableTypes"/>.</summary>
private readonly ConcurrentDictionary<SzArrayTypeSignature, TypeSignatureEquatableSet> _szArrayTypes = new(SignatureComparer.IgnoreVersion);
/// <summary>Backing field for <see cref="UserDefinedVtableTypes"/>.</summary>
/// <remarks>
/// The value is also <see cref="TypeSignatureEquatableSet"/> so we can de-duplicate equivalent sets across different maps (e.g. <see cref="_userDefinedTypes"/>).
/// </remarks>
private readonly ConcurrentDictionary<TypeSignatureEquatableSet, TypeSignatureEquatableSet> _userDefinedVtableTypes = [];
/// <summary>
/// The mapping of all types that failed resolution.
/// </summary>
private readonly ConcurrentDictionary<(TypeSignature, ModuleDefinition), byte> _failedResolutionTypes = new(SignatureComparer.IgnoreVersion.MakeValueTupleLeftComparer<ModuleDefinition>());
/// <summary>
/// Indicates whether the current state is readonly.
/// </summary>
private volatile bool _isReadOnly;
/// <summary>
/// Indicates whether any of the loaded modules reference the WinRT runtime .dll version 2.
/// </summary>
private volatile bool _hasWinRTRuntimeDllVersion2References;
/// <summary>
/// Gets the runtime context to use for the current invocation.
/// </summary>
public required RuntimeContext RuntimeContext { get; init; }
/// <summary>
/// Gets the loaded modules.
/// </summary>
public IReadOnlyDictionary<string, ModuleDefinition> Modules => _modules;
/// <summary>
/// Gets the <see cref="ModuleDefinition"/> for <c>WinRT.Sdk.Projection.dll</c>.
/// </summary>
public ModuleDefinition? WindowsRuntimeSdkProjectionModule => _windowsRuntimeSdkProjectionModule;
/// <summary>
/// Gets the <see cref="ModuleDefinition"/> for <c>WinRT.Sdk.Xaml.Projection.dll</c>.
/// </summary>
public ModuleDefinition? WindowsRuntimeSdkXamlProjectionModule => _windowsRuntimeSdkXamlProjectionModule;
/// <summary>
/// Gets the <see cref="ModuleDefinition"/> for <c>WinRT.Projection.dll</c>.
/// </summary>
public ModuleDefinition? WindowsRuntimeProjectionModule => _windowsRuntimeProjectionModule;
/// <summary>
/// Gets the <see cref="ModuleDefinition"/> for <c>WinRT.Component.dll</c>.
/// </summary>
public ModuleDefinition? WindowsRuntimeComponentModule => _windowsRuntimeComponentModule;
/// <summary>
/// Gets the type hierarchy entries.
/// </summary>
public IReadOnlyDictionary<string, string> TypeHierarchyEntries => _typeHierarchyEntries;
/// <summary>
/// Gets all <see cref="IEnumerator{T}"/> types.
/// </summary>
public IReadOnlyCollection<GenericInstanceTypeSignature> IEnumerator1Types => (IReadOnlyCollection<GenericInstanceTypeSignature>)_ienumerator1Types.Keys;
/// <summary>
/// Gets all <see cref="IEnumerable{T}"/> types.
/// </summary>
public IReadOnlyCollection<GenericInstanceTypeSignature> IEnumerable1Types => (IReadOnlyCollection<GenericInstanceTypeSignature>)_ienumerable1Types.Keys;
/// <summary>
/// Gets all <see cref="IList{T}"/> types.
/// </summary>
public IReadOnlyCollection<GenericInstanceTypeSignature> IList1Types => (IReadOnlyCollection<GenericInstanceTypeSignature>)_ilist1Types.Keys;
/// <summary>
/// Gets all <see cref="IReadOnlyList{T}"/> types.
/// </summary>
public IReadOnlyCollection<GenericInstanceTypeSignature> IReadOnlyList1Types => (IReadOnlyCollection<GenericInstanceTypeSignature>)_ireadOnlyList1Types.Keys;
/// <summary>
/// Gets all <see cref="IDictionary{TKey, TValue}"/> types.
/// </summary>
public IReadOnlyCollection<GenericInstanceTypeSignature> IDictionary2Types => (IReadOnlyCollection<GenericInstanceTypeSignature>)_idictionary2Types.Keys;
/// <summary>
/// Gets all <see cref="IReadOnlyDictionary{TKey, TValue}"/> types.
/// </summary>
public IReadOnlyCollection<GenericInstanceTypeSignature> IReadOnlyDictionary2Types => (IReadOnlyCollection<GenericInstanceTypeSignature>)_ireadOnlyDictionary2Types.Keys;
/// <summary>
/// Gets all <c>Windows.Foundation.Collections.IObservableVector<T></c> types.
/// </summary>
public IReadOnlyCollection<GenericInstanceTypeSignature> IObservableVector1Types => (IReadOnlyCollection<GenericInstanceTypeSignature>)_iobservableVector1Types.Keys;
/// <summary>
/// Gets all <c>Windows.Foundation.Collections.IObservableMap<K, V></c> types.
/// </summary>
public IReadOnlyCollection<GenericInstanceTypeSignature> IObservableMap2Types => (IReadOnlyCollection<GenericInstanceTypeSignature>)_iobservableMap2Types.Keys;
/// <summary>
/// Gets all <c>Windows.Foundation.Collections.IMapChangedEventArgs<K></c> types.
/// </summary>
public IReadOnlyCollection<GenericInstanceTypeSignature> IMapChangedEventArgs1Types => (IReadOnlyCollection<GenericInstanceTypeSignature>)_imapChangedEventArgs1Types.Keys;
/// <summary>
/// Gets all <c>Windows.Foundation.IAsyncActionWithProgress<TProgress></c> types.
/// </summary>
public IReadOnlyCollection<GenericInstanceTypeSignature> IAsyncActionWithProgress1Types => (IReadOnlyCollection<GenericInstanceTypeSignature>)_iasyncActionWithProgress1Types.Keys;
/// <summary>
/// Gets all <c>Windows.Foundation.IAsyncOperation<TResult></c> types.
/// </summary>
public IReadOnlyCollection<GenericInstanceTypeSignature> IAsyncOperation1Types => (IReadOnlyCollection<GenericInstanceTypeSignature>)_iasyncOperation1Types.Keys;
/// <summary>
/// Gets all <c>Windows.Foundation.IAsyncOperationWithProgress<TResult, TProgress></c> types.
/// </summary>
public IReadOnlyCollection<GenericInstanceTypeSignature> IAsyncOperationWithProgress2Types => (IReadOnlyCollection<GenericInstanceTypeSignature>)_iasyncOperationWithProgress2Types.Keys;
/// <summary>
/// Gets all generic delegate types.
/// </summary>
public IReadOnlyCollection<GenericInstanceTypeSignature> GenericDelegateTypes => (IReadOnlyCollection<GenericInstanceTypeSignature>)_genericDelegateTypes.Keys;
/// <summary>
/// Gets all <see cref="KeyValuePair{TKey, TValue}"/> types.
/// </summary>
public IReadOnlyCollection<GenericInstanceTypeSignature> KeyValuePairTypes => (IReadOnlyCollection<GenericInstanceTypeSignature>)_keyValuePairTypes.Keys;
/// <summary>
/// Gets all user-defined types.
/// </summary>
public IReadOnlyCollection<TypeSignature> UserDefinedTypes => (IReadOnlyCollection<TypeSignature>)_userDefinedTypes.Keys;
/// <summary>
/// Gets all user-defined types and their vtable types.
/// </summary>
public IReadOnlyDictionary<TypeSignature, TypeSignatureEquatableSet> UserDefinedAndVtableTypes => _userDefinedTypes;
/// <summary>
/// Gets all user-defined vtable types (for each user-defined type).
/// </summary>
public IReadOnlyCollection<TypeSignatureEquatableSet> UserDefinedVtableTypes => (IReadOnlyCollection<TypeSignatureEquatableSet>)_userDefinedVtableTypes.Keys;
/// <summary>
/// Gets all SZ array types and their vtable types.
/// </summary>
public IReadOnlyDictionary<SzArrayTypeSignature, TypeSignatureEquatableSet> SzArrayAndVtableTypes => _szArrayTypes;
/// <summary>
/// Gets whether any of the loaded modules reference the WinRT runtime .dll version 2.
/// </summary>
public bool HasWinRTRuntimeDllVersion2References => _hasWinRTRuntimeDllVersion2References;
/// <summary>
/// Tracks a loaded module definition.
/// </summary>
/// <param name="path">The assembly path.</param>
/// <param name="module">The loaded module.</param>
public void TrackModule(string path, ModuleDefinition module)
{
ThrowIfReadOnly();
_ = _modules.TryAdd(path, module);
}
/// <summary>
/// Tracks the <c>WinRT.Sdk.Projection.dll</c> loaded module definition.
/// </summary>
/// <param name="module">The loaded module.</param>
[MemberNotNull(nameof(_windowsRuntimeSdkProjectionModule))]
public void TrackWindowsRuntimeSdkProjectionModule(ModuleDefinition module)
{
ThrowIfReadOnly();
_windowsRuntimeSdkProjectionModule = module;
}
/// <summary>
/// Tracks the <c>WinRT.Sdk.Xaml.Projection.dll</c> loaded module definition.
/// </summary>
/// <param name="module">The loaded module.</param>
[MemberNotNull(nameof(_windowsRuntimeSdkXamlProjectionModule))]
public void TrackWindowsRuntimeSdkXamlProjectionModule(ModuleDefinition module)
{
ThrowIfReadOnly();
_windowsRuntimeSdkXamlProjectionModule = module;
}
/// <summary>
/// Tracks the <c>WinRT.Projection.dll</c> loaded module definition.
/// </summary>
/// <param name="module">The loaded module.</param>
[MemberNotNull(nameof(_windowsRuntimeProjectionModule))]
public void TrackWindowsRuntimeProjectionModule(ModuleDefinition module)
{
ThrowIfReadOnly();
_windowsRuntimeProjectionModule = module;
}
/// <summary>
/// Tracks the <c>WinRT.Component.dll</c> loaded module definition.
/// </summary>
/// <param name="module">The loaded module.</param>
[MemberNotNull(nameof(_windowsRuntimeComponentModule))]
public void TrackWindowsRuntimeComponentModule(ModuleDefinition module)
{
ThrowIfReadOnly();
_windowsRuntimeComponentModule = module;
}
/// <summary>
/// Tracks a pair of runtime class names for the type hierarchy.
/// </summary>
/// <param name="runtimeClassName">The runtime class name to use as key.</param>
/// <param name="baseRuntimeClassName">The runtime class name of the base type.</param>
public void TrackTypeHierarchyEntry(string runtimeClassName, string baseRuntimeClassName)
{
ThrowIfReadOnly();
_ = _typeHierarchyEntries.TryAdd(runtimeClassName, baseRuntimeClassName);
}
/// <summary>
/// Tracks a <see cref="IEnumerator{T}"/> type.
/// </summary>
/// <param name="enumeratorType">The <see cref="IEnumerator{T}"/> type.</param>
public void TrackIEnumerator1Type(GenericInstanceTypeSignature enumeratorType)
{
ThrowIfReadOnly();
_ = _ienumerator1Types.TryAdd(enumeratorType, 0);
}
/// <summary>
/// Tracks a <see cref="IEnumerable{T}"/> type.
/// </summary>
/// <param name="enumerableType">The <see cref="IEnumerable{T}"/> type.</param>
public void TrackIEnumerable1Type(GenericInstanceTypeSignature enumerableType)
{
ThrowIfReadOnly();
_ = _ienumerable1Types.TryAdd(enumerableType, 0);
}
/// <summary>
/// Tracks a <see cref="IList{T}"/> type.
/// </summary>
/// <param name="listType">The <see cref="IList{T}"/> type.</param>
public void TrackIList1Type(GenericInstanceTypeSignature listType)
{
ThrowIfReadOnly();
_ = _ilist1Types.TryAdd(listType, 0);
}
/// <summary>
/// Tracks a <see cref="IReadOnlyList{T}"/> type.
/// </summary>
/// <param name="listType">The <see cref="IReadOnlyList{T}"/> type.</param>
public void TrackIReadOnlyList1Type(GenericInstanceTypeSignature listType)
{
ThrowIfReadOnly();
_ = _ireadOnlyList1Types.TryAdd(listType, 0);
}
/// <summary>
/// Tracks a <see cref="IDictionary{TKey, TValue}"/> type.
/// </summary>
/// <param name="dictionaryType">The <see cref="IDictionary{TKey, TValue}"/> type.</param>
public void TrackIDictionary2Type(GenericInstanceTypeSignature dictionaryType)
{
ThrowIfReadOnly();
_ = _idictionary2Types.TryAdd(dictionaryType, 0);
}
/// <summary>
/// Tracks a <see cref="IReadOnlyDictionary{TKey, TValue}"/> type.
/// </summary>
/// <param name="dictionaryType">The <see cref="IReadOnlyDictionary{TKey, TValue}"/> type.</param>
public void TrackIReadOnlyDictionary2Type(GenericInstanceTypeSignature dictionaryType)
{
ThrowIfReadOnly();
_ = _ireadOnlyDictionary2Types.TryAdd(dictionaryType, 0);
}
/// <summary>
/// Tracks a <c>Windows.Foundation.Collections.IObservableVector<T></c> type.
/// </summary>
/// <param name="vectorType">The <c>Windows.Foundation.Collections.IObservableVector<T></c> type.</param>
public void TrackIObservableVector1Type(GenericInstanceTypeSignature vectorType)
{
ThrowIfReadOnly();
_ = _iobservableVector1Types.TryAdd(vectorType, 0);
}
/// <summary>
/// Tracks a <c>Windows.Foundation.Collections.IObservableMap<K, V></c> type.
/// </summary>
/// <param name="mapType">The <c>Windows.Foundation.Collections.IObservableMap<K, V></c> type.</param>
public void TrackIObservableMap2Type(GenericInstanceTypeSignature mapType)
{
ThrowIfReadOnly();
_ = _iobservableMap2Types.TryAdd(mapType, 0);
}
/// <summary>
/// Tracks a <c>Windows.Foundation.Collections.IMapChangedEventArgs<K></c> type.
/// </summary>
/// <param name="argsType">The <c>Windows.Foundation.Collections.IMapChangedEventArgs<K></c> type.</param>
public void TrackIMapChangedEventArgs1Type(GenericInstanceTypeSignature argsType)
{
ThrowIfReadOnly();
_ = _imapChangedEventArgs1Types.TryAdd(argsType, 0);
}
/// <summary>
/// Tracks a <c>Windows.Foundation.IAsyncActionWithProgress<TProgress></c> type.
/// </summary>
/// <param name="actionType">The <c>Windows.Foundation.IAsyncActionWithProgress<TProgress></c> type.</param>
public void TrackIAsyncActionWithProgress1Type(GenericInstanceTypeSignature actionType)
{
ThrowIfReadOnly();
_ = _iasyncActionWithProgress1Types.TryAdd(actionType, 0);
}
/// <summary>
/// Tracks a <c>Windows.Foundation.IAsyncOperation<TResult></c> type.
/// </summary>
/// <param name="operationType">The <c>Windows.Foundation.IAsyncOperation<TResult></c> type.</param>
public void TrackIAsyncOperation1Type(GenericInstanceTypeSignature operationType)
{
ThrowIfReadOnly();
_ = _iasyncOperation1Types.TryAdd(operationType, 0);
}
/// <summary>
/// Tracks a <c>Windows.Foundation.IAsyncOperationWithProgress<TResult, TProgress></c> type.
/// </summary>
/// <param name="operationType">The <c>Windows.Foundation.IAsyncOperationWithProgress<TResult, TProgress></c> type.</param>
public void TrackIAsyncOperationWithProgress2Type(GenericInstanceTypeSignature operationType)
{
ThrowIfReadOnly();
_ = _iasyncOperationWithProgress2Types.TryAdd(operationType, 0);
}
/// <summary>
/// Tracks a generic delegate type.
/// </summary>
/// <param name="delegateType">The delegate type.</param>
public void TrackGenericDelegateType(GenericInstanceTypeSignature delegateType)
{
ThrowIfReadOnly();
_ = _genericDelegateTypes.TryAdd(delegateType, 0);
}
/// <summary>
/// Tracks a <see cref="KeyValuePair{TKey, TValue}"/> type.
/// </summary>
/// <param name="keyValuePairType">The <see cref="KeyValuePair{TKey, TValue}"/> type.</param>
public void TrackKeyValuePairType(GenericInstanceTypeSignature keyValuePairType)
{
ThrowIfReadOnly();
_ = _keyValuePairTypes.TryAdd(keyValuePairType, 0);
}
/// <summary>
/// Tries to mark a user-defined type as having been seen the first time,
/// and indicating that it's in the process of being processed.
/// </summary>
/// <param name="userDefinedType">The user-defined type.</param>
/// <returns>Whether this was the first time that <paramref name="userDefinedType"/> was seen.</returns>
public bool TryMarkUserDefinedType(TypeSignature userDefinedType)
{
return _markedUserDefinedTypes.TryAdd(userDefinedType, 0);
}
/// <summary>
/// Tries to mark an SZ array type as having been seen the first time,
/// and indicating that it's in the process of being processed.
/// </summary>
/// <param name="arrayType">The SZ array type.</param>
/// <returns>Whether this was the first time that <paramref name="arrayType"/> was seen.</returns>
public bool TryMarkSzArrayType(SzArrayTypeSignature arrayType)
{
return _markedSzArrayTypes.TryAdd(arrayType, 0);
}
/// <summary>
/// Tries to mark a constructed generic Windows Runtime interface type as having been seen the first time,
/// and indicating that it's in the process of being processed.
/// </summary>
/// <param name="interfaceType">The constructed generic Windows Runtime interface type.</param>
/// <returns>Whether this was the first time that <paramref name="interfaceType"/> was seen.</returns>
public bool TryMarkWindowsRuntimeGenericInterfaceTypeInstance(GenericInstanceTypeSignature interfaceType)
{
return _markedWindowsRuntimeGenericInterfaceTypeInstances.TryAdd(interfaceType, 0);
}
/// <summary>
/// Tracks a user-defined type.
/// </summary>
/// <param name="userDefinedType">The user-defined type.</param>
/// <param name="vtableTypes">The vtable types for <paramref name="userDefinedType"/>.</param>
public void TrackUserDefinedType(TypeSignature userDefinedType, TypeSignatureEquatableSet vtableTypes)
{
ThrowIfReadOnly();
// We want to de-duplicate all vtables across all user-defined types we need to generate CCW code for.
// This is because a significant portion of these vtables will be identical (it will be the case for
// all user-defined types that implement the same set of projected Windows Runtime interfaces). So here
// we first add this set to our map, and reuse the cached instance for this set (if it exists) later.
TypeSignatureEquatableSet cachedVtableTypes = _userDefinedVtableTypes.GetOrAdd(vtableTypes, vtableTypes);
_ = _userDefinedTypes.TryAdd(userDefinedType, cachedVtableTypes);
}
/// <summary>
/// Tracks an SZ array type.
/// </summary>
/// <param name="arrayType">The SZ array type.</param>
/// <param name="vtableTypes">The vtable types for <paramref name="arrayType"/>.</param>
public void TrackSzArrayType(SzArrayTypeSignature arrayType, TypeSignatureEquatableSet vtableTypes)
{
ThrowIfReadOnly();
_ = _szArrayTypes.TryAdd(arrayType, vtableTypes);
}
/// <summary>
/// Tracks a type that failed resolution.
/// </summary>
/// <param name="failedType">The type that failed resolution.</param>
/// <param name="module">The module in which the type resolution was attempted.</param>
/// <returns>Whether this is the first time this type failed resolution.</returns>
public bool TrackFailedResolutionType(TypeSignature failedType, ModuleDefinition module)
{
ThrowIfReadOnly();
return _failedResolutionTypes.TryAdd((failedType, module), 0);
}
/// <summary>
/// Marks the current state as readonly.
/// </summary>
public void MakeReadOnly()
{
_isReadOnly = true;
}
/// <summary>
/// Marks the state as having references to the WinRT runtime .dll version 2.
/// </summary>
public void MarkWinRTRuntimeDllVersion2References()
{
ThrowIfReadOnly();
_hasWinRTRuntimeDllVersion2References = true;
}
/// <summary>
/// Throws if <see cref="MakeReadOnly"/> was called.
/// </summary>
private void ThrowIfReadOnly()
{
if (_isReadOnly)
{
throw WellKnownInteropExceptions.DiscoveryStateChangeAfterMakeReadOnlyError();
}
}
}