IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
IkvmReflectionTypeSymbol.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Diagnostics;
4using System.Linq;
5using System.Reflection.Metadata.Ecma335;
6using System.Threading;
7
9
10using ConstructorInfo = IKVM.Reflection.ConstructorInfo;
11using EventInfo = IKVM.Reflection.EventInfo;
12using FieldInfo = IKVM.Reflection.FieldInfo;
13using MethodBase = IKVM.Reflection.MethodBase;
14using MethodInfo = IKVM.Reflection.MethodInfo;
15using PropertyInfo = IKVM.Reflection.PropertyInfo;
16using Type = IKVM.Reflection.Type;
17
19{
20
22 {
23
24 const BindingFlags DefaultBindingFlags = BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance;
25
26 readonly Type _underlyingType;
27
28 MethodBase[]? _methodsSource;
29 int _methodsBaseRow;
31
32 FieldInfo[]? _fieldsSource;
33 int _fieldsBaseRow;
34 IkvmReflectionFieldSymbol?[]? _fields;
35
36 PropertyInfo[]? _propertiesSource;
37 int _propertiesBaseRow;
38 IkvmReflectionPropertySymbol?[]? _properties;
39
40 EventInfo[]? _eventsSource;
41 int _eventsBaseRow;
42 IkvmReflectionEventSymbol?[]? _events;
43
44 IkvmReflectionTypeSymbol?[]? _asArray;
45 IkvmReflectionTypeSymbol? _asSZArray;
46 IkvmReflectionTypeSymbol? _asPointer;
48
49 Type[]? _genericParametersSource;
50 IkvmReflectionTypeSymbol?[]? _genericParameters;
51 List<(Type[] Arguments, IkvmReflectionTypeSymbol Symbol)>? _genericTypes;
52 ReaderWriterLockSlim? _genericTypesLock;
53
61 base(context, module, null, underlyingType)
62 {
63 Debug.Assert(module.UnderlyingModule == underlyingType.Module);
64 _underlyingType = underlyingType ?? throw new ArgumentNullException(nameof(underlyingType));
65 }
66
72 internal IkvmReflectionMethodSymbol GetOrCreateMethodSymbol(MethodInfo method)
73 {
74 return (IkvmReflectionMethodSymbol)GetOrCreateMethodBaseSymbol(method);
75 }
76
82 internal IkvmReflectionConstructorSymbol GetOrCreateConstructorSymbol(ConstructorInfo ctor)
83 {
84 return (IkvmReflectionConstructorSymbol)GetOrCreateMethodBaseSymbol(ctor);
85 }
86
92 internal IkvmReflectionMethodBaseSymbol GetOrCreateMethodBaseSymbol(MethodBase method)
93 {
94 if (method is null)
95 throw new ArgumentNullException(nameof(method));
96
97 Debug.Assert(method.DeclaringType == _underlyingType);
98
99 var hnd = MetadataTokens.MethodDefinitionHandle(method.MetadataToken);
100 var row = MetadataTokens.GetRowNumber(hnd);
101
102 // initialize source table
103 if (_methodsSource == null)
104 {
105 Interlocked.CompareExchange(ref _methodsSource, _underlyingType.GetConstructors(DefaultBindingFlags).Cast<MethodBase>().Concat(_underlyingType.GetMethods(DefaultBindingFlags)).OrderBy(i => i.MetadataToken).ToArray(), null);
106 _methodsBaseRow = _methodsSource.Length != 0 ? MetadataTokens.GetRowNumber(MetadataTokens.MethodDefinitionHandle(_methodsSource[0].MetadataToken)) : 0;
107 }
108
109 // initialize cache table
110 if (_methods == null)
111 Interlocked.CompareExchange(ref _methods, new IkvmReflectionMethodBaseSymbol?[_methodsSource.Length], null);
112
113 // index of current record is specified row - base
114 var idx = row - _methodsBaseRow;
115 Debug.Assert(idx >= 0);
116 Debug.Assert(idx < _methodsSource.Length);
117
118 // check that our list is long enough to contain the entire table
119 if (_methods.Length < idx)
120 throw new IndexOutOfRangeException();
121
122 // if not yet created, create, allow multiple instances, but only one is eventually inserted
123 ref var rec = ref _methods[idx];
124 if (rec == null)
125 {
126 switch (method)
127 {
128 case ConstructorInfo c:
129 Interlocked.CompareExchange(ref rec, new IkvmReflectionConstructorSymbol(Context, ContainingModule, this, c), null);
130 break;
131 case MethodInfo m:
132 Interlocked.CompareExchange(ref rec, new IkvmReflectionMethodSymbol(Context, ContainingModule, this, m), null);
133 break;
134 }
135 }
136
137 // this should never happen
138 if (rec is not IkvmReflectionMethodBaseSymbol sym)
139 throw new InvalidOperationException();
140
141 return sym;
142 }
143
150 internal IkvmReflectionFieldSymbol GetOrCreateFieldSymbol(FieldInfo field)
151 {
152 if (field is null)
153 throw new ArgumentNullException(nameof(field));
154
155 Debug.Assert(field.DeclaringType == _underlyingType);
156
157 var hnd = MetadataTokens.FieldDefinitionHandle(field.MetadataToken);
158 var row = MetadataTokens.GetRowNumber(hnd);
159
160 // initialize source table
161 if (_fieldsSource == null)
162 {
163 Interlocked.CompareExchange(ref _fieldsSource, _underlyingType.GetFields(DefaultBindingFlags).OrderBy(i => i.MetadataToken).ToArray(), null);
164 _fieldsBaseRow = _fieldsSource.Length != 0 ? MetadataTokens.GetRowNumber(MetadataTokens.MethodDefinitionHandle(_fieldsSource[0].MetadataToken)) : 0;
165 }
166
167 // initialize cache table
168 if (_fields == null)
169 Interlocked.CompareExchange(ref _fields, new IkvmReflectionFieldSymbol?[_fieldsSource.Length], null);
170
171 // index of current field is specified row - base
172 var idx = row - _fieldsBaseRow;
173 Debug.Assert(idx >= 0);
174 Debug.Assert(idx < _fieldsSource.Length);
175
176 // check that our list is long enough to contain the entire table
177 if (_fields.Length < idx)
178 throw new IndexOutOfRangeException();
179
180 // if not yet created, create, allow multiple instances, but only one is eventually inserted
181 ref var rec = ref _fields[idx];
182 if (rec == null)
183 Interlocked.CompareExchange(ref rec, new IkvmReflectionFieldSymbol(Context, this, field), null);
184
185 // this should never happen
186 if (rec is not IkvmReflectionFieldSymbol sym)
187 throw new InvalidOperationException();
188
189 return sym;
190 }
191
198 internal IkvmReflectionPropertySymbol GetOrCreatePropertySymbol(PropertyInfo property)
199 {
200 if (property is null)
201 throw new ArgumentNullException(nameof(property));
202
203 Debug.Assert(property.DeclaringType == _underlyingType);
204
205 var hnd = MetadataTokens.PropertyDefinitionHandle(property.MetadataToken);
206 var row = MetadataTokens.GetRowNumber(hnd);
207
208 // initialize source table
209 if (_propertiesSource == null)
210 {
211 Interlocked.CompareExchange(ref _propertiesSource, _underlyingType.GetProperties(DefaultBindingFlags).OrderBy(i => i.MetadataToken).ToArray(), null);
212 _propertiesBaseRow = _propertiesSource.Length != 0 ? MetadataTokens.GetRowNumber(MetadataTokens.MethodDefinitionHandle(_propertiesSource[0].MetadataToken)) : 0;
213 }
214
215 // initialize cache table
216 if (_properties == null)
217 Interlocked.CompareExchange(ref _properties, new IkvmReflectionPropertySymbol?[_propertiesSource.Length], null);
218
219 // index of current property is specified row - base
220 var idx = row - _propertiesBaseRow;
221 Debug.Assert(idx >= 0);
222 Debug.Assert(idx < _propertiesSource.Length);
223
224 // check that our list is long enough to contain the entire table
225 if (_properties.Length < idx)
226 throw new IndexOutOfRangeException();
227
228 // if not yet created, create, allow multiple instances, but only one is eventually inserted
229 ref var rec = ref _properties[idx];
230 if (rec == null)
231 Interlocked.CompareExchange(ref rec, new IkvmReflectionPropertySymbol(Context, this, property), null);
232
233 // this should never happen
234 if (rec is not IkvmReflectionPropertySymbol sym)
235 throw new InvalidOperationException();
236
237 return sym;
238 }
239
246 internal IkvmReflectionEventSymbol GetOrCreateEventSymbol(EventInfo @event)
247 {
248 if (@event is null)
249 throw new ArgumentNullException(nameof(@event));
250
251 Debug.Assert(@event.DeclaringType == _underlyingType);
252
253 var hnd = MetadataTokens.PropertyDefinitionHandle(@event.MetadataToken);
254 var row = MetadataTokens.GetRowNumber(hnd);
255
256 // initialize source events
257 if (_eventsSource == null)
258 {
259 Interlocked.CompareExchange(ref _eventsSource, _underlyingType.GetEvents(DefaultBindingFlags).OrderBy(i => i.MetadataToken).ToArray(), null);
260 _eventsBaseRow = _eventsSource.Length != 0 ? MetadataTokens.GetRowNumber(MetadataTokens.EventDefinitionHandle(_eventsSource[0].MetadataToken)) : 0;
261 }
262
263 // initialize cache table
264 if (_events == null)
265 Interlocked.CompareExchange(ref _events, new IkvmReflectionEventSymbol?[_eventsSource.Length], null);
266
267 // index of current event is specified row - base
268 var idx = row - _eventsBaseRow;
269 Debug.Assert(idx >= 0);
270 Debug.Assert(idx < _eventsSource.Length);
271
272 // check that our list is long enough to contain the entire table
273 if (_events.Length < idx)
274 throw new IndexOutOfRangeException();
275
276 // if not yet created, create, allow multiple instances, but only one is eventually inserted
277 ref var rec = ref _events[idx];
278 if (rec == null)
279 Interlocked.CompareExchange(ref rec, new IkvmReflectionEventSymbol(Context, this, @event), null);
280
281 // this should never happen
282 if (rec is not IkvmReflectionEventSymbol sym)
283 throw new InvalidOperationException();
284
285 return sym;
286 }
287
294 internal IkvmReflectionTypeSymbol GetOrCreateGenericParameterSymbol(Type genericTypeParameterType)
295 {
296 if (genericTypeParameterType is null)
297 throw new ArgumentNullException(nameof(genericTypeParameterType));
298
299 Debug.Assert(genericTypeParameterType.DeclaringType == _underlyingType);
300
301 // initialize tables
302 if (_genericParametersSource == null)
303 Interlocked.CompareExchange(ref _genericParametersSource, _underlyingType.GetGenericArguments(), null);
304 if (_genericParameters == null)
305 Interlocked.CompareExchange(ref _genericParameters, new IkvmReflectionTypeSymbol?[_genericParametersSource.Length], null);
306
307 // position of the parameter in the list
308 var idx = genericTypeParameterType.GenericParameterPosition;
309
310 // check that our list is long enough to contain the entire table
311 if (_genericParameters.Length < idx)
312 throw new IndexOutOfRangeException();
313
314 // if not yet created, create, allow multiple instances, but only one is eventually inserted
315 ref var rec = ref _genericParameters[idx];
316 if (rec == null)
317 Interlocked.CompareExchange(ref rec, new IkvmReflectionTypeSymbol(Context, ContainingModule, genericTypeParameterType), null);
318
319 // this should never happen
320 if (rec is not IkvmReflectionTypeSymbol sym)
321 throw new InvalidOperationException();
322
323 return sym;
324 }
325
332 internal IkvmReflectionTypeSymbol GetOrCreateGenericTypeSymbol(Type[] genericTypeArguments)
333 {
334 if (genericTypeArguments is null)
335 throw new ArgumentNullException(nameof(genericTypeArguments));
336
337 if (_underlyingType.IsGenericTypeDefinition == false)
338 throw new InvalidOperationException();
339
340 // initialize the available parameters
341 if (_genericParametersSource == null)
342 Interlocked.CompareExchange(ref _genericParametersSource, _underlyingType.GetGenericArguments(), null);
343 if (_genericParametersSource.Length != genericTypeArguments.Length)
344 throw new InvalidOperationException();
345
346 // initialize generic type map, and lock on it since we're potentially adding items
347 if (_genericTypes == null)
348 Interlocked.CompareExchange(ref _genericTypes, [], null);
349 if (_genericTypesLock == null)
350 Interlocked.CompareExchange(ref _genericTypesLock, new(), null);
351
352 try
353 {
354 _genericTypesLock.EnterUpgradeableReadLock();
355
356 // find existing entry
357 foreach (var i in _genericTypes)
358 if (i.Arguments.SequenceEqual(genericTypeArguments))
359 return i.Symbol;
360
361 try
362 {
363 _genericTypesLock.EnterWriteLock();
364
365 // generate new symbol
366 var sym = new IkvmReflectionTypeSymbol(Context, ContainingModule, _underlyingType.MakeGenericType(genericTypeArguments));
367 _genericTypes.Add((genericTypeArguments, sym));
368 return sym;
369 }
370 finally
371 {
372 _genericTypesLock.ExitWriteLock();
373 }
374 }
375 finally
376 {
377 _genericTypesLock.ExitUpgradeableReadLock();
378 }
379 }
380
386 protected internal override IkvmReflectionTypeSymbol ResolveTypeSymbol(Type type)
387 {
388 if (type == _underlyingType)
389 return this;
390 else
391 return base.ResolveTypeSymbol(type);
392 }
393
399 protected internal override IkvmReflectionConstructorSymbol ResolveConstructorSymbol(ConstructorInfo ctor)
400 {
401 if (ctor.DeclaringType == _underlyingType)
402 return GetOrCreateConstructorSymbol(ctor);
403 else
404 return base.ResolveConstructorSymbol(ctor);
405 }
406
412 protected internal override IkvmReflectionMethodSymbol ResolveMethodSymbol(MethodInfo method)
413 {
414 if (method.DeclaringType == _underlyingType)
415 return GetOrCreateMethodSymbol(method);
416 else
417 return base.ResolveMethodSymbol(method);
418 }
419
425 protected internal override IkvmReflectionFieldSymbol ResolveFieldSymbol(FieldInfo field)
426 {
427 if (field.DeclaringType == _underlyingType)
428 return GetOrCreateFieldSymbol(field);
429 else
430 return base.ResolveFieldSymbol(field);
431 }
432
438 protected internal override IkvmReflectionPropertySymbol ResolvePropertySymbol(PropertyInfo property)
439 {
440 if (property.DeclaringType == _underlyingType)
441 return GetOrCreatePropertySymbol(property);
442 else
443 return base.ResolvePropertySymbol(property);
444 }
445
451 protected internal override IkvmReflectionEventSymbol ResolveEventSymbol(EventInfo @event)
452 {
453 if (@event.DeclaringType == _underlyingType)
454 return GetOrCreateEventSymbol(@event);
455 else
456 return base.ResolveEventSymbol(@event);
457 }
458
462 internal Type UnderlyingType => _underlyingType;
463
464 public IAssemblySymbol Assembly => Context.GetOrCreateAssemblySymbol(_underlyingType.Assembly);
465
466 public string? AssemblyQualifiedName => _underlyingType.AssemblyQualifiedName;
467
468 public global::System.Reflection.TypeAttributes Attributes => (global::System.Reflection.TypeAttributes)(int)_underlyingType.Attributes;
469
470 public ITypeSymbol? BaseType => _underlyingType.BaseType != null ? ResolveTypeSymbol(_underlyingType.BaseType) : null;
471
472 public bool ContainsGenericParameters => _underlyingType.ContainsGenericParameters;
473
474 public IMethodBaseSymbol? DeclaringMethod => _underlyingType.DeclaringMethod is MethodInfo m ? ResolveMethodSymbol(m) : null;
475
476 public string? FullName => _underlyingType.FullName;
477
478 public global::System.Reflection.GenericParameterAttributes GenericParameterAttributes => (global::System.Reflection.GenericParameterAttributes)(int)_underlyingType.GenericParameterAttributes;
479
480 public int GenericParameterPosition => _underlyingType.GenericParameterPosition;
481
482 public ITypeSymbol[] GenericTypeArguments => ResolveTypeSymbols(_underlyingType.GenericTypeArguments);
483
484 public bool HasElementType => _underlyingType.HasElementType;
485
486 public bool IsAbstract => _underlyingType.IsAbstract;
487
488 public bool IsArray => _underlyingType.IsArray;
489
490 public bool IsAutoLayout => _underlyingType.IsAutoLayout;
491
492 public bool IsByRef => _underlyingType.IsByRef;
493
494 public bool IsClass => _underlyingType.IsClass;
495
496 public bool IsConstructedGenericType => _underlyingType.IsConstructedGenericType;
497
498 public bool IsEnum => _underlyingType.IsEnum;
499
500 public bool IsExplicitLayout => _underlyingType.IsExplicitLayout;
501
502 public bool IsGenericParameter => _underlyingType.IsGenericParameter;
503
504 public bool IsGenericType => _underlyingType.IsGenericType;
505
506 public bool IsGenericTypeDefinition => _underlyingType.IsGenericTypeDefinition;
507
508 public bool IsInterface => _underlyingType.IsInterface;
509
510 public bool IsLayoutSequential => _underlyingType.IsLayoutSequential;
511
512 public bool IsNested => _underlyingType.IsNested;
513
514 public bool IsNestedAssembly => _underlyingType.IsNestedAssembly;
515
516 public bool IsNestedFamANDAssem => _underlyingType.IsNestedFamANDAssem;
517
518 public bool IsNestedFamORAssem => _underlyingType.IsNestedFamORAssem;
519
520 public bool IsNestedFamily => _underlyingType.IsNestedFamily;
521
522 public bool IsNestedPrivate => _underlyingType.IsNestedPrivate;
523
524 public bool IsNestedPublic => _underlyingType.IsNestedPublic;
525
526 public bool IsNotPublic => _underlyingType.IsNotPublic;
527
528 public bool IsPointer => _underlyingType.IsPointer;
529
530 public bool IsPrimitive => _underlyingType.IsPrimitive;
531
532 public bool IsPublic => _underlyingType.IsPublic;
533
534 public bool IsSealed => _underlyingType.IsSealed;
535
536#pragma warning disable SYSLIB0050 // Type or member is obsolete
537 public bool IsSerializable => _underlyingType.IsSerializable;
538#pragma warning restore SYSLIB0050 // Type or member is obsolete
539
540 public bool IsValueType => _underlyingType.IsValueType;
541
542 public bool IsVisible => _underlyingType.IsVisible;
543
544 public string? Namespace => _underlyingType.Namespace;
545
546 public IConstructorSymbol? TypeInitializer => _underlyingType.TypeInitializer is ConstructorInfo ctor ? ResolveConstructorSymbol(ctor) : null;
547
548 public int GetArrayRank()
549 {
550 return _underlyingType.GetArrayRank();
551 }
552
553 public IConstructorSymbol? GetConstructor(global::System.Reflection.BindingFlags bindingAttr, ITypeSymbol[] types)
554 {
555 return _underlyingType.GetConstructor((BindingFlags)bindingAttr, binder: null, UnpackTypeSymbols(types), modifiers: null) is ConstructorInfo ctor ? ResolveConstructorSymbol(ctor) : null;
556 }
557
559 {
560 return _underlyingType.GetConstructor(UnpackTypeSymbols(types)) is ConstructorInfo ctor ? ResolveConstructorSymbol(ctor) : null;
561 }
562
564 {
565 return ResolveConstructorSymbols(_underlyingType.GetConstructors());
566 }
567
568 public IConstructorSymbol[] GetConstructors(global::System.Reflection.BindingFlags bindingAttr)
569 {
570 return ResolveConstructorSymbols(_underlyingType.GetConstructors((BindingFlags)bindingAttr));
571 }
572
574 {
575 return ResolveMemberSymbols(_underlyingType.GetDefaultMembers());
576 }
577
579 {
580 return _underlyingType.GetElementType() is Type t ? ResolveTypeSymbol(t) : null;
581 }
582
583 public string? GetEnumName(object value)
584 {
585 return _underlyingType.GetEnumName(value);
586 }
587
588 public string[] GetEnumNames()
589 {
590 return _underlyingType.GetEnumNames();
591 }
592
594 {
595 return ResolveTypeSymbol(_underlyingType.GetEnumUnderlyingType());
596 }
597
598 public IEventSymbol? GetEvent(string name, global::System.Reflection.BindingFlags bindingAttr)
599 {
600 return _underlyingType.GetEvent(name, (BindingFlags)bindingAttr) is { } f ? ResolveEventSymbol(f) : null;
601 }
602
603 public IEventSymbol? GetEvent(string name)
604 {
605 return _underlyingType.GetEvent(name) is { } f ? ResolveEventSymbol(f) : null;
606 }
607
609 {
610 return ResolveEventSymbols(_underlyingType.GetEvents());
611 }
612
613 public IEventSymbol[] GetEvents(global::System.Reflection.BindingFlags bindingAttr)
614 {
615 return ResolveEventSymbols(_underlyingType.GetEvents((BindingFlags)bindingAttr));
616 }
617
618 public IFieldSymbol? GetField(string name)
619 {
620 return _underlyingType.GetField(name) is FieldInfo f ? ResolveFieldSymbol(f) : null;
621 }
622
623 public IFieldSymbol? GetField(string name, global::System.Reflection.BindingFlags bindingAttr)
624 {
625 return _underlyingType.GetField(name, (BindingFlags)bindingAttr) is FieldInfo f ? ResolveFieldSymbol(f) : null;
626 }
627
629 {
630 return ResolveFieldSymbols(_underlyingType.GetFields());
631 }
632
633 public IFieldSymbol[] GetFields(global::System.Reflection.BindingFlags bindingAttr)
634 {
635 return ResolveFieldSymbols(_underlyingType.GetFields((BindingFlags)bindingAttr));
636 }
637
639 {
640 return ResolveTypeSymbols(_underlyingType.GetGenericArguments());
641 }
642
644 {
645 return ResolveTypeSymbols(_underlyingType.GetGenericParameterConstraints());
646 }
647
649 {
650 return ResolveTypeSymbol(_underlyingType.GetGenericTypeDefinition());
651 }
652
653 public ITypeSymbol? GetInterface(string name)
654 {
655 return _underlyingType.GetInterface(name) is { } i ? ResolveTypeSymbol(i) : null;
656 }
657
658 public ITypeSymbol? GetInterface(string name, bool ignoreCase)
659 {
660 return _underlyingType.GetInterface(name, ignoreCase) is { } i ? ResolveTypeSymbol(i) : null;
661 }
662
664 {
665 throw new NotImplementedException();
666 }
667
669 {
670 return ResolveTypeSymbols(_underlyingType.GetInterfaces());
671 }
672
673 public IMemberSymbol[] GetMember(string name)
674 {
675 return ResolveMemberSymbols(_underlyingType.GetMember(name));
676 }
677
678 public IMemberSymbol[] GetMember(string name, global::System.Reflection.BindingFlags bindingAttr)
679 {
680 return ResolveMemberSymbols(_underlyingType.GetMember(name, (BindingFlags)bindingAttr));
681 }
682
683 public IMemberSymbol[] GetMember(string name, global::System.Reflection.MemberTypes type, global::System.Reflection.BindingFlags bindingAttr)
684 {
685 return ResolveMemberSymbols(_underlyingType.GetMember(name, (MemberTypes)type, (BindingFlags)bindingAttr));
686 }
687
688 public IMemberSymbol[] GetMembers(global::System.Reflection.BindingFlags bindingAttr)
689 {
690 return ResolveMemberSymbols(_underlyingType.GetMembers((BindingFlags)bindingAttr));
691 }
692
694 {
695 return ResolveMemberSymbols(_underlyingType.GetMembers());
696 }
697
698 public IMethodSymbol? GetMethod(string name, global::System.Reflection.BindingFlags bindingAttr)
699 {
700 return _underlyingType.GetMethod(name, (BindingFlags)bindingAttr) is { } m ? ResolveMethodSymbol(m) : null;
701 }
702
703 public IMethodSymbol? GetMethod(string name, global::System.Reflection.BindingFlags bindingAttr, ITypeSymbol[] types)
704 {
705 return _underlyingType.GetMethod(name, (BindingFlags)bindingAttr, null, UnpackTypeSymbols(types), null) is { } m ? ResolveMethodSymbol(m) : null;
706 }
707
708 public IMethodSymbol? GetMethod(string name, ITypeSymbol[] types)
709 {
710 return _underlyingType.GetMethod(name, UnpackTypeSymbols(types)) is { } m ? ResolveMethodSymbol(m) : null;
711 }
712
713 public IMethodSymbol? GetMethod(string name)
714 {
715 return _underlyingType.GetMethod(name) is { } m ? ResolveMethodSymbol(m) : null;
716 }
717
718 public IMethodSymbol? GetMethod(string name, ITypeSymbol[] types, global::System.Reflection.ParameterModifier[]? modifiers)
719 {
720 if (modifiers != null)
721 throw new NotImplementedException();
722
723 return _underlyingType.GetMethod(name, UnpackTypeSymbols(types), null) is { } m ? ResolveMethodSymbol(m) : null;
724 }
725
726 public IMethodSymbol[] GetMethods(global::System.Reflection.BindingFlags bindingAttr)
727 {
728 return ResolveMethodSymbols(_underlyingType.GetMethods((BindingFlags)bindingAttr));
729 }
730
732 {
733 return ResolveMethodSymbols(_underlyingType.GetMethods());
734 }
735
736 public ITypeSymbol? GetNestedType(string name)
737 {
738 return _underlyingType.GetNestedType(name) is Type t ? ResolveTypeSymbol(t) : null;
739 }
740
741 public ITypeSymbol? GetNestedType(string name, global::System.Reflection.BindingFlags bindingAttr)
742 {
743 return _underlyingType.GetNestedType(name, (BindingFlags)bindingAttr) is Type t ? ResolveTypeSymbol(t) : null;
744 }
745
747 {
748 return ResolveTypeSymbols(_underlyingType.GetNestedTypes());
749 }
750
751 public ITypeSymbol[] GetNestedTypes(global::System.Reflection.BindingFlags bindingAttr)
752 {
753 return ResolveTypeSymbols(_underlyingType.GetNestedTypes((BindingFlags)bindingAttr));
754 }
755
757 {
758 return ResolvePropertySymbols(_underlyingType.GetProperties());
759 }
760
761 public IPropertySymbol[] GetProperties(global::System.Reflection.BindingFlags bindingAttr)
762 {
763 return ResolvePropertySymbols(_underlyingType.GetProperties((BindingFlags)bindingAttr));
764 }
765
766 public IPropertySymbol? GetProperty(string name, ITypeSymbol? returnType, ITypeSymbol[] types, global::System.Reflection.ParameterModifier[]? modifiers)
767 {
768 if (modifiers != null)
769 throw new NotImplementedException();
770
771 var _returnType = returnType != null ? ((IkvmReflectionTypeSymbol)returnType).UnderlyingType : null;
772 return _underlyingType.GetProperty(name, _returnType, UnpackTypeSymbols(types), null) is { } p ? ResolvePropertySymbol(p) : null;
773 }
774
775 public IPropertySymbol? GetProperty(string name, ITypeSymbol[] types)
776 {
777 return _underlyingType.GetProperty(name, UnpackTypeSymbols(types)) is { } p ? ResolvePropertySymbol(p) : null;
778 }
779
780 public IPropertySymbol? GetProperty(string name, ITypeSymbol? returnType, ITypeSymbol[] types)
781 {
782 var _returnType = returnType != null ? ((IkvmReflectionTypeSymbol)returnType).UnderlyingType : null;
783 return _underlyingType.GetProperty(name, _returnType, UnpackTypeSymbols(types)) is { } p ? ResolvePropertySymbol(p) : null;
784 }
785
786 public IPropertySymbol? GetProperty(string name, global::System.Reflection.BindingFlags bindingAttr)
787 {
788 return _underlyingType.GetProperty(name, (BindingFlags)bindingAttr) is { } p ? ResolvePropertySymbol(p) : null;
789 }
790
791 public IPropertySymbol? GetProperty(string name)
792 {
793 return _underlyingType.GetProperty(name) is { } p ? ResolvePropertySymbol(p) : null;
794 }
795
796 public IPropertySymbol? GetProperty(string name, ITypeSymbol? returnType)
797 {
798 var _returnType = returnType != null ? ((IkvmReflectionTypeSymbol)returnType).UnderlyingType : null;
799
800 return _underlyingType.GetProperty(name, _returnType) is { } p ? ResolvePropertySymbol(p) : null;
801 }
802
804 {
805 return _underlyingType.IsAssignableFrom(c != null ? ((IkvmReflectionTypeSymbol)c).UnderlyingType : null);
806 }
807
808 public bool IsEnumDefined(object value)
809 {
810 return _underlyingType.IsEnumDefined(value);
811 }
812
814 {
815 return _underlyingType.IsSubclassOf(((IkvmReflectionTypeSymbol)c).UnderlyingType);
816 }
817
819 {
820 if (_asSZArray == null)
821 Interlocked.CompareExchange(ref _asSZArray, new IkvmReflectionTypeSymbol(Context, ContainingModule, _underlyingType.MakeArrayType()), null);
822
823 return _asSZArray;
824 }
825
826 public ITypeSymbol MakeArrayType(int rank)
827 {
828 if (rank == 1)
829 return MakeArrayType();
830
831 if (_asArray == null)
832 Interlocked.CompareExchange(ref _asArray, new IkvmReflectionTypeSymbol?[32], null);
833
834 ref var asArray = ref _asArray[rank];
835 if (asArray == null)
836 Interlocked.CompareExchange(ref asArray, new IkvmReflectionTypeSymbol(Context, ContainingModule, _underlyingType.MakeArrayType(rank)), null);
837
838 return asArray;
839 }
840
842 {
843 if (_asByRef == null)
844 Interlocked.CompareExchange(ref _asByRef, new IkvmReflectionTypeSymbol(Context, ContainingModule, _underlyingType.MakeByRefType()), null);
845
846 return _asByRef;
847 }
848
849 public ITypeSymbol MakeGenericType(params ITypeSymbol[] typeArguments)
850 {
851 throw new NotImplementedException();
852 }
853
855 {
856 if (_asPointer == null)
857 Interlocked.CompareExchange(ref _asPointer, new IkvmReflectionTypeSymbol(Context, ContainingModule, _underlyingType.MakePointerType()), null);
858
859 return _asPointer;
860 }
861
862 }
863
864}
System.Threading.Interlocked Interlocked
Implementation of IModuleSymbol derived from System.Reflection.
Holds references to symbols derived from System.Reflection.
IkvmReflectionAssemblySymbol GetOrCreateAssemblySymbol(Assembly assembly)
Gets or creates a IkvmReflectionAssemblySymbol for the specified Assembly.
IkvmReflectionSymbolContext Context
Gets the associated IkvmReflectionSymbolContext.
bool IsEnumDefined(object value)
Returns a value that indicates whether the specified value exists in the current enumeration type.
global::System.Reflection.TypeAttributes Attributes
Gets the attributes associated with the .
ITypeSymbol? BaseType
Gets the type from which the current ITypeSymbol directly inherits.
IMemberSymbol[] GetDefaultMembers()
Searches for the members defined for the current ITypeSymbol whose DefaultMemberAttribute is set.
bool IsVisible
Gets a value indicating whether the ITypeSymbol can be accessed by code outside the assembly.
ITypeSymbol MakeByRefType()
Returns a ITypeSymbol object that represents the current type when passed as a ref parameter (ByRef p...
IConstructorSymbol? GetConstructor(global::System.Reflection.BindingFlags bindingAttr, ITypeSymbol[] types)
IPropertySymbol? GetProperty(string name, global::System.Reflection.BindingFlags bindingAttr)
IEventSymbol[] GetEvents()
Returns all the public events that are declared or inherited by the current ITypeSymbol.
ITypeSymbol MakePointerType()
Returns a ITypeSymbol object that represents a pointer to the current type.
ITypeSymbol GetEnumUnderlyingType()
Returns the underlying type of the current enumeration type.
IConstructorSymbol[] GetConstructors(global::System.Reflection.BindingFlags bindingAttr)
bool IsNotPublic
Gets a value indicating whether the ITypeSymbol is not declared public.
ITypeSymbol GetGenericTypeDefinition()
Returns a ITypeSymbol object that represents a generic type definition from which the current generic...
bool ContainsGenericParameters
Gets a value indicating whether the current ITypeSymbol object has type parameters that have not been...
bool IsPointer
Gets a value indicating whether the ITypeSymbol is a pointer.
int GetArrayRank()
Gets the number of dimensions in an array.
IPropertySymbol? GetProperty(string name, ITypeSymbol? returnType)
Searches for the public property with the specified name and return type.
IMethodSymbol? GetMethod(string name, global::System.Reflection.BindingFlags bindingAttr, ITypeSymbol[] types)
IMethodSymbol? GetMethod(string name, ITypeSymbol[] types)
Searches for the specified public method whose parameters match the specified argument types.
bool IsLayoutSequential
Gets a value indicating whether the fields of the current type are laid out sequentially,...
bool IsNestedFamORAssem
Gets a value indicating whether the ITypeSymbol is nested and visible only to classes that belong to ...
ITypeSymbol? GetInterface(string name)
Searches for the interface with the specified name.
ITypeSymbol? GetElementType()
When overridden in a derived class, returns the ITypeSymbol of the object encompassed or referred to ...
bool IsNestedPrivate
Gets a value indicating whether the ITypeSymbol is nested and declared private.
IPropertySymbol[] GetProperties(global::System.Reflection.BindingFlags bindingAttr)
IEventSymbol[] GetEvents(global::System.Reflection.BindingFlags bindingAttr)
IMethodSymbol[] GetMethods(global::System.Reflection.BindingFlags bindingAttr)
IConstructorSymbol? GetConstructor(ITypeSymbol[] types)
Searches for a public instance constructor whose parameters match the types in the specified array.
IPropertySymbol? GetProperty(string name, ITypeSymbol? returnType, ITypeSymbol[] types)
Searches for the specified public property whose parameters match the specified argument types.
IConstructorSymbol? TypeInitializer
Gets the initializer for the type.
ITypeSymbol? GetNestedType(string name, global::System.Reflection.BindingFlags bindingAttr)
bool IsNestedFamily
Gets a value indicating whether the ITypeSymbol is nested and visible only within its own family.
ITypeSymbol? GetNestedType(string name)
Searches for the public nested type with the specified name.
bool IsValueType
Gets a value indicating whether the ITypeSymbol is a value type.
IFieldSymbol[] GetFields(global::System.Reflection.BindingFlags bindingAttr)
bool IsNestedAssembly
Gets a value indicating whether the ITypeSymbol is nested and visible only within its own assembly.
bool IsAssignableFrom(ITypeSymbol? c)
Determines whether an instance of a specified type c can be assigned to a variable of the current typ...
IMemberSymbol[] GetMember(string name)
Searches for the public members with the specified name.
bool IsAbstract
Gets a value indicating whether the ITypeSymbol is abstract and must be overridden.
IConstructorSymbol[] GetConstructors()
Returns all the public constructors defined for the current ITypeSymbol.
bool IsPublic
Gets a value indicating whether the ITypeSymbol is declared public.
IMemberSymbol[] GetMembers()
Returns all the public members of the current ITypeSymbol.
bool IsByRef
Gets a value indicating whether the ITypeSymbol is passed by reference.
bool IsClass
Gets a value indicating whether the ITypeSymbol is a class or a delegate; that is,...
IEventSymbol? GetEvent(string name)
Returns the EventInfo object representing the specified public event.
InterfaceMapping GetInterfaceMap(ITypeSymbol interfaceType)
Returns an interface mapping for the specified interface type.
IFieldSymbol? GetField(string name)
Searches for the public field with the specified name.
ITypeSymbol MakeArrayType(int rank)
Returns a ITypeSymbol object representing an array of the current type, with the specified number of ...
IMethodSymbol? GetMethod(string name)
Searches for the public method with the specified name.
string? AssemblyQualifiedName
Gets the assembly-qualified name of the type, which includes the name of the assembly from which this...
bool IsNested
Gets a value indicating whether the current ITypeSymbol object represents a type whose definition is ...
IMethodSymbol[] GetMethods()
Returns all the public methods of the current ITypeSymbol.
ITypeSymbol[] GetNestedTypes(global::System.Reflection.BindingFlags bindingAttr)
ITypeSymbol[] GetInterfaces()
When overridden in a derived class, gets all the interfaces implemented or inherited by the current I...
string? GetEnumName(object value)
Returns the name of the constant that has the specified value, for the current enumeration type.
bool IsNestedPublic
Gets a value indicating whether a class is nested and declared public.
bool IsGenericParameter
Gets a value indicating whether the current ITypeSymbol represents a type parameter in the definition...
string[] GetEnumNames()
Returns the names of the members of the current enumeration type.
bool HasElementType
Gets a value indicating whether the current ITypeSymbol encompasses or refers to another type; that i...
IMethodSymbol? GetMethod(string name, global::System.Reflection.BindingFlags bindingAttr)
IFieldSymbol? GetField(string name, global::System.Reflection.BindingFlags bindingAttr)
bool IsEnum
Gets a value indicating whether the current ITypeSymbol represents an enumeration.
IMemberSymbol[] GetMember(string name, global::System.Reflection.MemberTypes type, global::System.Reflection.BindingFlags bindingAttr)
IPropertySymbol[] GetProperties()
Returns all the public properties of the current ITypeSymbol.
IMethodSymbol? GetMethod(string name, ITypeSymbol[] types, global::System.Reflection.ParameterModifier[]? modifiers)
ITypeSymbol? GetInterface(string name, bool ignoreCase)
When overridden in a derived class, searches for the specified interface, specifying whether to do a ...
bool IsAutoLayout
Gets a value indicating whether the fields of the current type are laid out automatically by the comm...
ITypeSymbol[] GetGenericArguments()
Returns an array of ITypeSymbol objects that represent the type arguments of a closed generic type or...
IMemberSymbol[] GetMembers(global::System.Reflection.BindingFlags bindingAttr)
IPropertySymbol? GetProperty(string name)
Searches for the public property with the specified name.
bool IsExplicitLayout
Gets a value indicating whether the fields of the current type are laid out at explicitly specified o...
IEventSymbol? GetEvent(string name, global::System.Reflection.BindingFlags bindingAttr)
bool IsSealed
Gets a value indicating whether the ITypeSymbol is declared sealed.
bool IsSubclassOf(ITypeSymbol c)
Determines whether the current ITypeSymbol derives from the specified ITypeSymbol.
bool IsConstructedGenericType
Gets a value that indicates whether this object represents a constructed generic type....
bool IsGenericType
Gets a value indicating whether the current type is a generic type.
bool IsInterface
Gets a value indicating whether the ITypeSymbol is an interface; that is, not a class or a value type...
ITypeSymbol[] GetNestedTypes()
Returns the public types nested in the current ITypeSymbol.
ITypeSymbol MakeArrayType()
Returns a ITypeSymbol object representing a one-dimensional array of the current type,...
bool IsArray
Gets a value that indicates whether the type is an array.
IkvmReflectionTypeSymbol(IkvmReflectionSymbolContext context, IkvmReflectionModuleSymbol module, Type underlyingType)
Initializes a new instance.
bool IsPrimitive
Gets a value indicating whether the ITypeSymbol is one of the primitive types.
bool IsNestedFamANDAssem
Gets a value indicating whether the ITypeSymbol is nested and visible only to classes that belong to ...
ITypeSymbol[] GetGenericParameterConstraints()
Returns an array of ITypeSymbol objects that represent the constraints on the current generic type pa...
IMemberSymbol[] GetMember(string name, global::System.Reflection.BindingFlags bindingAttr)
IPropertySymbol? GetProperty(string name, ITypeSymbol[] types)
Searches for the specified public property whose parameters match the specified argument types.
string? FullName
Gets the fully qualified name of the type, including its namespace but not its assembly.
ITypeSymbol[] GenericTypeArguments
Gets an array of the generic type arguments for this type.
IPropertySymbol? GetProperty(string name, ITypeSymbol? returnType, ITypeSymbol[] types, global::System.Reflection.ParameterModifier[]? modifiers)
bool IsSerializable
Gets a value indicating whether the ITypeSymbol is binary serializable.
IFieldSymbol[] GetFields()
Returns all the public fields of the current ITypeSymbol.
int GenericParameterPosition
Gets the position of the type parameter in the type parameter list of the generic type or method that...
IMethodBaseSymbol? DeclaringMethod
Gets a IMethodBaseSymbol that represents the declaring method, if the current ITypeSymbol represents ...
ITypeSymbol MakeGenericType(params ITypeSymbol[] typeArguments)
Substitutes the elements of an array of types for the type parameters of the current generic type def...
Represents an assembly, which is a reusable, versionable, and self-describing building block of a com...
Discovers the attributes of a class constructor and provides access to constructor metadata.
Discovers the attributes of an event and provides access to event metadata.
Discovers the attributes of a field and provides access to field metadata.
Obtains information about the attributes of a member and provides access to member metadata.
Provides information about methods and constructors.
Discovers the attributes of a method and provides access to method metadata.
Discovers the attributes of a property and provides access to property metadata.
Represents type declarations: class types, interface types, array types, value types,...
ITypeSymbol? GetNestedType(string name)
Searches for the public nested type with the specified name.
ITypeSymbol? GetElementType()
When overridden in a derived class, returns the ITypeSymbol of the object encompassed or referred to ...
ITypeSymbol? GetInterface(string name)
Searches for the interface with the specified name.