问题
I am trying to convert Java libs to c# libs. I am stuck at a place and could not find any solution via googling. The issue is in c# Class Lib i want to write assembly load/init event handler, is it possible as in Java it seems is? In java the code is.
public class abc implements ServletContextListener {
public void contextInitialized(ServletContextEvent event) {
//do something
}
public void contextDestroyed(ServletContextEvent event) {
//do something
}
}
what would be its equivalent in c#?
回答1:
There is an AssemblyLoad event in the AppDomain class that may be what you are looking for:
private void SomeMethod() {
AppDomain.CurrentDomain.AssemblyLoad += new AssemblyLoadEventHandler(CurrentDomain_AssemblyLoad);
}
void CurrentDomain_AssemblyLoad(object sender, AssemblyLoadEventArgs args) {
// Code to initialize here...
}
来源:https://stackoverflow.com/questions/4020178/how-to-write-class-libs-assembly-load-init-event-handler