25using System.Collections.Generic;
26using System.Diagnostics.SymbolStore;
29using System.Security.Cryptography;
41 internal sealed class Universe : IDisposable
44 public static readonly
string NetCoreLibName =
"System.Runtime";
45 public static readonly
string NetFxCoreLibName =
"mscorlib";
47#if NETCOREAPP3_1_OR_GREATER
49 public static readonly
string DefaultCoreLibName = NetCoreLibName;
53 public static readonly
string DefaultCoreLibName = NetFxCoreLibName;
58 internal static readonly
bool MonoRuntime =
System.Type.GetType(
"Mono.Runtime") !=
null;
59 internal static readonly
bool CoreRuntime =
false;
61 internal static readonly
bool MonoRuntime =
false;
62 internal static readonly
bool CoreRuntime =
true;
65 readonly
string coreLibName;
66 readonly Dictionary<Type, Type> canonicalizedTypes =
new Dictionary<Type, Type>();
67 readonly List<AssemblyReader> assemblies =
new List<AssemblyReader>();
68 readonly List<AssemblyBuilder> dynamicAssemblies =
new List<AssemblyBuilder>();
69 readonly Dictionary<string, Assembly> assembliesByName =
new Dictionary<string, Assembly>();
71 Dictionary<ScopedTypeName, Type> missingTypes;
72 bool resolveMissingMembers;
73 readonly
bool enableFunctionPointers;
74 readonly
bool useNativeFusion;
75 readonly
bool returnPseudoCustomAttributes;
76 readonly
bool automaticallyProvideDefaultConstructor;
77 HashAlgorithmName pdbChecksumAlgorithm = HashAlgorithmName.SHA256;
78 readonly UniverseOptions options;
79 Func<ModuleBuilder, ISymbolWriter> symbolWriterFactory;
80 Type typeof_System_Object;
81 Type typeof_System_ValueType;
82 Type typeof_System_Enum;
83 Type typeof_System_Void;
84 Type typeof_System_Boolean;
85 Type typeof_System_Char;
86 Type typeof_System_SByte;
87 Type typeof_System_Byte;
88 Type typeof_System_Int16;
89 Type typeof_System_UInt16;
90 Type typeof_System_Int32;
91 Type typeof_System_UInt32;
92 Type typeof_System_Int64;
93 Type typeof_System_UInt64;
94 Type typeof_System_Single;
95 Type typeof_System_Double;
96 Type typeof_System_String;
97 Type typeof_System_IntPtr;
98 Type typeof_System_UIntPtr;
99 Type typeof_System_TypedReference;
100 Type typeof_System_Type;
101 Type typeof_System_Array;
102 Type typeof_System_DateTime;
103 Type typeof_System_DBNull;
104 Type typeof_System_Decimal;
105 Type typeof_System_AttributeUsageAttribute;
106 Type typeof_System_ContextBoundObject;
107 Type typeof_System_MarshalByRefObject;
108 Type typeof_System_Console;
109 Type typeof_System_IO_TextWriter;
110 Type typeof_System_Runtime_InteropServices_DllImportAttribute;
111 Type typeof_System_Runtime_InteropServices_FieldOffsetAttribute;
112 Type typeof_System_Runtime_InteropServices_MarshalAsAttribute;
113 Type typeof_System_Runtime_InteropServices_UnmanagedType;
114 Type typeof_System_Runtime_InteropServices_VarEnum;
115 Type typeof_System_Runtime_InteropServices_PreserveSigAttribute;
116 Type typeof_System_Runtime_InteropServices_CallingConvention;
117 Type typeof_System_Runtime_InteropServices_CharSet;
118 Type typeof_System_Runtime_CompilerServices_DecimalConstantAttribute;
119 Type typeof_System_Reflection_AssemblyCopyrightAttribute;
120 Type typeof_System_Reflection_AssemblyTrademarkAttribute;
121 Type typeof_System_Reflection_AssemblyProductAttribute;
122 Type typeof_System_Reflection_AssemblyCompanyAttribute;
123 Type typeof_System_Reflection_AssemblyDescriptionAttribute;
124 Type typeof_System_Reflection_AssemblyTitleAttribute;
125 Type typeof_System_Reflection_AssemblyInformationalVersionAttribute;
126 Type typeof_System_Reflection_AssemblyFileVersionAttribute;
127 Type typeof_System_Security_Permissions_CodeAccessSecurityAttribute;
128 Type typeof_System_Security_Permissions_PermissionSetAttribute;
129 Type typeof_System_Security_Permissions_SecurityAction;
130 List<ResolveEventHandler> resolvers =
new List<ResolveEventHandler>();
131 Predicate<Type> missingTypeIsValueType;
137 public Universe(
string coreLibName =
null) :
138 this(UniverseOptions.None, coreLibName)
148 public Universe(UniverseOptions options,
string coreLibName =
null)
150 this.options = options;
151 this.coreLibName = coreLibName ?? DefaultCoreLibName;
152 enableFunctionPointers = (options & UniverseOptions.EnableFunctionPointers) != 0;
153 useNativeFusion = (options & UniverseOptions.DisableFusion) == 0 && GetUseNativeFusion();
154 returnPseudoCustomAttributes = (options & UniverseOptions.DisablePseudoCustomAttributeRetrieval) == 0;
155 automaticallyProvideDefaultConstructor = (options & UniverseOptions.DontProvideAutomaticDefaultConstructor) == 0;
156 resolveMissingMembers = (options & UniverseOptions.ResolveMissingMembers) != 0;
163 public void SetSymbolWriterFactory(Func<ModuleBuilder, ISymbolWriter> factory)
165 this.symbolWriterFactory = factory;
172 public void SetPdbChecksumAlgorithm(HashAlgorithmName pdbChecksumAlgorithm)
174 this.pdbChecksumAlgorithm = pdbChecksumAlgorithm;
182 internal ISymbolWriter CreateSymbolWriter(ModuleBuilder module)
184 return symbolWriterFactory?.Invoke(module);
187 static bool GetUseNativeFusion()
191 return Environment.OSVersion.Platform == PlatformID.Win32NT && !MonoRuntime && !CoreRuntime && Environment.GetEnvironmentVariable(
"IKVM_DISABLE_FUSION") ==
null;
193 catch (SecurityException)
202 public string CoreLibName => coreLibName;
207 public Assembly CoreLib => Load(coreLibName);
215 Type ImportCoreLibType(
string ns,
string name)
217 if (CoreLib.__IsMissing)
218 return CoreLib.ResolveType(
null,
new TypeName(ns, name));
224 return CoreLib.FindType(
new TypeName(ns, name));
232 Type ResolvePrimitive(
string name)
237 return CoreLib.FindType(
new TypeName(
"System", name)) ?? GetMissingType(
null, CoreLib.ManifestModule,
null,
new TypeName(
"System", name));
240 internal Type System_Object => typeof_System_Object ??= ResolvePrimitive(
"Object");
242 internal Type System_ValueType => typeof_System_ValueType ??= ResolvePrimitive(
"ValueType");
244 internal Type System_Enum => typeof_System_Enum ??= ResolvePrimitive(
"Enum");
246 internal Type System_Void => typeof_System_Void ??= ResolvePrimitive(
"Void");
248 internal Type System_Boolean => typeof_System_Boolean ??= ResolvePrimitive(
"Boolean");
250 internal Type System_Char => typeof_System_Char ??= ResolvePrimitive(
"Char");
252 internal Type System_SByte => typeof_System_SByte ??= ResolvePrimitive(
"SByte");
254 internal Type System_Byte => typeof_System_Byte ??= ResolvePrimitive(
"Byte");
256 internal Type System_Int16 => typeof_System_Int16 ??= ResolvePrimitive(
"Int16");
258 internal Type System_UInt16 => typeof_System_UInt16 ??= ResolvePrimitive(
"UInt16");
260 internal Type System_Int32 => typeof_System_Int32 ??= ResolvePrimitive(
"Int32");
262 internal Type System_UInt32 => typeof_System_UInt32 ??= ResolvePrimitive(
"UInt32");
264 internal Type System_Int64 => typeof_System_Int64 ??= ResolvePrimitive(
"Int64");
266 internal Type System_UInt64 => typeof_System_UInt64 ??= ResolvePrimitive(
"UInt64");
268 internal Type System_Single => typeof_System_Single ??= ResolvePrimitive(
"Single");
270 internal Type System_Double => typeof_System_Double ??= ResolvePrimitive(
"Double");
272 internal Type System_String => typeof_System_String ??= ResolvePrimitive(
"String");
274 internal Type System_IntPtr => typeof_System_IntPtr ??= ResolvePrimitive(
"IntPtr");
276 internal Type System_UIntPtr => typeof_System_UIntPtr ??= ResolvePrimitive(
"UIntPtr");
278 internal Type System_TypedReference => typeof_System_TypedReference ??= ResolvePrimitive(
"TypedReference");
280 internal Type System_Type => typeof_System_Type ??= ResolvePrimitive(
"Type");
282 internal Type System_Array => typeof_System_Array ??= ResolvePrimitive(
"Array");
284 internal Type System_DateTime => typeof_System_DateTime ??= ImportCoreLibType(
"System",
"DateTime");
286 internal Type System_DBNull => typeof_System_DBNull ??= ImportCoreLibType(
"System",
"DBNull");
288 internal Type System_Decimal => typeof_System_Decimal ??= ImportCoreLibType(
"System",
"Decimal");
290 internal Type System_AttributeUsageAttribute => typeof_System_AttributeUsageAttribute ??= ImportCoreLibType(
"System",
"AttributeUsageAttribute");
292 internal Type System_ContextBoundObject => typeof_System_ContextBoundObject ??= ImportCoreLibType(
"System",
"ContextBoundObject");
294 internal Type System_MarshalByRefObject => typeof_System_MarshalByRefObject ??= ImportCoreLibType(
"System",
"MarshalByRefObject");
296 internal Type System_Console => typeof_System_Console ??= ImportCoreLibType(
"System",
"Console");
298 internal Type System_IO_TextWriter => typeof_System_IO_TextWriter ??= ImportCoreLibType(
"System.IO",
"TextWriter");
300 internal Type System_Runtime_InteropServices_DllImportAttribute => typeof_System_Runtime_InteropServices_DllImportAttribute ??= ImportCoreLibType(
"System.Runtime.InteropServices",
"DllImportAttribute");
302 internal Type System_Runtime_InteropServices_FieldOffsetAttribute => typeof_System_Runtime_InteropServices_FieldOffsetAttribute ??= ImportCoreLibType(
"System.Runtime.InteropServices",
"FieldOffsetAttribute");
304 internal Type System_Runtime_InteropServices_MarshalAsAttribute => typeof_System_Runtime_InteropServices_MarshalAsAttribute ??= ImportCoreLibType(
"System.Runtime.InteropServices",
"MarshalAsAttribute");
306 internal Type System_Runtime_InteropServices_UnmanagedType => typeof_System_Runtime_InteropServices_UnmanagedType ??= ImportCoreLibType(
"System.Runtime.InteropServices",
"UnmanagedType");
308 internal Type System_Runtime_InteropServices_VarEnum => typeof_System_Runtime_InteropServices_VarEnum ??= ImportCoreLibType(
"System.Runtime.InteropServices",
"VarEnum");
310 internal Type System_Runtime_InteropServices_PreserveSigAttribute => typeof_System_Runtime_InteropServices_PreserveSigAttribute ??= ImportCoreLibType(
"System.Runtime.InteropServices",
"PreserveSigAttribute");
312 internal Type System_Runtime_InteropServices_CallingConvention => typeof_System_Runtime_InteropServices_CallingConvention ??= ImportCoreLibType(
"System.Runtime.InteropServices",
"CallingConvention");
314 internal Type System_Runtime_InteropServices_CharSet => typeof_System_Runtime_InteropServices_CharSet ??= ImportCoreLibType(
"System.Runtime.InteropServices",
"CharSet");
316 internal Type System_Runtime_CompilerServices_DecimalConstantAttribute => typeof_System_Runtime_CompilerServices_DecimalConstantAttribute ??= ImportCoreLibType(
"System.Runtime.CompilerServices",
"DecimalConstantAttribute");
318 internal Type System_Reflection_AssemblyCopyrightAttribute => typeof_System_Reflection_AssemblyCopyrightAttribute ??= ImportCoreLibType(
"System.Reflection",
"AssemblyCopyrightAttribute");
320 internal Type System_Reflection_AssemblyTrademarkAttribute => typeof_System_Reflection_AssemblyTrademarkAttribute ??= ImportCoreLibType(
"System.Reflection",
"AssemblyTrademarkAttribute");
322 internal Type System_Reflection_AssemblyProductAttribute => typeof_System_Reflection_AssemblyProductAttribute ??= ImportCoreLibType(
"System.Reflection",
"AssemblyProductAttribute");
324 internal Type System_Reflection_AssemblyCompanyAttribute => typeof_System_Reflection_AssemblyCompanyAttribute ??= ImportCoreLibType(
"System.Reflection",
"AssemblyCompanyAttribute");
326 internal Type System_Reflection_AssemblyDescriptionAttribute => typeof_System_Reflection_AssemblyDescriptionAttribute ??= ImportCoreLibType(
"System.Reflection",
"AssemblyDescriptionAttribute");
328 internal Type System_Reflection_AssemblyTitleAttribute => typeof_System_Reflection_AssemblyTitleAttribute ??= ImportCoreLibType(
"System.Reflection",
"AssemblyTitleAttribute");
330 internal Type System_Reflection_AssemblyInformationalVersionAttribute => typeof_System_Reflection_AssemblyInformationalVersionAttribute ??= ImportCoreLibType(
"System.Reflection",
"AssemblyInformationalVersionAttribute");
332 internal Type System_Reflection_AssemblyFileVersionAttribute => typeof_System_Reflection_AssemblyFileVersionAttribute ??= ImportCoreLibType(
"System.Reflection",
"AssemblyFileVersionAttribute");
334 internal Type System_Security_Permissions_CodeAccessSecurityAttribute => typeof_System_Security_Permissions_CodeAccessSecurityAttribute ??= ImportCoreLibType(
"System.Security.Permissions",
"CodeAccessSecurityAttribute");
336 internal Type System_Security_Permissions_PermissionSetAttribute => typeof_System_Security_Permissions_PermissionSetAttribute ??= ImportCoreLibType(
"System.Security.Permissions",
"PermissionSetAttribute");
338 internal Type System_Security_Permissions_SecurityAction => typeof_System_Security_Permissions_SecurityAction ??= ImportCoreLibType(
"System.Security.Permissions",
"SecurityAction");
343 internal bool HasCoreLib
345 get {
return GetLoadedAssembly(coreLibName) !=
null; }
351 public event ResolveEventHandler AssemblyResolve
353 add { resolvers.Add(value); }
354 remove { resolvers.Remove(value); }
364 if (!importedTypes.TryGetValue(type, out var imported))
366 imported = ImportImpl(type);
367 if (imported !=
null)
368 importedTypes.Add(type, imported);
386 throw new ArgumentException(
"Did you really want to import " + type.FullName +
"?");
389 if (type.HasElementType)
394 if (type.Name.EndsWith(
"[]"))
395 return Import(type.GetElementType()).MakeArrayType();
397 return Import(type.GetElementType()).MakeArrayType(type.GetArrayRank());
402 return Import(type.GetElementType()).MakeByRefType();
406 return Import(type.GetElementType()).MakePointerType();
408 throw new InvalidOperationException();
412 if (type.IsGenericParameter)
414 if (
TypeUtil.GetDeclaringMethod(type) !=
null)
415 throw new NotImplementedException();
417 return Import(type.DeclaringType).GetGenericArguments()[type.GenericParameterPosition];
420 if (
TypeUtil.IsGenericType(type) && !
TypeUtil.IsGenericTypeDefinition(type))
423 Type[] importedArgs =
new Type[args.Length];
424 for (
int i = 0; i < args.Length; i++)
425 importedArgs[i] = Import(args[i]);
427 return Import(type.GetGenericTypeDefinition()).MakeGenericType(importedArgs);
432 return ResolveType(CoreLib, type.FullName);
435 return ResolveType(Import(
TypeUtil.GetAssembly(type)), type.FullName);
445 return Load(
asm.FullName);
448 public RawModule OpenRawModule(
string path)
450 path = Path.GetFullPath(path);
452 FileStream fs =
null;
457 fs =
new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
458 module = OpenRawModule(fs, path);
459 if (MetadataOnly ==
false)
470 public RawModule OpenRawModule(Stream stream,
string location)
472 return OpenRawModule(stream, location,
false);
475 public RawModule OpenMappedRawModule(Stream stream,
string location)
477 return OpenRawModule(stream, location,
true);
480 RawModule OpenRawModule(Stream stream,
string location,
bool mapped)
482 if (!stream.CanRead || !stream.CanSeek || stream.Position != 0)
483 throw new ArgumentException(
"Stream must support read/seek and current position must be zero.",
"stream");
485 return new RawModule(
new ModuleReader(
null,
this, stream, location, mapped));
488 public Assembly LoadAssembly(RawModule module)
490 var refname = module.GetAssemblyName().FullName;
491 var
asm = GetLoadedAssembly(refname);
494 var asm1 = module.ToAssembly();
495 assemblies.Add(asm1);
502 public Assembly LoadFile(
string path)
506 using (var module = OpenRawModule(path))
507 return LoadAssembly(module);
509 catch (IOException e)
511 throw new FileNotFoundException(e.Message, e);
513 catch (UnauthorizedAccessException e)
515 throw new FileNotFoundException(e.Message, e);
519 static string GetSimpleAssemblyName(
string refname)
522 throw new ArgumentException();
527 Assembly GetLoadedAssembly(
string refname)
529 if (!assembliesByName.TryGetValue(refname, out var
asm) && (options & UniverseOptions.DisableDefaultAssembliesLookup) == 0)
531 var simpleName = GetSimpleAssemblyName(refname);
532 for (
int i = 0; i < assemblies.Count; i++)
534 if (simpleName.Equals(assemblies[i].Name, StringComparison.OrdinalIgnoreCase) && CompareAssemblyIdentity(coreLibName, refname,
false, assemblies[i].FullName,
false, out var result))
537 assembliesByName.Add(refname,
asm);
546 Assembly GetDynamicAssembly(
string refname)
548 var simpleName = GetSimpleAssemblyName(refname);
549 foreach (var
asm in dynamicAssemblies)
550 if (simpleName.Equals(
asm.Name, StringComparison.OrdinalIgnoreCase) && CompareAssemblyIdentity(coreLibName, refname,
false,
asm.FullName,
false, out var result))
556 public Assembly Load(
string refname)
558 return Load(refname,
null,
true);
561 internal Assembly Load(
string refname,
Module requestingModule,
bool throwOnError)
563 var
asm = GetLoadedAssembly(refname);
567 if (resolvers.Count == 0)
569 asm = DefaultResolver(refname, throwOnError);
573 var args =
new ResolveEventArgs(refname, requestingModule ==
null ?
null : requestingModule.Assembly);
574 foreach (var evt
in resolvers)
576 asm = evt(
this, args);
582 asm = GetDynamicAssembly(refname);
588 var defname =
asm.FullName;
589 assembliesByName[refname] =
asm;
590 assembliesByName[defname] =
asm;
595 throw new FileNotFoundException(refname);
600 Assembly DefaultResolver(
string refname,
bool throwOnError)
602 var
asm = GetDynamicAssembly(refname);
609 public Type GetType(
string assemblyQualifiedTypeName)
613 return GetType(
null, assemblyQualifiedTypeName,
false,
false);
616 public Type GetType(
string assemblyQualifiedTypeName,
bool throwOnError)
620 return GetType(
null, assemblyQualifiedTypeName, throwOnError,
false);
623 public Type GetType(
string assemblyQualifiedTypeName,
bool throwOnError,
bool ignoreCase)
627 return GetType(
null, assemblyQualifiedTypeName, throwOnError, ignoreCase);
632 public Type GetType(
Assembly context,
string assemblyQualifiedTypeName,
bool throwOnError)
634 return GetType(context, assemblyQualifiedTypeName, throwOnError,
false);
639 public Type GetType(
Assembly context,
string assemblyQualifiedTypeName,
bool throwOnError,
bool ignoreCase)
646 return parser.GetType(
this, context ==
null ?
null : context.ManifestModule, throwOnError, assemblyQualifiedTypeName,
false, ignoreCase);
652 public Type ResolveType(
Assembly context,
string assemblyQualifiedTypeName)
659 return parser.GetType(
this, context ==
null ?
null : context.ManifestModule,
false, assemblyQualifiedTypeName,
true,
false);
668 public Type GetBuiltInType(
string ns,
string name)
675 "Boolean" => System_Boolean,
676 "Char" => System_Char,
677 "Object" => System_Object,
678 "String" => System_String,
679 "Single" => System_Single,
680 "Double" => System_Double,
681 "SByte" => System_SByte,
682 "Int16" => System_Int16,
683 "Int32" => System_Int32,
684 "Int64" => System_Int64,
685 "IntPtr" => System_IntPtr,
686 "UIntPtr" => System_UIntPtr,
687 "TypedReference" => System_TypedReference,
688 "Byte" => System_Byte,
689 "UInt16" => System_UInt16,
690 "UInt32" => System_UInt32,
691 "UInt64" => System_UInt64,
692 "Void" => System_Void,
703 var array =
new Assembly[assemblies.Count + dynamicAssemblies.Count];
704 for (
int i = 0; i < assemblies.Count; i++)
705 array[i] = assemblies[i];
706 for (
int i = 0, j = assemblies.Count; j < array.Length; i++, j++)
707 array[j] = dynamicAssemblies[i];
712 public bool CompareAssemblyIdentity(
string coreLibName,
string assemblyIdentity1,
bool unified1,
string assemblyIdentity2,
bool unified2, out AssemblyComparisonResult result)
714 return useNativeFusion
715 ?
Fusion.CompareAssemblyIdentityNative(coreLibName, assemblyIdentity1, unified1, assemblyIdentity2, unified2, out result)
716 :
Fusion.CompareAssemblyIdentityPure(coreLibName, assemblyIdentity1, unified1, assemblyIdentity2, unified2, out result);
719 public AssemblyBuilder DefineDynamicAssembly(
AssemblyName name, AssemblyBuilderAccess access)
721 return new AssemblyBuilder(
this, name,
null,
null);
724 public AssemblyBuilder DefineDynamicAssembly(
AssemblyName name, AssemblyBuilderAccess access, IEnumerable<CustomAttributeBuilder> assemblyAttributes)
726 return new AssemblyBuilder(
this, name,
null, assemblyAttributes);
729 public AssemblyBuilder DefineDynamicAssembly(
AssemblyName name, AssemblyBuilderAccess access,
string dir)
731 return new AssemblyBuilder(
this, name, dir,
null);
735 public AssemblyBuilder DefineDynamicAssembly(
AssemblyName name, AssemblyBuilderAccess access,
string dir, PermissionSet requiredPermissions, PermissionSet optionalPermissions, PermissionSet refusedPermissions)
737 var ab =
new AssemblyBuilder(
this, name, dir,
null);
738 AddLegacyPermissionSet(ab, requiredPermissions,
System.Security.Permissions.SecurityAction.RequestMinimum);
739 AddLegacyPermissionSet(ab, optionalPermissions,
System.Security.Permissions.SecurityAction.RequestOptional);
740 AddLegacyPermissionSet(ab, refusedPermissions,
System.Security.Permissions.SecurityAction.RequestRefuse);
744 private static void AddLegacyPermissionSet(AssemblyBuilder ab, PermissionSet permissionSet,
System.Security.Permissions.SecurityAction action)
746 if (permissionSet !=
null)
748 ab.__AddDeclarativeSecurity(CustomAttributeBuilder.__FromBlob(CustomAttributeBuilder.LegacyPermissionSet, (
int)action, Encoding.Unicode.GetBytes(permissionSet.ToXml().ToString())));
752 internal void RegisterDynamicAssembly(AssemblyBuilder
asm)
754 dynamicAssemblies.Add(
asm);
759 List<string>
remove =
new List<string>();
760 foreach (KeyValuePair<string, Assembly> kv
in assembliesByName)
762 if (kv.Value == assembly)
767 foreach (
string key
in remove)
769 assembliesByName.Remove(key);
773 public void Dispose()
775 foreach (
Assembly asm in assemblies)
777 foreach (
Module mod
in asm.GetLoadedModules())
782 foreach (AssemblyBuilder
asm in dynamicAssemblies)
784 foreach (
Module mod
in asm.GetLoadedModules())
791 public Assembly CreateMissingAssembly(
string assemblyName)
794 string name =
asm.FullName;
795 if (!assembliesByName.ContainsKey(name))
797 assembliesByName.Add(name,
asm);
802 [Obsolete(
"Please set UniverseOptions.ResolveMissingMembers instead.")]
803 public void EnableMissingMemberResolution()
805 resolveMissingMembers =
true;
808 internal bool MissingMemberResolution
810 get {
return resolveMissingMembers; }
813 internal bool EnableFunctionPointers
815 get {
return enableFunctionPointers; }
818 private struct ScopedTypeName : IEquatable<ScopedTypeName>
820 private readonly
object scope;
823 internal ScopedTypeName(
object scope,
TypeName name)
829 public override bool Equals(
object obj)
831 ScopedTypeName? other = obj as ScopedTypeName?;
832 return other !=
null && ((IEquatable<ScopedTypeName>)other.Value).Equals(
this);
835 public override int GetHashCode()
837 return scope.GetHashCode() * 7 + name.GetHashCode();
840 bool IEquatable<ScopedTypeName>.Equals(ScopedTypeName other)
842 return other.scope == scope && other.name == name;
848 if (missingTypes ==
null)
850 missingTypes =
new Dictionary<ScopedTypeName, Type>();
852 ScopedTypeName stn =
new ScopedTypeName(declaringType ?? (
object)module, typeName);
854 if (!missingTypes.TryGetValue(stn, out type))
856 type =
new MissingType(module, declaringType, typeName.Namespace, typeName.Name);
857 missingTypes.Add(stn, type);
859 if (ResolvedMissingMember !=
null && !module.Assembly.__IsMissing)
861 ResolvedMissingMember(requester, type);
868 if (resolveMissingMembers || module.Assembly.__IsMissing)
870 return GetMissingType(requester, module, declaringType, typeName);
873 if (declaringType !=
null)
875 fullName = declaringType.FullName +
"+" + fullName;
877 throw new TypeLoadException(String.Format(
"Type '{0}' not found in assembly '{1}'", fullName, module.Assembly.FullName));
882 if (resolveMissingMembers)
888 if (ResolvedMissingMember !=
null)
889 ResolvedMissingMember(requester, method);
894 throw new MissingMethodException(declaringType.ToString(), name);
899 if (resolveMissingMembers)
902 if (ResolvedMissingMember !=
null)
903 ResolvedMissingMember(requester, field);
908 throw new MissingFieldException(declaringType.ToString(), name);
915 if (resolveMissingMembers || declaringType.__IsMissing)
918 if (ResolvedMissingMember !=
null && !declaringType.__IsMissing)
919 ResolvedMissingMember(requester, property);
924 throw new System.MissingMemberException(declaringType.ToString(), name);
927 internal Type CanonicalizeType(
Type type)
929 if (!canonicalizedTypes.TryGetValue(type, out var canon))
932 canonicalizedTypes.Add(canon, canon);
938 public Type MakeFunctionPointer(__StandAloneMethodSig sig)
943 public __StandAloneMethodSig MakeStandAloneMethodSig(
System.
Runtime.InteropServices.CallingConvention callingConvention,
Type returnType, CustomModifiers returnTypeCustomModifiers,
Type[] parameterTypes, CustomModifiers[] parameterTypeCustomModifiers)
945 return new __StandAloneMethodSig(
true, callingConvention, 0, returnType ?? this.System_Void,
Util.Copy(parameterTypes),
Type.EmptyTypes,
946 PackedCustomModifiers.CreateFromExternal(returnTypeCustomModifiers, parameterTypeCustomModifiers,
Util.NullSafeLength(parameterTypes)));
949 public __StandAloneMethodSig MakeStandAloneMethodSig(CallingConventions callingConvention,
Type returnType, CustomModifiers returnTypeCustomModifiers,
Type[] parameterTypes,
Type[] optionalParameterTypes, CustomModifiers[] parameterTypeCustomModifiers)
951 return new __StandAloneMethodSig(
false, 0, callingConvention, returnType ?? this.System_Void,
Util.Copy(parameterTypes),
Util.Copy(optionalParameterTypes),
952 PackedCustomModifiers.CreateFromExternal(returnTypeCustomModifiers, parameterTypeCustomModifiers,
Util.NullSafeLength(parameterTypes) +
Util.NullSafeLength(optionalParameterTypes)));
955 public event ResolvedMissingMemberHandler ResolvedMissingMember;
957 public event Predicate<Type> MissingTypeIsValueType
959 add => missingTypeIsValueType = missingTypeIsValueType ==
null ? value :
throw new InvalidOperationException(
"Only a single MissingTypeIsValueType handler can be registered.");
962 if (value.Equals(missingTypeIsValueType))
963 missingTypeIsValueType =
null;
967 internal bool ResolveMissingTypeIsValueType(
MissingType missingType)
969 if (missingTypeIsValueType !=
null)
970 return missingTypeIsValueType(missingType);
972 throw new MissingMemberException(missingType);
975 internal bool ReturnPseudoCustomAttributes => returnPseudoCustomAttributes;
977 internal bool AutomaticallyProvideDefaultConstructor => automaticallyProvideDefaultConstructor;
979 internal bool MetadataOnly => (options & UniverseOptions.MetadataOnly) != 0;
981 internal bool WindowsRuntimeProjection => (options & UniverseOptions.DisableWindowsRuntimeProjection) == 0;
983 internal bool DecodeVersionInfoAttributeBlobs => (options & UniverseOptions.DecodeVersionInfoAttributeBlobs) != 0;
988 internal bool Deterministic => (options & UniverseOptions.DeterministicOutput) != 0;
993 internal HashAlgorithmName PdbChecksumAlgorithm => pdbChecksumAlgorithm;
IKVM.Reflection.Module Module
IKVM.Reflection.Type Type
IKVM.Reflection.Assembly Assembly
IKVM.Reflection.AssemblyName AssemblyName
IKVM.Reflection.FieldInfo FieldInfo
IKVM.Reflection.PropertyInfo PropertyInfo
IKVM.Reflection.MethodInfo MethodInfo
IKVM.Reflection.MethodBase MethodBase
Represents a method signature from IL metadadata.
override string ToString()