diff options
author | Ryan Lucia <rylucia@microsoft.com> | 2019-08-20 17:45:03 +0300 |
---|---|---|
committer | Alexander Köplinger <alex.koeplinger@outlook.com> | 2019-08-20 22:25:00 +0300 |
commit | 3b47d28e37d80d82e6496fbe59676078578dbaa8 (patch) | |
tree | 6163ca5b9b7968cf88cce7952e8e154208479112 /netcore/System.Private.CoreLib/shared/System/Runtime/Loader/AssemblyLoadContext.cs | |
parent | a147402d07c315a829ba7e37232366b4c735dbc4 (diff) |
Move AssemblyLoadContext VM-invoked static resolve methods to shared (#26248)
Shared between CoreCLR and Mono. Mono began using a copy of these methods with https://github.com/mono/mono/pull/16256/
Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
Diffstat (limited to 'netcore/System.Private.CoreLib/shared/System/Runtime/Loader/AssemblyLoadContext.cs')
-rw-r--r-- | netcore/System.Private.CoreLib/shared/System/Runtime/Loader/AssemblyLoadContext.cs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Loader/AssemblyLoadContext.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Loader/AssemblyLoadContext.cs index e7e928560e9..a2cc279c2d6 100644 --- a/netcore/System.Private.CoreLib/shared/System/Runtime/Loader/AssemblyLoadContext.cs +++ b/netcore/System.Private.CoreLib/shared/System/Runtime/Loader/AssemblyLoadContext.cs @@ -657,6 +657,48 @@ namespace System.Runtime.Loader return assembly; } + + // This method is called by the VM. + private static void OnAssemblyLoad(RuntimeAssembly assembly) + { + AssemblyLoad?.Invoke(AppDomain.CurrentDomain, new AssemblyLoadEventArgs(assembly)); + } + + // This method is called by the VM. + private static RuntimeAssembly? OnResourceResolve(RuntimeAssembly assembly, string resourceName) + { + return InvokeResolveEvent(ResourceResolve, assembly, resourceName); + } + + // This method is called by the VM + private static RuntimeAssembly? OnTypeResolve(RuntimeAssembly assembly, string typeName) + { + return InvokeResolveEvent(TypeResolve, assembly, typeName); + } + + // This method is called by the VM. + private static RuntimeAssembly? OnAssemblyResolve(RuntimeAssembly assembly, string assemblyFullName) + { + return InvokeResolveEvent(AssemblyResolve, assembly, assemblyFullName); + } + + private static RuntimeAssembly? InvokeResolveEvent(ResolveEventHandler? eventHandler, RuntimeAssembly assembly, string name) + { + if (eventHandler == null) + return null; + + var args = new ResolveEventArgs(name, assembly); + + foreach (ResolveEventHandler handler in eventHandler.GetInvocationList()) + { + Assembly? asm = handler(AppDomain.CurrentDomain, args); + RuntimeAssembly? ret = GetRuntimeAssembly(asm); + if (ret != null) + return ret; + } + + return null; + } #endif // !CORERT private Assembly? ResolveSatelliteAssembly(AssemblyName assemblyName) |