ModuleResolveEventHandler 委托
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示将要处理 Assembly 的 ModuleResolve 事件的方法。
public delegate System::Reflection::Module ^ ModuleResolveEventHandler(System::Object ^ sender, ResolveEventArgs ^ e);
public delegate System.Reflection.Module ModuleResolveEventHandler(object sender, ResolveEventArgs e);
[System.Serializable]
public delegate System.Reflection.Module ModuleResolveEventHandler(object sender, ResolveEventArgs e);
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public delegate System.Reflection.Module ModuleResolveEventHandler(object sender, ResolveEventArgs e);
type ModuleResolveEventHandler = delegate of obj * ResolveEventArgs -> Module
[<System.Serializable>]
type ModuleResolveEventHandler = delegate of obj * ResolveEventArgs -> Module
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type ModuleResolveEventHandler = delegate of obj * ResolveEventArgs -> Module
Public Delegate Function ModuleResolveEventHandler(sender As Object, e As ResolveEventArgs) As Module
- sender
- Object
曾作为事件源的程序集。
由描述事件的对象提供的参数。
满足请求的模块。
- 属性
以下示例演示调用事件处理程序的执行序列。 在此示例中,Server1 是 MySample 类的外部模块。
using System;
using System.IO;
using System.Reflection;
class MySample
{
public static int Main(String[] args)
{
Assembly asm1 = typeof(MySample).Assembly;
asm1.ModuleResolve += new ModuleResolveEventHandler(evModuleResolve);
Console.WriteLine("Calling MySample.Test...");
Test();
return 0;
}
private static Module evModuleResolve(object sender, ResolveEventArgs e)
{
Console.WriteLine();
Console.WriteLine("******************************************************");
Console.WriteLine("* MySample.evModuleResolve() in module: {0:s} *",
Type.GetType("MySample").Module.ScopeName);
Console.WriteLine("******************************************************");
FileStream fs = File.Open("subfolder\\Server1.netmodule", FileMode.Open);
long len = fs.Length;
byte[] rgFileBytes = new byte[len];
fs.Read(rgFileBytes, 0, (int)len);
Assembly a = typeof(MySample).Assembly;
Module m = a.LoadModule("Server1.netmodule", rgFileBytes);
return m;
}
private static void Test()
{
Console.WriteLine("Instantiating Server1...");
Server1 s = new Server1();
Console.WriteLine("Calling Server1.trivial...");
s.trivial();
}
}
// Server1 module
using System;
using System.Reflection;
public class Server1 : MarshalByRefObject
{
public int trivial()
{
Console.WriteLine();
Console.WriteLine("******************************************************");
Console.WriteLine("* Server1.trivial() in module: {0:s} *", this.GetType().Module.ScopeName);
Console.WriteLine("******************************************************");
Console.WriteLine("Returning from Server1.trivial...");
return 1;
}
}
编译并运行示例:
使用以下命令编译 Server1:
csc /out:subfolder\Server1.netmodule /t:module Server1.cs
使用以下命令编译 MySample:
csc /out:MySample.exe /t:exe /addmodule:subfolder\Server1.netmodule MySample.cs
运行 MySample.exe。
备注
模块文件 Server1.netmodule 必须位于名为“subfolder”的子目录中,此示例才能正常工作。
如果公共语言运行时类加载程序无法通过正常方式解析对程序集内部模块的引用,则会引发此事件。 此委托的事件处理程序必须查找并返回满足请求的模块。
Get |
获取指示指定委托表示的方法的对象。 |
产品 | 版本 |
---|---|
.NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |