forked from dnSpy/dnSpy
-
-
Notifications
You must be signed in to change notification settings - Fork 530
/
Copy pathDmdType.cs
1448 lines (1264 loc) · 57.4 KB
/
DmdType.cs
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
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright (C) 2014-2019 [email protected]
This file is part of dnSpy
dnSpy is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
dnSpy is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with dnSpy. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Runtime.InteropServices;
using dnSpy.Debugger.DotNet.Metadata.Impl;
namespace dnSpy.Debugger.DotNet.Metadata {
/// <summary>
/// A .NET type
/// </summary>
public abstract partial class DmdType : DmdMemberInfo, IEquatable<DmdType?> {
/// <summary>
/// Gets the AppDomain
/// </summary>
public override DmdAppDomain AppDomain => Assembly.AppDomain;
/// <summary>
/// Gets the member type
/// </summary>
public sealed override DmdMemberTypes MemberType => (TypeSignatureKind == DmdTypeSignatureKind.Type || TypeSignatureKind == DmdTypeSignatureKind.GenericInstance) && DeclaringType is not null ? DmdMemberTypes.NestedType : DmdMemberTypes.TypeInfo;
/// <summary>
/// Gets the type signature kind
/// </summary>
public abstract DmdTypeSignatureKind TypeSignatureKind { get; }
/// <summary>
/// Gets the type scope. This property is only valid if it's a TypeDef or TypeRef (i.e., not an array, generic instance, etc)
/// </summary>
public abstract DmdTypeScope TypeScope { get; }
/// <summary>
/// Gets the reflected type. This is the type that owns this member, see also <see cref="DmdMemberInfo.DeclaringType"/>
/// </summary>
public override DmdType? ReflectedType => DeclaringType;
/// <summary>
/// Gets the declaring method or null
/// </summary>
public abstract DmdMethodBase? DeclaringMethod { get; }
/// <summary>
/// Gets the module
/// </summary>
public abstract override DmdModule Module { get; }
/// <summary>
/// Gets the assembly
/// </summary>
public abstract DmdAssembly Assembly { get; }
/// <summary>
/// Gets the full name
/// </summary>
public string? FullName => DmdMemberFormatter.FormatFullName(this);
/// <summary>
/// Gets the namespace or null
/// </summary>
public abstract string? Namespace { get; }
/// <summary>
/// Gets the name
/// </summary>
public sealed override string Name => DmdMemberFormatter.FormatName(this);
/// <summary>
/// Gets the namespace or null. This is the namespace stored in the metadata. <see cref="Namespace"/>
/// is the namespace of the non-declaring type.
/// </summary>
public abstract string? MetadataNamespace { get; }
/// <summary>
/// Gets the name stored in the metadata. It's not escaped like <see cref="DmdMemberInfo.Name"/>
/// </summary>
public abstract string? MetadataName { get; }
/// <summary>
/// Gets the assembly qualified name
/// </summary>
public string? AssemblyQualifiedName => DmdMemberFormatter.FormatAssemblyQualifiedName(this);
/// <summary>
/// Gets the base type or null if none
/// </summary>
public abstract DmdType? BaseType { get; }
/// <summary>
/// Gets the struct layout attribute
/// </summary>
public abstract StructLayoutAttribute? StructLayoutAttribute { get; }
/// <summary>
/// true if it's a nested type
/// </summary>
public bool IsNested => DeclaringType is not null;
/// <summary>
/// Gets the generic parameter attributes
/// </summary>
public abstract DmdGenericParameterAttributes GenericParameterAttributes { get; }
/// <summary>
/// true if this is a public type and all its declaring types are public
/// </summary>
public bool IsVisible => CalculateIsVisible(this);
static bool CalculateIsVisible(DmdType type) {
while (type.GetElementType() is DmdType elementType)
type = elementType;
if (type.IsGenericParameter)
return true;
for (;;) {
var declType = type.DeclaringType;
if (declType is null)
break;
if (!type.IsNestedPublic)
return false;
type = declType;
}
if (!type.IsPublic)
return false;
if (type.IsConstructedGenericType) {
foreach (var genArg in type.GetGenericArguments()) {
if (!genArg.IsVisible)
return false;
}
}
return true;
}
/// <summary>
/// Gets the type attributes
/// </summary>
public abstract DmdTypeAttributes Attributes { get; }
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
public bool IsNotPublic => (Attributes & DmdTypeAttributes.VisibilityMask) == DmdTypeAttributes.NotPublic;
public bool IsPublic => (Attributes & DmdTypeAttributes.VisibilityMask) == DmdTypeAttributes.Public;
public bool IsNestedPublic => (Attributes & DmdTypeAttributes.VisibilityMask) == DmdTypeAttributes.NestedPublic;
public bool IsNestedPrivate => (Attributes & DmdTypeAttributes.VisibilityMask) == DmdTypeAttributes.NestedPrivate;
public bool IsNestedFamily => (Attributes & DmdTypeAttributes.VisibilityMask) == DmdTypeAttributes.NestedFamily;
public bool IsNestedAssembly => (Attributes & DmdTypeAttributes.VisibilityMask) == DmdTypeAttributes.NestedAssembly;
public bool IsNestedFamANDAssem => (Attributes & DmdTypeAttributes.VisibilityMask) == DmdTypeAttributes.NestedFamANDAssem;
public bool IsNestedFamORAssem => (Attributes & DmdTypeAttributes.VisibilityMask) == DmdTypeAttributes.NestedFamORAssem;
public bool IsAutoLayout => (Attributes & DmdTypeAttributes.LayoutMask) == DmdTypeAttributes.AutoLayout;
public bool IsLayoutSequential => (Attributes & DmdTypeAttributes.LayoutMask) == DmdTypeAttributes.SequentialLayout;
public bool IsExplicitLayout => (Attributes & DmdTypeAttributes.LayoutMask) == DmdTypeAttributes.ExplicitLayout;
public bool IsClass => (Attributes & DmdTypeAttributes.ClassSemanticsMask) == DmdTypeAttributes.Class && !IsValueType;
public bool IsInterface => (Attributes & DmdTypeAttributes.ClassSemanticsMask) == DmdTypeAttributes.Interface;
public bool IsValueType => BaseType is DmdType baseType && (baseType == AppDomain.System_ValueType ? this != AppDomain.System_Enum : baseType == AppDomain.System_Enum);
public bool IsAbstract => (Attributes & DmdTypeAttributes.Abstract) != 0;
public bool IsSealed => (Attributes & DmdTypeAttributes.Sealed) != 0;
public bool IsEnum => BaseType == AppDomain.System_Enum;
public bool IsSpecialName => (Attributes & DmdTypeAttributes.SpecialName) != 0;
public bool IsImport => (Attributes & DmdTypeAttributes.Import) != 0;
public bool IsWindowsRuntime => (Attributes & DmdTypeAttributes.WindowsRuntime) != 0;
public bool IsBeforeFieldInit => (Attributes & DmdTypeAttributes.BeforeFieldInit) != 0;
public bool IsForwarder => (Attributes & DmdTypeAttributes.Forwarder) != 0;
public bool IsRTSpecialName => (Attributes & DmdTypeAttributes.RTSpecialName) != 0;
public bool HasSecurity => (Attributes & DmdTypeAttributes.HasSecurity) != 0;
public bool IsAnsiClass => (Attributes & DmdTypeAttributes.StringFormatMask) == DmdTypeAttributes.AnsiClass;
public bool IsUnicodeClass => (Attributes & DmdTypeAttributes.StringFormatMask) == DmdTypeAttributes.UnicodeClass;
public bool IsAutoClass => (Attributes & DmdTypeAttributes.StringFormatMask) == DmdTypeAttributes.AutoClass;
public bool IsCustomFormatClass => (Attributes & DmdTypeAttributes.StringFormatMask) == DmdTypeAttributes.CustomFormatClass;
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
/// <summary>
/// true if this type is <see cref="Nullable{T}"/>
/// </summary>
public bool IsNullable {
get {
switch (TypeSignatureKind) {
case DmdTypeSignatureKind.GenericInstance:
return GetGenericTypeDefinition() == AppDomain.System_Nullable_T;
case DmdTypeSignatureKind.Type:
return this == AppDomain.System_Nullable_T;
default:
return false;
}
}
}
/// <summary>
/// Gets the nullable value type, eg. <see cref="int"/> if it's a nullable <see cref="int"/>
/// </summary>
/// <returns></returns>
public DmdType GetNullableElementType() {
if (!IsNullable)
throw new ArgumentException();
var genArgs = GetGenericArguments();
Debug.Assert(genArgs.Count == 1);
if (genArgs.Count != 1)
throw new ArgumentException();
return genArgs[0];
}
/// <summary>
/// true if it's a serializable type
/// </summary>
public bool IsSerializable {
get {
if ((Attributes & DmdTypeAttributes.Serializable) != 0)
return true;
var systemDelegate = AppDomain.System_Delegate;
var systemEnum = AppDomain.System_Enum;
for (DmdType? type = this; type is not null; type = type.BaseType) {
if (type == systemDelegate || type == systemEnum)
return true;
}
return false;
}
}
/// <summary>
/// Only used by CanCastTo(). true if it or any of the types it depends on (base type, generic args,
/// element type, interfaces) has the TypeIdentifierAttribute or similar attributes that enable type
/// equivalency checks.
/// </summary>
internal abstract bool HasTypeEquivalence { get; }
/// <summary>
/// Resolves a member reference
/// </summary>
/// <param name="throwOnError">true to throw if it doesn't exist, false to return null if it doesn't exist</param>
/// <returns></returns>
public sealed override DmdMemberInfo? ResolveMember(bool throwOnError) => Resolve(throwOnError);
/// <summary>
/// Resolves a type reference and throws if it doesn't exist
/// </summary>
/// <returns></returns>
public DmdType Resolve() => Resolve(throwOnError: true)!;
/// <summary>
/// Resolves a type reference and returns null if it doesn't exist
/// </summary>
/// <returns></returns>
public DmdType? ResolveNoThrow() => Resolve(throwOnError: false);
/// <summary>
/// Resolves a type reference
/// </summary>
/// <param name="throwOnError">true to throw if it doesn't exist, false to return null if it doesn't exist</param>
/// <returns></returns>
public abstract DmdType? Resolve(bool throwOnError);
/// <summary>
/// Makes a pointer type
/// </summary>
/// <returns></returns>
public abstract DmdType MakePointerType();
/// <summary>
/// Makes a by-ref type
/// </summary>
/// <returns></returns>
public abstract DmdType MakeByRefType();
/// <summary>
/// Makes a SZ array type
/// </summary>
/// <returns></returns>
public abstract DmdType MakeArrayType();
/// <summary>
/// Makes a multi-dimensional array type
/// </summary>
/// <param name="rank">Number of dimensions</param>
/// <returns></returns>
public DmdType MakeArrayType(int rank) => MakeArrayType(rank, Array.Empty<int>(), Array.Empty<int>());
/// <summary>
/// Makes a multi-dimensional array type
/// </summary>
/// <param name="rank">Number of dimensions</param>
/// <param name="sizes">Sizes</param>
/// <param name="lowerBounds">Lower bounds</param>
/// <returns></returns>
public abstract DmdType MakeArrayType(int rank, IList<int> sizes, IList<int> lowerBounds);
/// <summary>
/// Makes a generic type
/// </summary>
/// <param name="typeArguments">Generic arguments</param>
/// <returns></returns>
public DmdType MakeGenericType(params DmdType[] typeArguments) => MakeGenericType((IList<DmdType>)typeArguments);
/// <summary>
/// Makes a generic type
/// </summary>
/// <param name="typeArguments">Generic arguments</param>
/// <returns></returns>
public DmdType MakeGenericType(params Type[] typeArguments) => MakeGenericType((IList<Type>)typeArguments);
/// <summary>
/// Makes a generic type
/// </summary>
/// <param name="typeArguments">Generic arguments</param>
/// <returns></returns>
public abstract DmdType MakeGenericType(IList<DmdType> typeArguments);
/// <summary>
/// Makes a generic type
/// </summary>
/// <param name="typeArguments">Generic arguments</param>
/// <returns></returns>
public DmdType MakeGenericType(IList<Type> typeArguments) => MakeGenericType(typeArguments.ToDmdTypeNoNull(AppDomain));
/// <summary>
/// Gets the type code
/// </summary>
/// <param name="type">Type or null</param>
/// <returns></returns>
public static TypeCode GetTypeCode(DmdType? type) {
if (type is null) return TypeCode.Empty;
const TypeCode defaultValue = TypeCode.Object;
if (type.IsEnum)
type = type.GetEnumUnderlyingType();
if (type.MetadataNamespace == "System" && !type.IsNested) {
switch (type.MetadataName) {
case "Boolean": return type == type.AppDomain.System_Boolean ? TypeCode.Boolean : defaultValue;
case "Char": return type == type.AppDomain.System_Char ? TypeCode.Char : defaultValue;
case "SByte": return type == type.AppDomain.System_SByte ? TypeCode.SByte : defaultValue;
case "Byte": return type == type.AppDomain.System_Byte ? TypeCode.Byte : defaultValue;
case "Int16": return type == type.AppDomain.System_Int16 ? TypeCode.Int16 : defaultValue;
case "UInt16": return type == type.AppDomain.System_UInt16 ? TypeCode.UInt16 : defaultValue;
case "Int32": return type == type.AppDomain.System_Int32 ? TypeCode.Int32 : defaultValue;
case "UInt32": return type == type.AppDomain.System_UInt32 ? TypeCode.UInt32 : defaultValue;
case "Int64": return type == type.AppDomain.System_Int64 ? TypeCode.Int64 : defaultValue;
case "UInt64": return type == type.AppDomain.System_UInt64 ? TypeCode.UInt64 : defaultValue;
case "Single": return type == type.AppDomain.System_Single ? TypeCode.Single : defaultValue;
case "Double": return type == type.AppDomain.System_Double ? TypeCode.Double : defaultValue;
case "Decimal": return type == type.AppDomain.System_Decimal ? TypeCode.Decimal : defaultValue;
case "DateTime":return type == type.AppDomain.System_DateTime ? TypeCode.DateTime : defaultValue;
case "String": return type == type.AppDomain.System_String ? TypeCode.String : defaultValue;
case "DBNull":
if (type == type.AppDomain.GetWellKnownType(DmdWellKnownType.System_DBNull, isOptional: true))
return TypeCode.DBNull;
break;
}
}
return defaultValue;
}
/// <summary>
/// Gets all fields
/// </summary>
public abstract IEnumerable<DmdFieldInfo> Fields { get; }
/// <summary>
/// Gets all methods and constructors
/// </summary>
public abstract IEnumerable<DmdMethodBase> Methods { get; }
/// <summary>
/// Gets all properties
/// </summary>
public abstract IEnumerable<DmdPropertyInfo> Properties { get; }
/// <summary>
/// Gets all events
/// </summary>
public abstract IEnumerable<DmdEventInfo> Events { get; }
/// <summary>
/// Gets all declared fields
/// </summary>
public abstract ReadOnlyCollection<DmdFieldInfo> DeclaredFields { get; }
/// <summary>
/// Gets all declared methods and constructors
/// </summary>
public abstract ReadOnlyCollection<DmdMethodBase> DeclaredMethods { get; }
/// <summary>
/// Gets all declared properties
/// </summary>
public abstract ReadOnlyCollection<DmdPropertyInfo> DeclaredProperties { get; }
/// <summary>
/// Gets all declared events
/// </summary>
public abstract ReadOnlyCollection<DmdEventInfo> DeclaredEvents { get; }
/// <summary>
/// Gets all nested types
/// </summary>
public abstract ReadOnlyCollection<DmdType> NestedTypes { get; }
/// <summary>
/// Gets a method or returns null if it doesn't exist
/// </summary>
/// <param name="module">Module</param>
/// <param name="metadataToken">Metadata token</param>
/// <returns></returns>
public DmdMethodBase? GetMethod(DmdModule module, int metadataToken) => GetMethod(module, metadataToken, throwOnError: false);
/// <summary>
/// Gets a method
/// </summary>
/// <param name="module">Module</param>
/// <param name="metadataToken">Metadata token</param>
/// <param name="throwOnError">true to throw if it doesn't exist, false to return null if it doesn't exist</param>
/// <returns></returns>
public abstract DmdMethodBase? GetMethod(DmdModule module, int metadataToken, bool throwOnError);
/// <summary>
/// Gets a field or returns null if it doesn't exist
/// </summary>
/// <param name="module">Module</param>
/// <param name="metadataToken">Metadata token</param>
/// <returns></returns>
public DmdFieldInfo? GetField(DmdModule module, int metadataToken) => GetField(module, metadataToken, throwOnError: false);
/// <summary>
/// Gets a field
/// </summary>
/// <param name="module">Module</param>
/// <param name="metadataToken">Metadata token</param>
/// <param name="throwOnError">true to throw if it doesn't exist, false to return null if it doesn't exist</param>
/// <returns></returns>
public abstract DmdFieldInfo? GetField(DmdModule module, int metadataToken, bool throwOnError);
/// <summary>
/// Gets a property or returns null if it doesn't exist
/// </summary>
/// <param name="module">Module</param>
/// <param name="metadataToken">Metadata token</param>
/// <returns></returns>
public DmdPropertyInfo? GetProperty(DmdModule module, int metadataToken) => GetProperty(module, metadataToken, throwOnError: false);
/// <summary>
/// Gets a property
/// </summary>
/// <param name="module">Module</param>
/// <param name="metadataToken">Metadata token</param>
/// <param name="throwOnError">true to throw if it doesn't exist, false to return null if it doesn't exist</param>
/// <returns></returns>
public abstract DmdPropertyInfo? GetProperty(DmdModule module, int metadataToken, bool throwOnError);
/// <summary>
/// Gets an event or returns null if it doesn't exist
/// </summary>
/// <param name="module">Module</param>
/// <param name="metadataToken">Metadata token</param>
/// <returns></returns>
public DmdEventInfo? GetEvent(DmdModule module, int metadataToken) => GetEvent(module, metadataToken, throwOnError: false);
/// <summary>
/// Gets an event
/// </summary>
/// <param name="module">Module</param>
/// <param name="metadataToken">Metadata token</param>
/// <param name="throwOnError">true to throw if it doesn't exist, false to return null if it doesn't exist</param>
/// <returns></returns>
public abstract DmdEventInfo? GetEvent(DmdModule module, int metadataToken, bool throwOnError);
/// <summary>
/// Gets a method
/// </summary>
/// <param name="name">Method name</param>
/// <param name="methodSignature">Method signature</param>
/// <param name="throwOnError">true to throw if it doesn't exist, false to return null if it doesn't exist</param>
/// <returns></returns>
public DmdMethodBase? GetMethod(string name, DmdMethodSignature methodSignature, bool throwOnError) {
if (methodSignature is null)
throw new ArgumentNullException(nameof(methodSignature));
return GetMethod(name, methodSignature.Flags, methodSignature.GenericParameterCount, methodSignature.ReturnType, methodSignature.GetParameterTypes(), throwOnError);
}
/// <summary>
/// Gets a method
/// </summary>
/// <param name="name">Method name</param>
/// <param name="flags">Method signature flags</param>
/// <param name="genericParameterCount">Generic parameter count</param>
/// <param name="returnType">Return type or null to ignore it</param>
/// <param name="parameterTypes">Parameter types</param>
/// <param name="throwOnError">true to throw if it doesn't exist, false to return null if it doesn't exist</param>
/// <returns></returns>
public abstract DmdMethodBase? GetMethod(string name, DmdSignatureCallingConvention flags, int genericParameterCount, DmdType? returnType, IList<DmdType> parameterTypes, bool throwOnError);
/// <summary>
/// Gets a method
/// </summary>
/// <param name="name">Method name</param>
/// <param name="flags">Method signature flags</param>
/// <param name="genericParameterCount">Generic parameter count</param>
/// <param name="returnType">Return type or null to ignore it</param>
/// <param name="parameterTypes">Parameter types</param>
/// <param name="throwOnError">true to throw if it doesn't exist, false to return null if it doesn't exist</param>
/// <returns></returns>
public DmdMethodBase? GetMethod(string name, DmdSignatureCallingConvention flags, int genericParameterCount, Type? returnType, IList<Type> parameterTypes, bool throwOnError) =>
GetMethod(name, flags, genericParameterCount, DmdTypeUtilities.ToDmdType(returnType, AppDomain), parameterTypes.ToDmdTypeNoNull(AppDomain), throwOnError);
/// <summary>
/// Gets a method
/// </summary>
/// <param name="name">Method name</param>
/// <param name="returnType">Return type or null to ignore it</param>
/// <param name="parameterTypes">Parameter types</param>
/// <param name="throwOnError">true to throw if it doesn't exist, false to return null if it doesn't exist</param>
/// <returns></returns>
public DmdMethodBase? GetMethod(string name, DmdType? returnType, IList<DmdType> parameterTypes, bool throwOnError) =>
GetMethod(name, DmdSignatureCallingConvention.Default, 0, returnType, parameterTypes, throwOnError);
/// <summary>
/// Gets a method
/// </summary>
/// <param name="name">Method name</param>
/// <param name="returnType">Return type or null to ignore it</param>
/// <param name="parameterTypes">Parameter types</param>
/// <param name="throwOnError">true to throw if it doesn't exist, false to return null if it doesn't exist</param>
/// <returns></returns>
public DmdMethodBase? GetMethod(string name, Type? returnType, IList<Type> parameterTypes, bool throwOnError) =>
GetMethod(name, DmdSignatureCallingConvention.Default, 0, DmdTypeUtilities.ToDmdType(returnType, AppDomain), parameterTypes.ToDmdTypeNoNull(AppDomain), throwOnError);
/// <summary>
/// Gets a field
/// </summary>
/// <param name="name">Name</param>
/// <param name="fieldType">Field type</param>
/// <param name="throwOnError">true to throw if it doesn't exist, false to return null if it doesn't exist</param>
/// <returns></returns>
public abstract DmdFieldInfo? GetField(string name, DmdType fieldType, bool throwOnError);
/// <summary>
/// Gets a field
/// </summary>
/// <param name="name">Name</param>
/// <param name="fieldType">Field type</param>
/// <param name="throwOnError">true to throw if it doesn't exist, false to return null if it doesn't exist</param>
/// <returns></returns>
public DmdFieldInfo? GetField(string name, Type fieldType, bool throwOnError) =>
GetField(name, DmdTypeUtilities.ToDmdTypeNoNull(fieldType, AppDomain), throwOnError);
/// <summary>
/// Gets a property
/// </summary>
/// <param name="name">Name</param>
/// <param name="methodSignature">Method signature</param>
/// <param name="throwOnError">true to throw if it doesn't exist, false to return null if it doesn't exist</param>
/// <returns></returns>
public DmdPropertyInfo? GetProperty(string name, DmdMethodSignature methodSignature, bool throwOnError) {
if (methodSignature is null)
throw new ArgumentNullException(nameof(methodSignature));
return GetProperty(name, methodSignature.Flags, methodSignature.GenericParameterCount, methodSignature.ReturnType, methodSignature.GetParameterTypes(), throwOnError);
}
/// <summary>
/// Gets a property
/// </summary>
/// <param name="name">Property name</param>
/// <param name="flags">Property signature flags</param>
/// <param name="genericParameterCount">Generic parameter count</param>
/// <param name="returnType">Return type or null to ignore it</param>
/// <param name="parameterTypes">Parameter types</param>
/// <param name="throwOnError">true to throw if it doesn't exist, false to return null if it doesn't exist</param>
/// <returns></returns>
public abstract DmdPropertyInfo? GetProperty(string name, DmdSignatureCallingConvention flags, int genericParameterCount, DmdType? returnType, IList<DmdType> parameterTypes, bool throwOnError);
/// <summary>
/// Gets a property
/// </summary>
/// <param name="name">Property name</param>
/// <param name="flags">Property signature flags</param>
/// <param name="genericParameterCount">Generic parameter count</param>
/// <param name="returnType">Return type or null to ignore it</param>
/// <param name="parameterTypes">Parameter types</param>
/// <param name="throwOnError">true to throw if it doesn't exist, false to return null if it doesn't exist</param>
/// <returns></returns>
public DmdPropertyInfo? GetProperty(string name, DmdSignatureCallingConvention flags, int genericParameterCount, Type? returnType, IList<Type> parameterTypes, bool throwOnError) =>
GetProperty(name, flags, genericParameterCount, DmdTypeUtilities.ToDmdType(returnType, AppDomain), parameterTypes.ToDmdTypeNoNull(AppDomain), throwOnError);
/// <summary>
/// Gets an event
/// </summary>
/// <param name="name">Name</param>
/// <param name="eventHandlerType">Event handler type</param>
/// <param name="throwOnError">true to throw if it doesn't exist, false to return null if it doesn't exist</param>
/// <returns></returns>
public abstract DmdEventInfo? GetEvent(string name, DmdType eventHandlerType, bool throwOnError);
/// <summary>
/// Gets an event
/// </summary>
/// <param name="name">Name</param>
/// <param name="eventHandlerType">Event handler type</param>
/// <param name="throwOnError">true to throw if it doesn't exist, false to return null if it doesn't exist</param>
/// <returns></returns>
public DmdEventInfo? GetEvent(string name, Type eventHandlerType, bool throwOnError) =>
GetEvent(name, DmdTypeUtilities.ToDmdTypeNoNull(eventHandlerType, AppDomain), throwOnError);
/// <summary>
/// Gets a constructor
/// </summary>
/// <param name="bindingAttr">Binding flags</param>
/// <param name="callConvention">Calling convention</param>
/// <param name="types">Parameter types</param>
/// <returns></returns>
public abstract DmdConstructorInfo? GetConstructor(DmdBindingFlags bindingAttr, DmdCallingConventions callConvention, IList<DmdType> types);
/// <summary>
/// Gets a constructor
/// </summary>
/// <param name="bindingAttr">Binding flags</param>
/// <param name="callConvention">Calling convention</param>
/// <param name="types">Parameter types</param>
/// <returns></returns>
public DmdConstructorInfo? GetConstructor(DmdBindingFlags bindingAttr, DmdCallingConventions callConvention, IList<Type> types) =>
GetConstructor(bindingAttr, callConvention, types.ToDmdTypeNoNull(AppDomain));
/// <summary>
/// Gets a constructor
/// </summary>
/// <param name="bindingAttr">Binding flags</param>
/// <param name="types">Parameter types</param>
/// <returns></returns>
public DmdConstructorInfo? GetConstructor(DmdBindingFlags bindingAttr, IList<DmdType> types) => GetConstructor(bindingAttr, DmdCallingConventions.Any, types);
/// <summary>
/// Gets a constructor
/// </summary>
/// <param name="bindingAttr">Binding flags</param>
/// <param name="types">Parameter types</param>
/// <returns></returns>
public DmdConstructorInfo? GetConstructor(DmdBindingFlags bindingAttr, IList<Type> types) => GetConstructor(bindingAttr, DmdCallingConventions.Any, types.ToDmdTypeNoNull(AppDomain));
/// <summary>
/// Gets a public constructor
/// </summary>
/// <param name="types">Parameter types</param>
/// <returns></returns>
public DmdConstructorInfo? GetConstructor(IList<DmdType> types) => GetConstructor(DmdBindingFlags.Instance | DmdBindingFlags.Public, types);
/// <summary>
/// Gets a public constructor
/// </summary>
/// <param name="types">Parameter types</param>
/// <returns></returns>
public DmdConstructorInfo? GetConstructor(IList<Type> types) => GetConstructor(DmdBindingFlags.Instance | DmdBindingFlags.Public, types.ToDmdTypeNoNull(AppDomain));
/// <summary>
/// Gets all public constructors
/// </summary>
/// <returns></returns>
public DmdConstructorInfo[] GetConstructors() => GetConstructors(DmdBindingFlags.Instance | DmdBindingFlags.Public);
/// <summary>
/// Gets constructors
/// </summary>
/// <param name="bindingAttr">Binding flags</param>
/// <returns></returns>
public abstract DmdConstructorInfo[] GetConstructors(DmdBindingFlags bindingAttr);
/// <summary>
/// Gets the type initializer
/// </summary>
public DmdConstructorInfo? TypeInitializer => GetConstructor(DmdBindingFlags.Static | DmdBindingFlags.Public | DmdBindingFlags.NonPublic, DmdCallingConventions.Any, Array.Empty<DmdType>());
/// <summary>
/// Gets a method
/// </summary>
/// <param name="name">Name</param>
/// <param name="bindingAttr">Binding flags</param>
/// <param name="callConvention">Calling convention</param>
/// <param name="types">Parameter types or null</param>
/// <returns></returns>
public abstract DmdMethodInfo? GetMethod(string name, DmdBindingFlags bindingAttr, DmdCallingConventions callConvention, IList<DmdType>? types);
/// <summary>
/// Gets a method
/// </summary>
/// <param name="name">Name</param>
/// <param name="bindingAttr">Binding flags</param>
/// <param name="callConvention">Calling convention</param>
/// <param name="types">Parameter types or null</param>
/// <returns></returns>
public DmdMethodInfo? GetMethod(string name, DmdBindingFlags bindingAttr, DmdCallingConventions callConvention, IList<Type>? types) =>
GetMethod(name, bindingAttr, callConvention, types.ToDmdType(AppDomain));
/// <summary>
/// Gets a method
/// </summary>
/// <param name="name">Name</param>
/// <param name="bindingAttr">Binding flags</param>
/// <param name="types">Parameter types or null</param>
/// <returns></returns>
public DmdMethodInfo? GetMethod(string name, DmdBindingFlags bindingAttr, IList<DmdType>? types) => GetMethod(name, bindingAttr, DmdCallingConventions.Any, types);
/// <summary>
/// Gets a method
/// </summary>
/// <param name="name">Name</param>
/// <param name="bindingAttr">Binding flags</param>
/// <param name="types">Parameter types or null</param>
/// <returns></returns>
public DmdMethodInfo? GetMethod(string name, DmdBindingFlags bindingAttr, IList<Type>? types) => GetMethod(name, bindingAttr, DmdCallingConventions.Any, types.ToDmdType(AppDomain));
/// <summary>
/// Gets a public static or instance method
/// </summary>
/// <param name="name">Name</param>
/// <param name="types">Parameter types or null</param>
/// <returns></returns>
public DmdMethodInfo? GetMethod(string name, IList<DmdType>? types) => GetMethod(name, DmdBindingFlags.Instance | DmdBindingFlags.Static | DmdBindingFlags.Public, DmdCallingConventions.Any, types);
/// <summary>
/// Gets a public static or instance method
/// </summary>
/// <param name="name">Name</param>
/// <param name="types">Parameter types or null</param>
/// <returns></returns>
public DmdMethodInfo? GetMethod(string name, IList<Type>? types) => GetMethod(name, DmdBindingFlags.Instance | DmdBindingFlags.Static | DmdBindingFlags.Public, DmdCallingConventions.Any, types.ToDmdType(AppDomain));
/// <summary>
/// Gets a method
/// </summary>
/// <param name="name">Name</param>
/// <param name="bindingAttr">Binding flags</param>
/// <returns></returns>
public DmdMethodInfo? GetMethod(string name, DmdBindingFlags bindingAttr) => GetMethod(name, bindingAttr, DmdCallingConventions.Any, (IList<DmdType>?)null);
/// <summary>
/// Gets a public static or instance method
/// </summary>
/// <param name="name">Name</param>
/// <returns></returns>
public DmdMethodInfo? GetMethod(string name) => GetMethod(name, DmdBindingFlags.Instance | DmdBindingFlags.Static | DmdBindingFlags.Public, DmdCallingConventions.Any, (IList<DmdType>?)null);
/// <summary>
/// Gets all public static or instance methods
/// </summary>
/// <returns></returns>
public DmdMethodInfo[] GetMethods() => GetMethods(DmdBindingFlags.Instance | DmdBindingFlags.Static | DmdBindingFlags.Public);
/// <summary>
/// Gets all methods
/// </summary>
/// <param name="bindingAttr">Binding flags</param>
/// <returns></returns>
public abstract DmdMethodInfo[] GetMethods(DmdBindingFlags bindingAttr);
/// <summary>
/// Gets a field
/// </summary>
/// <param name="name">Name</param>
/// <param name="bindingAttr">Binding flags</param>
/// <returns></returns>
public abstract DmdFieldInfo? GetField(string name, DmdBindingFlags bindingAttr);
/// <summary>
/// Gets a field
/// </summary>
/// <param name="name">Name</param>
/// <param name="bindingAttr">Binding flags</param>
/// <param name="allowTypeVarianceOnPrivateFields">Allow the reflected type to not equal the declared type</param>
///
/// <returns></returns>
public abstract DmdFieldInfo? GetField(string name, DmdBindingFlags bindingAttr, bool allowTypeVarianceOnPrivateFields);
/// <summary>
/// Gets a public static or instance field
/// </summary>
/// <param name="name">Name</param>
/// <returns></returns>
public DmdFieldInfo? GetField(string name) => GetField(name, DmdBindingFlags.Instance | DmdBindingFlags.Static | DmdBindingFlags.Public);
/// <summary>
/// Gets all public static or instance fields
/// </summary>
/// <returns></returns>
public DmdFieldInfo[] GetFields() => GetFields(DmdBindingFlags.Instance | DmdBindingFlags.Static | DmdBindingFlags.Public);
/// <summary>
/// Gets all fields
/// </summary>
/// <param name="bindingAttr">Binding flags</param>
/// <returns></returns>
public abstract DmdFieldInfo[] GetFields(DmdBindingFlags bindingAttr);
/// <summary>
/// Gets an interface
/// </summary>
/// <param name="name">Name</param>
/// <returns></returns>
public DmdType? GetInterface(string name) => GetInterface(name, false);
/// <summary>
/// Gets an interface
/// </summary>
/// <param name="name">Name</param>
/// <param name="ignoreCase">true if ignore case</param>
/// <returns></returns>
public abstract DmdType? GetInterface(string name, bool ignoreCase);
/// <summary>
/// Gets all interfaces
/// </summary>
/// <returns></returns>
public abstract ReadOnlyCollection<DmdType> GetInterfaces();
/// <summary>
/// Gets a public static or instance event
/// </summary>
/// <param name="name">Name</param>
/// <returns></returns>
public DmdEventInfo? GetEvent(string name) => GetEvent(name, DmdBindingFlags.Instance | DmdBindingFlags.Static | DmdBindingFlags.Public);
/// <summary>
/// Gets an event
/// </summary>
/// <param name="name">Name</param>
/// <param name="bindingAttr">Binding flags</param>
/// <returns></returns>
public abstract DmdEventInfo? GetEvent(string name, DmdBindingFlags bindingAttr);
/// <summary>
/// Gets all public static or instance events
/// </summary>
/// <returns></returns>
public DmdEventInfo[] GetEvents() => GetEvents(DmdBindingFlags.Instance | DmdBindingFlags.Static | DmdBindingFlags.Public);
/// <summary>
/// Gets all events
/// </summary>
/// <param name="bindingAttr">Binding flags</param>
/// <returns></returns>
public abstract DmdEventInfo[] GetEvents(DmdBindingFlags bindingAttr);
/// <summary>
/// Gets a property
/// </summary>
/// <param name="name">Name</param>
/// <param name="bindingAttr">Binding flags</param>
/// <param name="returnType">Return type or null</param>
/// <param name="types">Parameter types or null</param>
/// <returns></returns>
public abstract DmdPropertyInfo? GetProperty(string name, DmdBindingFlags bindingAttr, DmdType? returnType, IList<DmdType>? types);
/// <summary>
/// Gets a property
/// </summary>
/// <param name="name">Name</param>
/// <param name="bindingAttr">Binding flags</param>
/// <param name="returnType">Return type</param>
/// <param name="types">Parameter types or null</param>
/// <returns></returns>
public DmdPropertyInfo? GetProperty(string name, DmdBindingFlags bindingAttr, Type returnType, IList<Type>? types) =>
GetProperty(name, bindingAttr, DmdTypeUtilities.ToDmdType(returnType, AppDomain), types.ToDmdType(AppDomain));
/// <summary>
/// Gets a property
/// </summary>
/// <param name="name">Name</param>
/// <param name="bindingAttr">Binding flags</param>
/// <returns></returns>
public DmdPropertyInfo? GetProperty(string name, DmdBindingFlags bindingAttr) => GetProperty(name, bindingAttr, null, (IList<DmdType>?)null);
/// <summary>
/// Gets a public static or instance property
/// </summary>
/// <param name="name">Name</param>
/// <param name="returnType">Return type or null</param>
/// <param name="types">Parameter types or null</param>
/// <returns></returns>
public DmdPropertyInfo? GetProperty(string name, DmdType? returnType, IList<DmdType>? types) => GetProperty(name, DmdBindingFlags.Instance | DmdBindingFlags.Static | DmdBindingFlags.Public, returnType, types);
/// <summary>
/// Gets a public static or instance property
/// </summary>
/// <param name="name">Name</param>
/// <param name="returnType">Return type or null</param>
/// <param name="types">Parameter types or null</param>
/// <returns></returns>
public DmdPropertyInfo? GetProperty(string name, Type? returnType, IList<Type>? types) => GetProperty(name, DmdBindingFlags.Instance | DmdBindingFlags.Static | DmdBindingFlags.Public, DmdTypeUtilities.ToDmdType(returnType, AppDomain), types.ToDmdType(AppDomain));
/// <summary>
/// Gets a public static or instance property
/// </summary>
/// <param name="name">Name</param>
/// <param name="types">Parameter types or null</param>
/// <returns></returns>
public DmdPropertyInfo? GetProperty(string name, IList<DmdType>? types) => GetProperty(name, DmdBindingFlags.Instance | DmdBindingFlags.Static | DmdBindingFlags.Public, null, types);
/// <summary>
/// Gets a public static or instance property
/// </summary>
/// <param name="name">Name</param>
/// <param name="types">Parameter types or null</param>
/// <returns></returns>
public DmdPropertyInfo? GetProperty(string name, IList<Type>? types) => GetProperty(name, DmdBindingFlags.Instance | DmdBindingFlags.Static | DmdBindingFlags.Public, null, types.ToDmdType(AppDomain));
/// <summary>
/// Gets a public static or instance property
/// </summary>
/// <param name="name">Name</param>
/// <param name="returnType">Return type or null</param>
/// <returns></returns>
public DmdPropertyInfo? GetProperty(string name, DmdType? returnType) => GetProperty(name, DmdBindingFlags.Instance | DmdBindingFlags.Static | DmdBindingFlags.Public, returnType, null);
/// <summary>
/// Gets a public static or instance property
/// </summary>
/// <param name="name">Name</param>
/// <param name="returnType">Return type or null</param>
/// <returns></returns>
public DmdPropertyInfo? GetProperty(string name, Type? returnType) => GetProperty(name, DmdBindingFlags.Instance | DmdBindingFlags.Static | DmdBindingFlags.Public, DmdTypeUtilities.ToDmdType(returnType, AppDomain), null);
/// <summary>
/// Gets a public static or instance property
/// </summary>
/// <param name="name">Name</param>
/// <returns></returns>
public DmdPropertyInfo? GetProperty(string name) => GetProperty(name, DmdBindingFlags.Instance | DmdBindingFlags.Static | DmdBindingFlags.Public, null, (IList<DmdType>?)null);
/// <summary>
/// Gets all properties
/// </summary>
/// <param name="bindingAttr">Bindig flags</param>
/// <returns></returns>
public abstract DmdPropertyInfo[] GetProperties(DmdBindingFlags bindingAttr);
/// <summary>
/// Gets all public static or instance properties
/// </summary>
/// <returns></returns>
public DmdPropertyInfo[] GetProperties() => GetProperties(DmdBindingFlags.Instance | DmdBindingFlags.Static | DmdBindingFlags.Public);
/// <summary>
/// Gets all public nested types
/// </summary>
/// <returns></returns>
public DmdType[] GetNestedTypes() => GetNestedTypes(DmdBindingFlags.Instance | DmdBindingFlags.Static | DmdBindingFlags.Public);
/// <summary>
/// Gets all nested types
/// </summary>
/// <param name="bindingAttr">Binding flags</param>
/// <returns></returns>
public abstract DmdType[] GetNestedTypes(DmdBindingFlags bindingAttr);
/// <summary>
/// Gets a public nested type
/// </summary>
/// <param name="name">Name</param>
/// <returns></returns>
public DmdType? GetNestedType(string name) => GetNestedType(name, DmdBindingFlags.Instance | DmdBindingFlags.Static | DmdBindingFlags.Public);
/// <summary>
/// Gets a nested type
/// </summary>
/// <param name="name">Name</param>
/// <param name="bindingAttr">Binding flags</param>
/// <returns></returns>
public abstract DmdType? GetNestedType(string name, DmdBindingFlags bindingAttr);
/// <summary>
/// Gets a public static or instance member
/// </summary>
/// <param name="name">Name</param>
/// <returns></returns>
public DmdMemberInfo[] GetMember(string name) => GetMember(name, DmdBindingFlags.Instance | DmdBindingFlags.Static | DmdBindingFlags.Public);
/// <summary>
/// Gets a public static or instance member
/// </summary>
/// <param name="name">Name</param>
/// <param name="bindingAttr">Binding flags</param>
/// <returns></returns>
public DmdMemberInfo[] GetMember(string name, DmdBindingFlags bindingAttr) => GetMember(name, DmdMemberTypes.All, bindingAttr);
/// <summary>
/// Gets members
/// </summary>
/// <param name="name">Name</param>
/// <param name="type">Member type</param>
/// <param name="bindingAttr">Binding flags</param>