25using System.Collections.Generic;
26using System.Runtime.InteropServices;
31 internal abstract class Type :
MemberInfo, IGenericContext, IGenericBinder
34 public static readonly
Type[] EmptyTypes = Array.Empty<
Type>();
35 protected readonly
Type underlyingType;
36 protected TypeFlags typeFlags;
40 protected enum TypeFlags : ushort
43 IsGenericTypeDefinition = 1,
54 PotentialEnumOrValueType = 32,
58 NotGenericTypeDefinition = 128,
61 ContainsMissingType_Unknown = 0,
62 ContainsMissingType_Pending = 256,
63 ContainsMissingType_Yes = 512,
64 ContainsMissingType_No = 256 | 512,
65 ContainsMissingType_Mask = 256 | 512,
68 PotentialBuiltIn = 1024,
77 this.underlyingType =
this;
86 System.Diagnostics.Debug.Assert(underlyingType.underlyingType == underlyingType);
87 this.underlyingType = underlyingType;
88 this.typeFlags = underlyingType.typeFlags;
95 internal Type(
byte sigElementType) :
98 this.sigElementType = sigElementType;
101 public static Binder DefaultBinder
103 get {
return new DefaultBinder(); }
106 public sealed override MemberTypes MemberType
108 get {
return IsNested ? MemberTypes.NestedType : MemberTypes.TypeInfo; }
111 public virtual string AssemblyQualifiedName
114 get {
return this.FullName +
", " + this.
Assembly.FullName; }
117 public abstract Type BaseType
122 public abstract TypeAttributes Attributes
127 public virtual Type GetElementType()
132 internal virtual void CheckBaked()
136 public virtual Type[] __GetDeclaredTypes()
138 return Type.EmptyTypes;
141 public virtual Type[] __GetDeclaredInterfaces()
143 return Type.EmptyTypes;
146 public virtual MethodBase[] __GetDeclaredMethods()
151 public virtual __MethodImplMap __GetMethodImplMap()
153 throw new NotSupportedException();
156 public virtual FieldInfo[] __GetDeclaredFields()
161 public virtual EventInfo[] __GetDeclaredEvents()
171 public virtual CustomModifiers __GetCustomModifiers()
173 return new CustomModifiers();
176 [Obsolete(
"Please use __GetCustomModifiers() instead.")]
177 public Type[] __GetRequiredCustomModifiers()
179 return __GetCustomModifiers().GetRequired();
182 [Obsolete(
"Please use __GetCustomModifiers() instead.")]
183 public Type[] __GetOptionalCustomModifiers()
185 return __GetCustomModifiers().GetOptional();
188 public virtual __StandAloneMethodSig __MethodSignature
190 get {
throw new InvalidOperationException(); }
193 public bool HasElementType
195 get {
return IsArray || IsByRef || IsPointer; }
200 get {
return sigElementType == Signature.ELEMENT_TYPE_ARRAY || sigElementType == Signature.ELEMENT_TYPE_SZARRAY; }
203 public bool IsSZArray
205 get {
return sigElementType == Signature.ELEMENT_TYPE_SZARRAY; }
210 get {
return sigElementType == Signature.ELEMENT_TYPE_BYREF; }
213 public bool IsPointer
215 get {
return sigElementType == Signature.ELEMENT_TYPE_PTR; }
218 public bool IsFunctionPointer
220 get {
return sigElementType == Signature.ELEMENT_TYPE_FNPTR; }
223 public bool IsUnmanagedFunctionPointer
225 get {
throw new NotSupportedException(); }
228 public bool IsValueType
233 return (typeFlags & (TypeFlags.ValueType | TypeFlags.NotValueType))
switch
235 0 or TypeFlags.ValueType | TypeFlags.NotValueType => IsValueTypeImpl,
236 _ => (typeFlags & TypeFlags.ValueType) != 0,
241 protected abstract bool IsValueTypeImpl
246 public bool IsGenericParameter
248 get {
return sigElementType == Signature.ELEMENT_TYPE_VAR || sigElementType == Signature.ELEMENT_TYPE_MVAR; }
251 public bool IsGenericMethodParameter
253 get {
return IsGenericParameter && DeclaringMethod is not
null; }
256 public bool IsGenericTypeParameter
258 get {
return IsGenericParameter && DeclaringMethod is
null; }
261 public virtual int GenericParameterPosition
263 get {
throw new NotSupportedException(); }
271 public Type UnderlyingSystemType
273 get {
return underlyingType; }
276 public override Type DeclaringType
281 internal virtual TypeName TypeName
283 get {
throw new InvalidOperationException(); }
288 get {
return TypeName.Name; }
291 public string __Namespace
293 get {
return TypeName.Namespace; }
296 public abstract override string Name
301 public virtual string Namespace
306 return DeclaringType.Namespace;
312 internal virtual int GetModuleBuilderToken()
314 throw new InvalidOperationException();
317 public static bool operator ==(
Type t1,
Type t2)
322 return (
object)t1 == (object)t2
323 || ((
object)t1 !=
null && (
object)t2 !=
null && (
object)t1.underlyingType == (
object)t2.underlyingType);
326 public static bool operator !=(
Type t1,
Type t2)
331 public bool Equals(
Type type)
336 public override bool Equals(
object obj)
338 return Equals(obj as
Type);
341 public override int GetHashCode()
343 Type type = UnderlyingSystemType;
344 return ReferenceEquals(type,
this) ? base.GetHashCode() : type.GetHashCode();
347 public Type[] GenericTypeArguments
349 get {
return IsConstructedGenericType ? GetGenericArguments() :
Type.EmptyTypes; }
352 public virtual Type[] GetGenericArguments()
354 return Type.EmptyTypes;
357 public virtual CustomModifiers[] __GetGenericArgumentsCustomModifiers()
359 return Array.Empty<CustomModifiers>();
362 [Obsolete(
"Please use __GetGenericArgumentsCustomModifiers() instead")]
363 public Type[][] __GetGenericArgumentsRequiredCustomModifiers()
365 var customModifiers = __GetGenericArgumentsCustomModifiers();
366 var array =
new Type[customModifiers.Length][];
367 for (
int i = 0; i < array.Length; i++)
368 array[i] = customModifiers[i].GetRequired();
373 [Obsolete(
"Please use __GetGenericArgumentsCustomModifiers() instead")]
374 public Type[][] __GetGenericArgumentsOptionalCustomModifiers()
376 var customModifiers = __GetGenericArgumentsCustomModifiers();
377 var array =
new Type[customModifiers.Length][];
378 for (
int i = 0; i < array.Length; i++)
379 array[i] = customModifiers[i].GetOptional();
384 public virtual Type GetGenericTypeDefinition()
386 throw new InvalidOperationException();
389 public StructLayoutAttribute StructLayoutAttribute
393 var layout = (Attributes & TypeAttributes.LayoutMask)
switch
395 TypeAttributes.AutoLayout =>
new StructLayoutAttribute(LayoutKind.Auto),
396 TypeAttributes.SequentialLayout =>
new StructLayoutAttribute(LayoutKind.Sequential),
397 TypeAttributes.ExplicitLayout =>
new StructLayoutAttribute(LayoutKind.Explicit),
398 _ =>
throw new BadImageFormatException(),
401 layout.CharSet = (Attributes & TypeAttributes.StringFormatMask)
switch
403 TypeAttributes.AnsiClass => CharSet.Ansi,
404 TypeAttributes.UnicodeClass => CharSet.Unicode,
405 TypeAttributes.AutoClass => CharSet.Auto,
410 if (!__GetLayout(out layout.Pack, out layout.Size))
417 public virtual bool __GetLayout(out
int packingSize, out
int typeSize)
424 public virtual bool IsGenericType
426 get {
return false; }
429 public virtual bool IsGenericTypeDefinition
431 get {
return false; }
435 public virtual bool IsConstructedGenericType
437 get {
return false; }
440 public virtual bool ContainsGenericParameters
444 if (IsGenericParameter)
447 foreach (var arg
in GetGenericArguments())
448 if (arg.ContainsGenericParameters)
455 public virtual Type[] GetGenericParameterConstraints()
457 throw new InvalidOperationException();
460 public virtual CustomModifiers[] __GetGenericParameterConstraintCustomModifiers()
462 throw new InvalidOperationException();
465 public virtual GenericParameterAttributes GenericParameterAttributes
467 get {
throw new InvalidOperationException(); }
470 public virtual int GetArrayRank()
472 throw new NotSupportedException();
475 public virtual int[] __GetArraySizes()
477 throw new NotSupportedException();
480 public virtual int[] __GetArrayLowerBounds()
482 throw new NotSupportedException();
486 public virtual Type GetEnumUnderlyingType()
489 throw new ArgumentException();
492 return GetEnumUnderlyingTypeImpl();
495 internal Type GetEnumUnderlyingTypeImpl()
497 foreach (var field
in __GetDeclaredFields())
499 return field.FieldType;
501 throw new InvalidOperationException();
504 public string[] GetEnumNames()
507 throw new ArgumentException();
509 var names =
new List<string>();
510 foreach (var field
in __GetDeclaredFields())
512 names.Add(field.Name);
514 return names.ToArray();
517 public string GetEnumName(
object value)
520 throw new ArgumentException();
522 throw new ArgumentNullException();
526 value = Convert.ChangeType(value, __GetSystemType(GetTypeCode(GetEnumUnderlyingType())));
528 catch (FormatException)
530 throw new ArgumentException();
532 catch (OverflowException)
536 catch (InvalidCastException)
541 foreach (var field
in __GetDeclaredFields())
542 if (field.IsLiteral && field.GetRawConstantValue().Equals(value))
548 public bool IsEnumDefined(
object value)
551 return Array.IndexOf(GetEnumNames(), value) != -1;
553 throw new ArgumentException();
555 throw new ArgumentNullException();
556 if (value.GetType() != __GetSystemType(GetTypeCode(GetEnumUnderlyingType())))
557 throw new ArgumentException();
559 foreach (var field
in __GetDeclaredFields())
560 if (field.IsLiteral && field.GetRawConstantValue().Equals(value))
566 public Array GetEnumValues()
569 throw new ArgumentException();
571 var l = __GetDeclaredFields();
572 var a =
new object[l.Length];
574 for (
int i = 0; i < l.Length; i++)
581 public override string ToString()
586 public abstract string FullName
591 protected string GetFullName()
593 var ns = TypeNameParser.Escape(__Namespace);
594 var decl = DeclaringType;
600 return ns +
"." +
Name;
605 return decl.FullName +
"+" +
Name;
607 return decl.FullName +
"+" + ns +
"." +
Name;
611 internal virtual bool IsModulePseudoType
613 get {
return false; }
616 internal virtual Type GetGenericTypeArgument(
int index)
618 throw new InvalidOperationException();
623 var defaultMemberAttribute =
Module.Universe.Import(typeof(
System.Reflection.DefaultMemberAttribute));
624 foreach (var cad
in CustomAttributeData.GetCustomAttributes(
this))
625 if (cad.Constructor.DeclaringType.Equals(defaultMemberAttribute))
626 return GetMember((
string)cad.ConstructorArguments[0].Value);
633 return GetMember(name, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);
636 public MemberInfo[] GetMember(
string name, BindingFlags bindingAttr)
638 return GetMember(name, MemberTypes.All, bindingAttr);
643 return GetMembers(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);
646 public MemberInfo[] GetMembers(BindingFlags bindingAttr)
648 var members =
new List<MemberInfo>();
649 members.AddRange(GetConstructors(bindingAttr));
650 members.AddRange(GetMethods(bindingAttr));
651 members.AddRange(GetFields(bindingAttr));
652 members.AddRange(GetProperties(bindingAttr));
653 members.AddRange(GetEvents(bindingAttr));
654 members.AddRange(GetNestedTypes(bindingAttr));
655 return members.ToArray();
658 public MemberInfo[] GetMember(
string name, MemberTypes type, BindingFlags bindingAttr)
661 if ((bindingAttr & BindingFlags.IgnoreCase) != 0)
663 name = name.ToLowerInvariant();
664 filter = delegate (
MemberInfo member,
object filterCriteria) {
return member.Name.ToLowerInvariant().Equals(filterCriteria); };
668 filter = delegate (
MemberInfo member,
object filterCriteria) {
return member.Name.Equals(filterCriteria); };
671 return FindMembers(type, bindingAttr, filter, name);
674 static void AddMembers(List<MemberInfo> list, MemberFilter filter,
object filterCriteria,
MemberInfo[] members)
676 foreach (var member
in members)
677 if (filter ==
null || filter(member, filterCriteria))
681 public MemberInfo[] FindMembers(MemberTypes memberType, BindingFlags bindingAttr, MemberFilter filter,
object filterCriteria)
683 var members =
new List<MemberInfo>();
684 if ((memberType & MemberTypes.Constructor) != 0)
685 AddMembers(members, filter, filterCriteria, GetConstructors(bindingAttr));
686 if ((memberType & MemberTypes.Method) != 0)
687 AddMembers(members, filter, filterCriteria, GetMethods(bindingAttr));
688 if ((memberType & MemberTypes.Field) != 0)
689 AddMembers(members, filter, filterCriteria, GetFields(bindingAttr));
690 if ((memberType & MemberTypes.Property) != 0)
691 AddMembers(members, filter, filterCriteria, GetProperties(bindingAttr));
692 if ((memberType & MemberTypes.Event) != 0)
693 AddMembers(members, filter, filterCriteria, GetEvents(bindingAttr));
694 if ((memberType & MemberTypes.NestedType) != 0)
695 AddMembers(members, filter, filterCriteria, GetNestedTypes(bindingAttr));
697 return members.ToArray();
703 return __GetDeclaredMethods();
705 return __GetDeclaredFields();
707 return __GetDeclaredProperties();
709 return __GetDeclaredEvents();
710 else if (typeof(T) == typeof(
Type))
711 return __GetDeclaredTypes();
713 throw new InvalidOperationException();
716 T[] GetMembers<T>(BindingFlags flags)
721 var list =
new List<T>();
722 foreach (var member
in GetMembers<T>())
723 if (member is T m && m.BindingFlagsMatch(flags))
726 if ((flags & BindingFlags.DeclaredOnly) == 0)
728 for (var type = BaseType; type !=
null; type = type.BaseType)
732 foreach (var member
in type.GetMembers<T>())
733 if (member is T m && m.BindingFlagsMatchInherited(flags))
734 list.Add((T)m.SetReflectedType(
this));
738 return list.ToArray();
741 T GetMemberByName<T>(
string name, BindingFlags flags, Predicate<T> filter)
746 if ((flags & BindingFlags.IgnoreCase) != 0)
747 name = name.ToLowerInvariant();
751 foreach (var member
in GetMembers<T>())
753 if (member is T m && m.BindingFlagsMatch(flags))
755 var memberName = m.Name;
756 if ((flags & BindingFlags.IgnoreCase) != 0)
757 memberName = memberName.ToLowerInvariant();
759 if (memberName == name && (filter ==
null || filter(m)))
762 throw new AmbiguousMatchException();
769 if ((flags & BindingFlags.DeclaredOnly) == 0)
771 for (var type = BaseType; (found ==
null || typeof(T) == typeof(
MethodInfo)) && type !=
null; type = type.BaseType)
775 foreach (var member
in type.GetMembers<T>())
777 if (member is T m && m.BindingFlagsMatchInherited(flags))
779 var memberName = m.Name;
781 if ((flags & BindingFlags.IgnoreCase) != 0)
782 memberName = memberName.ToLowerInvariant();
784 if (memberName == name && (filter ==
null || filter(m)))
789 if (found is
MethodInfo mi && mi.MethodSignature.MatchParameterTypes(((
MethodBase)member).MethodSignature))
792 throw new AmbiguousMatchException();
795 found = (T)member.SetReflectedType(
this);
805 T GetMemberByName<T>(
string name, BindingFlags flags)
808 return GetMemberByName<T>(name, flags,
null);
813 return GetEvent(name, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);
816 public EventInfo GetEvent(
string name, BindingFlags bindingAttr)
818 return GetMemberByName<EventInfo>(name, bindingAttr);
823 return GetEvents(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);
826 public EventInfo[] GetEvents(BindingFlags bindingAttr)
828 return GetMembers<EventInfo>(bindingAttr);
833 return GetField(name, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);
836 public FieldInfo GetField(
string name, BindingFlags bindingAttr)
838 return GetMemberByName<FieldInfo>(name, bindingAttr);
843 return GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance);
846 public FieldInfo[] GetFields(BindingFlags bindingAttr)
848 return GetMembers<FieldInfo>(bindingAttr);
851 public Type[] GetInterfaces()
853 var list =
new List<Type>();
854 for (var type =
this; type !=
null; type = type.BaseType)
855 AddInterfaces(list, type);
857 return list.ToArray();
860 private static void AddInterfaces(List<Type> list,
Type type)
862 foreach (
Type iface
in type.__GetDeclaredInterfaces())
864 if (!list.Contains(iface))
867 AddInterfaces(list, iface);
872 public MethodInfo[] GetMethods(BindingFlags bindingAttr)
876 var list =
new List<MethodInfo>();
878 foreach (var mb
in __GetDeclaredMethods())
881 if (mi !=
null && mi.BindingFlagsMatch(bindingAttr))
885 if ((bindingAttr & BindingFlags.DeclaredOnly) == 0)
887 var baseMethods =
new List<MethodInfo>();
888 foreach (var mi
in list)
890 baseMethods.Add(mi.GetBaseDefinition());
892 for (var type = BaseType; type !=
null; type = type.BaseType)
896 foreach (var mb
in type.__GetDeclaredMethods())
899 if (mi !=
null && mi.BindingFlagsMatchInherited(bindingAttr))
903 if (baseMethods ==
null)
904 baseMethods =
new List<MethodInfo>();
905 else if (baseMethods.Contains(mi.GetBaseDefinition()))
908 baseMethods.Add(mi.GetBaseDefinition());
911 list.Add((
MethodInfo)mi.SetReflectedType(
this));
917 return list.ToArray();
922 return GetMethods(BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance);
927 return GetMethod(name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public);
930 public MethodInfo GetMethod(
string name, BindingFlags bindingAttr)
932 return GetMemberByName<MethodInfo>(name, bindingAttr);
937 return GetMethod(name, types,
null);
940 public MethodInfo GetMethod(
string name,
Type[] types, ParameterModifier[] modifiers)
942 return GetMethod(name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public,
null, types, modifiers);
945 public MethodInfo GetMethod(
string name, BindingFlags bindingAttr, Binder binder,
Type[] types, ParameterModifier[] modifiers)
948 return GetMemberByName(name, bindingAttr, (
MethodInfo m) => m.MethodSignature.MatchParameterTypes(types)) ?? GetMethodWithBinder<MethodInfo>(name, bindingAttr, binder ?? DefaultBinder, types, modifiers);
951 private T GetMethodWithBinder<T>(
string name, BindingFlags bindingAttr, Binder binder,
Type[] types, ParameterModifier[] modifiers)
954 var list =
new List<MethodBase>();
956 GetMemberByName(name, bindingAttr, delegate (T method)
962 return (T)binder.SelectMethod(bindingAttr, list.ToArray(), types, modifiers);
965 public MethodInfo GetMethod(
string name, BindingFlags bindingAttr, Binder binder, CallingConventions callConvention,
Type[] types, ParameterModifier[] modifiers)
968 return GetMethod(name, bindingAttr, binder, types, modifiers);
973 return GetConstructors(BindingFlags.Public | BindingFlags.Instance);
978 return GetMembers<ConstructorInfo>(bindingAttr | BindingFlags.DeclaredOnly);
983 return GetConstructor(BindingFlags.Public | BindingFlags.Instance,
null, CallingConventions.Standard, types,
null);
986 public ConstructorInfo GetConstructor(BindingFlags bindingAttr, Binder binder,
Type[] types, ParameterModifier[] modifiers)
989 if ((bindingAttr & BindingFlags.Instance) != 0)
990 ci1 = GetConstructorImpl(
ConstructorInfo.ConstructorName, bindingAttr, binder, types, modifiers);
992 if ((bindingAttr & BindingFlags.Static) != 0)
994 var ci2 = GetConstructorImpl(
ConstructorInfo.TypeConstructorName, bindingAttr, binder, types, modifiers);
998 throw new AmbiguousMatchException();
1007 private ConstructorInfo GetConstructorImpl(
string name, BindingFlags bindingAttr, Binder binder,
Type[] types, ParameterModifier[] modifiers)
1010 return GetMemberByName<ConstructorInfo>(name, bindingAttr | BindingFlags.DeclaredOnly,
1011 delegate (
ConstructorInfo ctor) {
return ctor.MethodSignature.MatchParameterTypes(types); })
1012 ?? GetMethodWithBinder<ConstructorInfo>(name, bindingAttr, binder ?? DefaultBinder, types, modifiers);
1015 public ConstructorInfo GetConstructor(BindingFlags bindingAttr, Binder binder, CallingConventions callingConvention,
Type[] types, ParameterModifier[] modifiers)
1018 return GetConstructor(bindingAttr, binder, types, modifiers);
1021 internal Type ResolveNestedType(
Module requester, TypeName typeName)
1023 return FindNestedType(typeName) ??
Module.Universe.GetMissingTypeOrThrow(requester,
Module,
this, typeName);
1027 internal virtual Type FindNestedType(TypeName name)
1029 foreach (var type
in __GetDeclaredTypes())
1030 if (type.TypeName == name)
1036 internal virtual Type FindNestedTypeIgnoreCase(TypeName lowerCaseName)
1038 foreach (var type
in __GetDeclaredTypes())
1039 if (type.TypeName.ToLowerInvariant() == lowerCaseName)
1045 public Type GetNestedType(
string name)
1047 return GetNestedType(name, BindingFlags.Public);
1050 public Type GetNestedType(
string name, BindingFlags bindingAttr)
1053 return GetMemberByName<Type>(name, bindingAttr | BindingFlags.DeclaredOnly);
1056 public Type[] GetNestedTypes()
1058 return GetNestedTypes(BindingFlags.Public);
1061 public Type[] GetNestedTypes(BindingFlags bindingAttr)
1064 return GetMembers<Type>(bindingAttr | BindingFlags.DeclaredOnly);
1069 return GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);
1072 public PropertyInfo[] GetProperties(BindingFlags bindingAttr)
1074 return GetMembers<PropertyInfo>(bindingAttr);
1079 return GetProperty(name, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);
1082 public PropertyInfo GetProperty(
string name, BindingFlags bindingAttr)
1084 return GetMemberByName<PropertyInfo>(name, bindingAttr);
1089 const BindingFlags flags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static;
1091 return GetMemberByName<PropertyInfo>(name, flags, delegate (
PropertyInfo prop) {
return prop.PropertyType.Equals(returnType); })
1092 ?? GetPropertyWithBinder(name, flags, DefaultBinder, returnType,
null,
null);
1097 const BindingFlags flags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static;
1099 return GetMemberByName<PropertyInfo>(name, flags, delegate (
PropertyInfo prop) {
return prop.PropertySignature.MatchParameterTypes(types); })
1100 ?? GetPropertyWithBinder(name, flags, DefaultBinder,
null, types,
null);
1105 return GetProperty(name, returnType, types,
null);
1108 public PropertyInfo GetProperty(
string name,
Type returnType,
Type[] types, ParameterModifier[] modifiers)
1110 return GetProperty(name, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static,
null, returnType, types, modifiers);
1113 public PropertyInfo GetProperty(
string name, BindingFlags bindingAttr, Binder binder,
Type returnType,
Type[] types, ParameterModifier[] modifiers)
1115 return GetMemberByName<PropertyInfo>(name, bindingAttr,
1118 return prop.PropertyType.Equals(returnType) && prop.PropertySignature.MatchParameterTypes(types);
1120 ?? GetPropertyWithBinder(name, bindingAttr, binder ?? DefaultBinder, returnType, types, modifiers);
1123 private PropertyInfo GetPropertyWithBinder(
string name, BindingFlags bindingAttr, Binder binder,
Type returnType,
Type[] types, ParameterModifier[] modifiers)
1125 List<PropertyInfo> list =
new List<PropertyInfo>();
1126 GetMemberByName<PropertyInfo>(name, bindingAttr, delegate (
PropertyInfo property)
1131 return binder.SelectProperty(bindingAttr, list.ToArray(), returnType, types, modifiers);
1134 public Type GetInterface(
string name)
1136 return GetInterface(name,
false);
1139 public Type GetInterface(
string name,
bool ignoreCase)
1142 name = name.ToLowerInvariant();
1146 foreach (var type
in GetInterfaces())
1148 var typeName = type.FullName;
1150 typeName = typeName.ToLowerInvariant();
1152 if (typeName == name)
1155 throw new AmbiguousMatchException();
1164 public Type[] FindInterfaces(TypeFilter filter,
object filterCriteria)
1166 var list =
new List<Type>();
1167 foreach (var type
in GetInterfaces())
1168 if (filter(type, filterCriteria))
1171 return list.ToArray();
1176 get {
return GetConstructor(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic,
null,
Type.EmptyTypes,
null); }
1179 public bool IsPrimitive
1184 && ((sigElementType >= Signature.ELEMENT_TYPE_BOOLEAN && sigElementType <= Signature.ELEMENT_TYPE_R8)
1185 || sigElementType == Signature.ELEMENT_TYPE_I
1186 || sigElementType == Signature.ELEMENT_TYPE_U);
1190 public bool __IsBuiltIn
1194 return (typeFlags & (TypeFlags.BuiltIn | TypeFlags.PotentialBuiltIn)) != 0
1195 && ((typeFlags & TypeFlags.BuiltIn) != 0 || ResolvePotentialBuiltInType());
1199 internal byte SigElementType
1204 System.Diagnostics.Debug.Assert((typeFlags & TypeFlags.BuiltIn) != 0 || HasElementType || IsFunctionPointer || IsGenericParameter);
1205 return sigElementType;
1209 bool ResolvePotentialBuiltInType()
1212 typeFlags &= ~TypeFlags.PotentialBuiltIn;
1214 return __Name
switch
1216 "Boolean" => ResolvePotentialBuiltInType(Universe.System_Boolean, Signature.ELEMENT_TYPE_BOOLEAN),
1217 "Char" => ResolvePotentialBuiltInType(Universe.System_Char, Signature.ELEMENT_TYPE_CHAR),
1218 "Object" => ResolvePotentialBuiltInType(Universe.System_Object, Signature.ELEMENT_TYPE_OBJECT),
1219 "String" => ResolvePotentialBuiltInType(Universe.System_String, Signature.ELEMENT_TYPE_STRING),
1220 "Single" => ResolvePotentialBuiltInType(Universe.System_Single, Signature.ELEMENT_TYPE_R4),
1221 "Double" => ResolvePotentialBuiltInType(Universe.System_Double, Signature.ELEMENT_TYPE_R8),
1222 "SByte" => ResolvePotentialBuiltInType(Universe.System_SByte, Signature.ELEMENT_TYPE_I1),
1223 "Int16" => ResolvePotentialBuiltInType(Universe.System_Int16, Signature.ELEMENT_TYPE_I2),
1224 "Int32" => ResolvePotentialBuiltInType(Universe.System_Int32, Signature.ELEMENT_TYPE_I4),
1225 "Int64" => ResolvePotentialBuiltInType(Universe.System_Int64, Signature.ELEMENT_TYPE_I8),
1226 "IntPtr" => ResolvePotentialBuiltInType(Universe.System_IntPtr, Signature.ELEMENT_TYPE_I),
1227 "UIntPtr" => ResolvePotentialBuiltInType(Universe.System_UIntPtr, Signature.ELEMENT_TYPE_U),
1228 "TypedReference" => ResolvePotentialBuiltInType(Universe.System_TypedReference, Signature.ELEMENT_TYPE_TYPEDBYREF),
1229 "Byte" => ResolvePotentialBuiltInType(Universe.System_Byte, Signature.ELEMENT_TYPE_U1),
1230 "UInt16" => ResolvePotentialBuiltInType(Universe.System_UInt16, Signature.ELEMENT_TYPE_U2),
1231 "UInt32" => ResolvePotentialBuiltInType(Universe.System_UInt32, Signature.ELEMENT_TYPE_U4),
1232 "UInt64" => ResolvePotentialBuiltInType(Universe.System_UInt64, Signature.ELEMENT_TYPE_U8),
1234 "Void" => ResolvePotentialBuiltInType(Universe.System_Void, Signature.ELEMENT_TYPE_VOID),
1235 _ =>
throw new InvalidOperationException(),
1239 bool ResolvePotentialBuiltInType(
Type builtIn,
byte elementType)
1241 if (
this == builtIn)
1243 typeFlags |= TypeFlags.BuiltIn;
1244 this.sigElementType = elementType;
1255 var baseType = BaseType;
1256 return baseType !=
null
1257 && baseType.IsEnumOrValueType
1258 && baseType.__Name[0] ==
'E';
1262 public bool IsSealed
1264 get {
return (Attributes & TypeAttributes.Sealed) != 0; }
1267 public bool IsAbstract
1269 get {
return (Attributes & TypeAttributes.Abstract) != 0; }
1272 private bool CheckVisibility(TypeAttributes access)
1274 return (Attributes & TypeAttributes.VisibilityMask) == access;
1277 public bool IsPublic
1279 get {
return CheckVisibility(TypeAttributes.Public); }
1282 public bool IsNestedPublic
1284 get {
return CheckVisibility(TypeAttributes.NestedPublic); }
1287 public bool IsNestedPrivate
1289 get {
return CheckVisibility(TypeAttributes.NestedPrivate); }
1292 public bool IsNestedFamily
1294 get {
return CheckVisibility(TypeAttributes.NestedFamily); }
1297 public bool IsNestedAssembly
1299 get {
return CheckVisibility(TypeAttributes.NestedAssembly); }
1302 public bool IsNestedFamANDAssem
1304 get {
return CheckVisibility(TypeAttributes.NestedFamANDAssem); }
1307 public bool IsNestedFamORAssem
1309 get {
return CheckVisibility(TypeAttributes.NestedFamORAssem); }
1312 public bool IsNotPublic
1314 get {
return CheckVisibility(TypeAttributes.NotPublic); }
1317 public bool IsImport
1319 get {
return (Attributes & TypeAttributes.Import) != 0; }
1322 public bool IsCOMObject
1324 get {
return IsClass && IsImport; }
1327 public bool IsContextful
1329 get {
return IsSubclassOf(this.
Module.Universe.System_ContextBoundObject); }
1332 public bool IsMarshalByRef
1334 get {
return IsSubclassOf(this.
Module.Universe.System_MarshalByRefObject); }
1337 public virtual bool IsVisible
1339 get {
return IsPublic || (IsNestedPublic && this.DeclaringType.IsVisible); }
1342 public bool IsAnsiClass
1344 get {
return (Attributes & TypeAttributes.StringFormatMask) == TypeAttributes.AnsiClass; }
1347 public bool IsUnicodeClass
1349 get {
return (Attributes & TypeAttributes.StringFormatMask) == TypeAttributes.UnicodeClass; }
1352 public bool IsAutoClass
1354 get {
return (Attributes & TypeAttributes.StringFormatMask) == TypeAttributes.AutoClass; }
1357 public bool IsAutoLayout
1359 get {
return (Attributes & TypeAttributes.LayoutMask) == TypeAttributes.AutoLayout; }
1362 public bool IsLayoutSequential
1364 get {
return (Attributes & TypeAttributes.LayoutMask) == TypeAttributes.SequentialLayout; }
1367 public bool IsExplicitLayout
1369 get {
return (Attributes & TypeAttributes.LayoutMask) == TypeAttributes.ExplicitLayout; }
1372 public bool IsSpecialName
1374 get {
return (Attributes & TypeAttributes.SpecialName) != 0; }
1377 public bool IsSerializable
1379 get {
return (Attributes & TypeAttributes.Serializable) != 0; }
1384 get {
return !IsInterface && !IsValueType; }
1387 public bool IsInterface
1389 get {
return (Attributes & TypeAttributes.Interface) != 0; }
1392 public bool IsNested
1396 get {
return this.DeclaringType !=
null; }
1399 public bool __ContainsMissingType
1403 if ((typeFlags & TypeFlags.ContainsMissingType_Mask) == TypeFlags.ContainsMissingType_Unknown)
1407 typeFlags |= TypeFlags.ContainsMissingType_Pending;
1408 typeFlags = (typeFlags & ~TypeFlags.ContainsMissingType_Mask) | (ContainsMissingTypeImpl ? TypeFlags.ContainsMissingType_Yes : TypeFlags.ContainsMissingType_No);
1411 return (typeFlags & TypeFlags.ContainsMissingType_Mask) == TypeFlags.ContainsMissingType_Yes;
1415 internal static bool ContainsMissingType(
Type[] types)
1420 foreach (var type
in types)
1421 if (type.__ContainsMissingType)
1427 protected virtual bool ContainsMissingTypeImpl
1432 || ContainsMissingType(GetGenericArguments())
1433 || __GetCustomModifiers().ContainsMissingType;
1437 public Type MakeArrayType()
1439 return ArrayType.Make(
this,
new CustomModifiers());
1442 public Type __MakeArrayType(CustomModifiers customModifiers)
1444 return ArrayType.Make(
this, customModifiers);
1447 [Obsolete(
"Please use __MakeArrayType(CustomModifiers) instead.")]
1448 public Type __MakeArrayType(
Type[] requiredCustomModifiers,
Type[] optionalCustomModifiers)
1450 return __MakeArrayType(CustomModifiers.FromReqOpt(requiredCustomModifiers, optionalCustomModifiers));
1453 public Type MakeArrayType(
int rank)
1455 return __MakeArrayType(rank,
new CustomModifiers());
1458 public Type __MakeArrayType(
int rank, CustomModifiers customModifiers)
1460 return MultiArrayType.Make(
this, rank, Array.Empty<
int>(),
new int[rank], customModifiers);
1463 [Obsolete(
"Please use __MakeArrayType(int, CustomModifiers) instead.")]
1464 public Type __MakeArrayType(
int rank,
Type[] requiredCustomModifiers,
Type[] optionalCustomModifiers)
1466 return __MakeArrayType(rank, CustomModifiers.FromReqOpt(requiredCustomModifiers, optionalCustomModifiers));
1469 public Type __MakeArrayType(
int rank,
int[] sizes,
int[] lobounds, CustomModifiers customModifiers)
1471 return MultiArrayType.Make(
this, rank, sizes ?? Array.Empty<
int>(), lobounds ?? Array.Empty<
int>(), customModifiers);
1474 [Obsolete(
"Please use __MakeArrayType(int, int[], int[], CustomModifiers) instead.")]
1475 public Type __MakeArrayType(
int rank,
int[] sizes,
int[] lobounds,
Type[] requiredCustomModifiers,
Type[] optionalCustomModifiers)
1477 return __MakeArrayType(rank, sizes, lobounds, CustomModifiers.FromReqOpt(requiredCustomModifiers, optionalCustomModifiers));
1480 public Type MakeByRefType()
1482 return ByRefType.Make(
this,
new CustomModifiers());
1485 public Type __MakeByRefType(CustomModifiers customModifiers)
1487 return ByRefType.Make(
this, customModifiers);
1490 [Obsolete(
"Please use __MakeByRefType(CustomModifiers) instead.")]
1491 public Type __MakeByRefType(
Type[] requiredCustomModifiers,
Type[] optionalCustomModifiers)
1493 return __MakeByRefType(CustomModifiers.FromReqOpt(requiredCustomModifiers, optionalCustomModifiers));
1496 public Type MakePointerType()
1498 return PointerType.Make(
this,
new CustomModifiers());
1501 public Type __MakePointerType(CustomModifiers customModifiers)
1503 return PointerType.Make(
this, customModifiers);
1506 [Obsolete(
"Please use __MakeByRefType(CustomModifiers) instead.")]
1507 public Type __MakePointerType(
Type[] requiredCustomModifiers,
Type[] optionalCustomModifiers)
1509 return __MakePointerType(CustomModifiers.FromReqOpt(requiredCustomModifiers, optionalCustomModifiers));
1512 public Type MakeGenericType(params
Type[] typeArguments)
1514 return __MakeGenericType(typeArguments,
null);
1517 public Type __MakeGenericType(
Type[] typeArguments, CustomModifiers[] customModifiers)
1519 if (!this.__IsMissing && !this.IsGenericTypeDefinition)
1521 throw new InvalidOperationException();
1523 return GenericTypeInstance.Make(
this, Util.Copy(typeArguments), customModifiers ==
null ?
null : (CustomModifiers[])customModifiers.Clone());
1526 [Obsolete(
"Please use __MakeGenericType(Type[], CustomModifiers[]) instead.")]
1527 public Type __MakeGenericType(
Type[] typeArguments,
Type[][] requiredCustomModifiers,
Type[][] optionalCustomModifiers)
1529 if (!this.__IsMissing && !this.IsGenericTypeDefinition)
1530 throw new InvalidOperationException();
1532 CustomModifiers[] mods =
null;
1533 if (requiredCustomModifiers !=
null || optionalCustomModifiers !=
null)
1535 mods =
new CustomModifiers[typeArguments.Length];
1536 for (
int i = 0; i < mods.Length; i++)
1537 mods[i] = CustomModifiers.FromReqOpt(Util.NullSafeElementAt(requiredCustomModifiers, i), Util.NullSafeElementAt(optionalCustomModifiers, i));
1540 return GenericTypeInstance.Make(
this, Util.Copy(typeArguments), mods);
1543 public static System.Type __GetSystemType(TypeCode typeCode)
1545 return typeCode
switch
1547 TypeCode.Boolean => typeof(
System.Boolean),
1548 TypeCode.Byte => typeof(
System.Byte),
1549 TypeCode.Char => typeof(
System.Char),
1550 TypeCode.DBNull => typeof(
System.DBNull),
1551 TypeCode.DateTime => typeof(
System.DateTime),
1552 TypeCode.Decimal => typeof(
System.Decimal),
1553 TypeCode.Double => typeof(
System.Double),
1554 TypeCode.Empty =>
null,
1555 TypeCode.Int16 => typeof(
System.Int16),
1556 TypeCode.Int32 => typeof(
System.Int32),
1557 TypeCode.Int64 => typeof(
System.Int64),
1558 TypeCode.Object => typeof(
System.Object),
1559 TypeCode.SByte => typeof(
System.SByte),
1560 TypeCode.Single => typeof(
System.Single),
1561 TypeCode.String => typeof(
System.String),
1562 TypeCode.UInt16 => typeof(
System.UInt16),
1563 TypeCode.UInt32 => typeof(
System.UInt32),
1564 TypeCode.UInt64 => typeof(
System.UInt64),
1565 _ =>
throw new ArgumentOutOfRangeException(),
1569 public static TypeCode GetTypeCode(
Type type)
1572 return TypeCode.Empty;
1574 if (!type.__IsMissing && type.IsEnum)
1575 type = type.GetEnumUnderlyingType();
1577 Universe u = type.Module.Universe;
1578 if (type == u.System_Boolean)
1580 return TypeCode.Boolean;
1582 else if (type == u.System_Char)
1584 return TypeCode.Char;
1586 else if (type == u.System_SByte)
1588 return TypeCode.SByte;
1590 else if (type == u.System_Byte)
1592 return TypeCode.Byte;
1594 else if (type == u.System_Int16)
1596 return TypeCode.Int16;
1598 else if (type == u.System_UInt16)
1600 return TypeCode.UInt16;
1602 else if (type == u.System_Int32)
1604 return TypeCode.Int32;
1606 else if (type == u.System_UInt32)
1608 return TypeCode.UInt32;
1610 else if (type == u.System_Int64)
1612 return TypeCode.Int64;
1614 else if (type == u.System_UInt64)
1616 return TypeCode.UInt64;
1618 else if (type == u.System_Single)
1620 return TypeCode.Single;
1622 else if (type == u.System_Double)
1624 return TypeCode.Double;
1626 else if (type == u.System_DateTime)
1628 return TypeCode.DateTime;
1630 else if (type == u.System_DBNull)
1632 return TypeCode.DBNull;
1634 else if (type == u.System_Decimal)
1636 return TypeCode.Decimal;
1638 else if (type == u.System_String)
1640 return TypeCode.String;
1642 else if (type.__IsMissing)
1644 throw new MissingMemberException(type);
1648 return TypeCode.Object;
1654 get {
return Module.Assembly; }
1657 public bool IsAssignableFrom(
Type type)
1663 else if (type ==
null)
1667 else if (this.IsArray && type.IsArray)
1669 if (GetArrayRank() != type.GetArrayRank())
1673 else if (this.IsSZArray && !type.IsSZArray)
1678 var e1 = this.GetElementType();
1679 var e2 = type.GetElementType();
1680 return e1.IsValueType == e2.IsValueType && e1.IsAssignableFrom(e2);
1682 else if (this.IsCovariant(type))
1686 else if (this.IsSealed)
1690 else if (this.IsInterface)
1692 foreach (
Type iface
in type.GetInterfaces())
1694 if (this.Equals(iface) || this.IsCovariant(iface))
1701 else if (type.IsInterface)
1703 return this == this.
Module.Universe.System_Object;
1705 else if (type.IsPointer)
1707 return this == this.Module.Universe.System_Object ||
this == this.
Module.Universe.System_ValueType;
1711 return type.IsSubclassOf(
this);
1715 bool IsCovariant(
Type other)
1717 if (this.IsConstructedGenericType
1718 && other.IsConstructedGenericType
1719 &&
this.GetGenericTypeDefinition() == other.GetGenericTypeDefinition())
1721 Type[] typeParameters = GetGenericTypeDefinition().GetGenericArguments();
1722 for (
int i = 0; i < typeParameters.Length; i++)
1724 Type t1 = this.GetGenericTypeArgument(i);
1725 Type t2 = other.GetGenericTypeArgument(i);
1726 if (t1.IsValueType != t2.IsValueType)
1730 switch (typeParameters[i].GenericParameterAttributes & GenericParameterAttributes.VarianceMask)
1732 case GenericParameterAttributes.Covariant:
1733 if (!t1.IsAssignableFrom(t2))
1738 case GenericParameterAttributes.Contravariant:
1739 if (!t2.IsAssignableFrom(t1))
1744 case GenericParameterAttributes.None:
1757 public bool IsSubclassOf(
Type type)
1759 Type thisType = this.BaseType;
1760 while (thisType !=
null)
1762 if (thisType.Equals(type))
1765 thisType = thisType.BaseType;
1778 bool IsDirectlyImplementedInterface(
Type interfaceType)
1780 foreach (var iface
in __GetDeclaredInterfaces())
1781 if (interfaceType.IsAssignableFrom(iface))
1787 public InterfaceMapping GetInterfaceMap(
Type interfaceType)
1791 var map =
new InterfaceMapping();
1792 map.InterfaceMethods = interfaceType.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public);
1793 map.InterfaceType = interfaceType;
1794 map.TargetMethods =
new MethodInfo[map.InterfaceMethods.Length];
1795 map.TargetType =
this;
1796 FillInInterfaceMethods(interfaceType, map.InterfaceMethods, map.TargetMethods);
1802 FillInExplicitInterfaceMethods(interfaceMethods, targetMethods);
1804 var direct = IsDirectlyImplementedInterface(interfaceType);
1806 FillInImplicitInterfaceMethods(interfaceMethods, targetMethods);
1808 var baseType = BaseType;
1809 if (baseType !=
null)
1811 baseType.FillInInterfaceMethods(interfaceType, interfaceMethods, targetMethods);
1812 ReplaceOverriddenMethods(targetMethods);
1816 for (var type = BaseType; type !=
null && type.Module ==
Module; type = type.BaseType)
1817 type.FillInImplicitInterfaceMethods(interfaceMethods, targetMethods);
1824 for (
int i = 0; i < targetMethods.Length; i++)
1826 if (targetMethods[i] ==
null)
1828 methods ??= __GetDeclaredMethods();
1830 for (
int j = 0; j < methods.Length; j++)
1832 if (methods[j].IsVirtual && methods[j].
Name == interfaceMethods[i].
Name && methods[j].MethodSignature.Equals(interfaceMethods[i].MethodSignature))
1842 void ReplaceOverriddenMethods(
MethodInfo[] baseMethods)
1844 var impl = __GetMethodImplMap();
1845 for (
int i = 0; i < baseMethods.Length; i++)
1847 if (baseMethods[i] !=
null && !baseMethods[i].IsFinal)
1849 var def = baseMethods[i].GetBaseDefinition();
1850 for (
int j = 0; j < impl.MethodDeclarations.Length; j++)
1852 for (
int k = 0; k < impl.MethodDeclarations[j].Length; k++)
1854 if (impl.MethodDeclarations[j][k].GetBaseDefinition() == def)
1856 baseMethods[i] = impl.MethodBodies[j];
1862 var candidate = FindMethod(def.Name, def.MethodSignature) as
MethodInfo;
1863 if (candidate != null && candidate.IsVirtual && !candidate.IsNewSlot)
1864 baseMethods[i] = candidate;
1872 var impl = __GetMethodImplMap();
1873 for (
int i = 0; i < impl.MethodDeclarations.Length; i++)
1875 for (
int j = 0; j < impl.MethodDeclarations[i].Length; j++)
1877 int index = Array.IndexOf(interfaceMethods, impl.MethodDeclarations[i][j]);
1878 if (index != -1 && targetMethods[index] ==
null)
1879 targetMethods[index] = impl.MethodBodies[i];
1884 Type IGenericContext.GetGenericTypeArgument(
int index)
1886 return GetGenericTypeArgument(index);
1889 Type IGenericContext.GetGenericMethodArgument(
int index)
1891 throw new BadImageFormatException();
1894 Type IGenericBinder.BindTypeParameter(
Type type)
1896 return GetGenericTypeArgument(type.GenericParameterPosition);
1899 Type IGenericBinder.BindMethodParameter(
Type type)
1901 throw new BadImageFormatException();
1904 internal virtual Type BindTypeParameters(IGenericBinder binder)
1906 if (IsGenericTypeDefinition)
1908 var args = GetGenericArguments();
1909 Type.InplaceBindTypeParameters(binder, args);
1910 return GenericTypeInstance.Make(
this, args,
null);
1918 static void InplaceBindTypeParameters(IGenericBinder binder,
Type[] types)
1920 for (
int i = 0; i < types.Length; i++)
1921 types[i] = types[i].BindTypeParameters(binder);
1924 internal virtual MethodBase FindMethod(
string name, MethodSignature signature)
1926 foreach (var method
in __GetDeclaredMethods())
1927 if (method.Name == name && method.MethodSignature.Equals(signature))
1933 internal virtual FieldInfo FindField(
string name, FieldSignature signature)
1935 foreach (var field
in __GetDeclaredFields())
1936 if (field.Name == name && field.FieldSignature.Equals(signature))
1942 internal bool IsAllowMultipleCustomAttribute
1946 var cad = CustomAttributeData.__GetCustomAttributes(
this, this.
Module.Universe.System_AttributeUsageAttribute,
false);
1948 foreach (CustomAttributeNamedArgument arg
in cad[0].NamedArguments)
1949 if (arg.MemberInfo.Name ==
"AllowMultiple")
1950 return (
bool)arg.TypedValue.Value;
1956 internal Type MarkNotValueType()
1958 typeFlags |= TypeFlags.NotValueType;
1962 internal Type MarkValueType()
1964 typeFlags |= TypeFlags.ValueType;
1968 internal ConstructorInfo GetPseudoCustomAttributeConstructor(params
Type[] parameterTypes)
1971 var methodSig = MethodSignature.MakeFromBuilder(u.System_Void, parameterTypes,
new PackedCustomModifiers(), CallingConventions.Standard | CallingConventions.HasThis, 0);
1972 var mb = FindMethod(
".ctor", methodSig) ?? u.GetMissingMethodOrThrow(
null,
this,
".ctor", methodSig);
1976 public MethodBase __CreateMissingMethod(
string name, CallingConventions callingConvention,
Type returnType, CustomModifiers returnTypeCustomModifiers,
Type[] parameterTypes, CustomModifiers[] parameterTypeCustomModifiers)
1978 return CreateMissingMethod(name, callingConvention, returnType, parameterTypes, PackedCustomModifiers.CreateFromExternal(returnTypeCustomModifiers, parameterTypeCustomModifiers, parameterTypes.Length));
1981 MethodBase CreateMissingMethod(
string name, CallingConventions callingConvention,
Type returnType,
Type[] parameterTypes, PackedCustomModifiers customModifiers)
1983 var sig =
new MethodSignature(returnType ??
Module.Universe.System_Void, Util.Copy(parameterTypes), customModifiers, callingConvention, 0);
1984 var method =
new MissingMethod(
this, name, sig);
1986 if (name ==
".ctor" || name ==
".cctor")
1987 return new ConstructorInfoImpl(method);
1992 [Obsolete(
"Please use __CreateMissingMethod(string, CallingConventions, Type, CustomModifiers, Type[], CustomModifiers[]) instead")]
1993 public MethodBase __CreateMissingMethod(
string name, CallingConventions callingConvention,
Type returnType,
Type[] returnTypeRequiredCustomModifiers,
Type[] returnTypeOptionalCustomModifiers,
Type[] parameterTypes,
Type[][] parameterTypeRequiredCustomModifiers,
Type[][] parameterTypeOptionalCustomModifiers)
1995 return CreateMissingMethod(name, callingConvention, returnType, parameterTypes, PackedCustomModifiers.CreateFromExternal(returnTypeOptionalCustomModifiers, returnTypeRequiredCustomModifiers, parameterTypeOptionalCustomModifiers, parameterTypeRequiredCustomModifiers, parameterTypes.Length));
1998 public FieldInfo __CreateMissingField(
string name,
Type fieldType, CustomModifiers customModifiers)
2000 return new MissingField(
this, name, FieldSignature.Create(fieldType, customModifiers));
2003 [Obsolete(
"Please use __CreateMissingField(string, Type, CustomModifiers) instead")]
2004 public FieldInfo __CreateMissingField(
string name,
Type fieldType,
Type[] requiredCustomModifiers,
Type[] optionalCustomModifiers)
2006 return __CreateMissingField(name, fieldType, CustomModifiers.FromReqOpt(requiredCustomModifiers, optionalCustomModifiers));
2009 public PropertyInfo __CreateMissingProperty(
string name, CallingConventions callingConvention,
Type propertyType, CustomModifiers propertyTypeCustomModifiers,
Type[] parameterTypes, CustomModifiers[] parameterTypeCustomModifiers)
2011 var sig = PropertySignature.Create(callingConvention, propertyType, parameterTypes, PackedCustomModifiers.CreateFromExternal(propertyTypeCustomModifiers, parameterTypeCustomModifiers, Util.NullSafeLength(parameterTypes)));
2012 return new MissingProperty(
this, name, sig);
2015 internal virtual Type SetMetadataTokenForMissing(
int token,
int flags)
2020 internal virtual Type SetCyclicTypeForwarder()
2025 internal virtual Type SetCyclicTypeSpec()
2030 protected void MarkKnownType(
string typeNamespace,
string typeName)
2034 if (typeNamespace ==
"System")
2050 case "TypedReference":
2056 typeFlags |= TypeFlags.PotentialBuiltIn;
2060 typeFlags |= TypeFlags.PotentialEnumOrValueType;
2066 bool ResolvePotentialEnumOrValueType()
2068 if (
Assembly == Universe.CoreLib ||
Assembly.GetName().Name.Equals(
"mscorlib", StringComparison.OrdinalIgnoreCase)
2070 || Universe.CoreLib.FindType(TypeName) ==
this)
2072 typeFlags = (typeFlags & ~TypeFlags.PotentialEnumOrValueType) | TypeFlags.EnumOrValueType;
2077 typeFlags &= ~TypeFlags.PotentialEnumOrValueType;
2082 internal bool IsEnumOrValueType
2086 return (typeFlags & (TypeFlags.EnumOrValueType | TypeFlags.PotentialEnumOrValueType)) != 0
2087 && ((typeFlags & TypeFlags.EnumOrValueType) != 0 || ResolvePotentialEnumOrValueType());
2091 internal virtual Universe Universe
2093 get {
return Module.Universe; }
2096 internal sealed override bool BindingFlagsMatch(BindingFlags flags)
2098 return BindingFlagsMatch(IsNestedPublic, flags, BindingFlags.Public, BindingFlags.NonPublic);
2103 throw new InvalidOperationException();
2106 internal override int GetCurrentToken()
2108 return MetadataToken;
2111 internal sealed override List<CustomAttributeData> GetPseudoCustomAttributes(
Type attributeType)
2118 public TypeInfo GetTypeInfo()
2120 return this as TypeInfo ??
throw new MissingMemberException(
this);
2123 public virtual bool __IsTypeForwarder
2125 get {
return false; }
2128 public virtual bool __IsCyclicTypeForwarder
2130 get {
return false; }
2133 public virtual bool __IsCyclicTypeSpec
2135 get {
return false; }
IKVM.Reflection.Module Module
IKVM.Reflection.Type Type
IKVM.Reflection.Assembly Assembly
IKVM.Reflection.ConstructorInfo ConstructorInfo
IKVM.Reflection.EventInfo EventInfo
IKVM.Reflection.FieldInfo FieldInfo
IKVM.Reflection.MemberInfo MemberInfo
IKVM.Reflection.PropertyInfo PropertyInfo
IKVM.Reflection.MethodInfo MethodInfo
IKVM.Reflection.MethodBase MethodBase
global::java.lang.invoke.LambdaForm.Name Name