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