Click here to Skip to main content
15,900,683 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to prevent multiple button clicks Pin
MichCl28-Nov-12 8:31
MichCl28-Nov-12 8:31 
AnswerRe: How to prevent multiple button clicks Pin
lukeer27-Nov-12 20:17
lukeer27-Nov-12 20:17 
GeneralRe: How to prevent multiple button clicks Pin
MichCl28-Nov-12 7:40
MichCl28-Nov-12 7:40 
GeneralRe: How to prevent multiple button clicks Pin
MichCl28-Nov-12 7:41
MichCl28-Nov-12 7:41 
QuestionTop books for learning C# (Complete novice) for thermodynamic mathematical modelling Pin
Mahdi Kapateh27-Nov-12 8:05
Mahdi Kapateh27-Nov-12 8:05 
AnswerRe: Top books for learning C# (Complete novice) for thermodynamic mathematical modelling Pin
Richard MacCutchan27-Nov-12 9:53
mveRichard MacCutchan27-Nov-12 9:53 
AnswerRe: Top books for learning C# (Complete novice) for thermodynamic mathematical modelling Pin
Nelek27-Nov-12 12:37
protectorNelek27-Nov-12 12:37 
GeneralRe: Top books for learning C# (Complete novice) for thermodynamic mathematical modelling Pin
Richard MacCutchan27-Nov-12 23:47
mveRichard MacCutchan27-Nov-12 23:47 
GeneralRe: Top books for learning C# (Complete novice) for thermodynamic mathematical modelling Pin
Nelek28-Nov-12 11:47
protectorNelek28-Nov-12 11:47 
AnswerRe: Top books for learning C# (Complete novice) for thermodynamic mathematical modelling Pin
Matt T Heffron27-Nov-12 12:59
professionalMatt T Heffron27-Nov-12 12:59 
GeneralRe: Top books for learning C# (Complete novice) for thermodynamic mathematical modelling Pin
Mahdi Kapateh28-Nov-12 3:04
Mahdi Kapateh28-Nov-12 3:04 
QuestionDynamically loading a plug-in assembly by interface Pin
MJL Rademakers27-Nov-12 4:07
MJL Rademakers27-Nov-12 4:07 
AnswerRe: Dynamically loading a plug-in assembly by interface Pin
Alan N27-Nov-12 4:27
Alan N27-Nov-12 4:27 
GeneralRe: Dynamically loading a plug-in assembly by interface Pin
MJL Rademakers27-Nov-12 4:41
MJL Rademakers27-Nov-12 4:41 
AnswerRe: Dynamically loading a plug-in assembly by interface Pin
Pete O'Hanlon27-Nov-12 4:30
mvePete O'Hanlon27-Nov-12 4:30 
GeneralRe: Dynamically loading a plug-in assembly by interface Pin
MJL Rademakers27-Nov-12 4:45
MJL Rademakers27-Nov-12 4:45 
AnswerRe: Dynamically loading a plug-in assembly by interface Pin
PIEBALDconsult27-Nov-12 8:17
mvePIEBALDconsult27-Nov-12 8:17 
GeneralRe: Dynamically loading a plug-in assembly by interface Pin
BobJanova28-Nov-12 23:49
BobJanova28-Nov-12 23:49 
Nothing wrong with Activator.CreateInstance if you specify that plugins should provide a parameterless constructor. I often use that and specify an Init method on the interface.

Here's what I use to load plugins in my game lobby client[^]:
107      public class PluginLoader : MarshalByRefObject {
108          Assembly a;
109          public PluginLoader(){
110              System.Runtime.Remoting.Lifetime.LifetimeServices.LeaseTime = new TimeSpan(1000, 0, 0, 0);
111          }
112          
113          public void SetAssembly(string filename){
114              a = Assembly.LoadFrom(filename);
115              if(a == null) throw new PluginLoadException("Assembly "+filename+" not found or not valid");
116          }
117          
118          public Type GetFirstType(Assembly a, Type type){
119              foreach(Module mod in a.GetLoadedModules()){
120                  foreach(Type ty in mod.GetTypes()){
121                      foreach(Type intf in ty.GetInterfaces()){
122                          if(intf == type){
123                              return ty;
124                          }
125                      }
126                  }
127              }
128              return null;
129          }
130          
131          public IGameType GetClientsideInfo(){
132              Type ty = GetFirstType(a, typeof(IGameType)); 
133              if(ty == null) return null;
134              return (IGameType)a.CreateInstance(ty.FullName);
135          }
136          
137          public static PluginLoader Make(PluginInfo pi){
138              AppDomainSetup setup = new AppDomainSetup();
139              setup.ApplicationName = "Plugins";
140              setup.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory;
141              pi.domain  = AppDomain.CreateDomain("plugin", null, setup);
142              pi.domain.DomainUnload += new EventHandler(DomainUnload);
143              PluginLoader loader = (PluginLoader)pi.domain.CreateInstanceAndUnwrap(Assembly.GetExecutingAssembly().FullName, "RedCorona.GameClient.PluginLoader");
144              //loader.Initialise();
145              return loader;
146          }
147          
148          public static void DomainUnload(object sender, EventArgs ea){
149              Console.WriteLine("Plugin domain "+sender+" unloaded!");
150          }
151          
152      }


used like

46          public static IGameType LoadContent(String filename){
60              PluginInfo pi = new PluginInfo();
61              PluginLoader loader = PluginLoader.Make(pi);
62              loader.SetAssembly(filename);
63              return loader.GetClientsideInfo();
64          }

GeneralRe: Dynamically loading a plug-in assembly by interface Pin
PIEBALDconsult29-Nov-12 2:41
mvePIEBALDconsult29-Nov-12 2:41 
GeneralRe: Dynamically loading a plug-in assembly by interface Pin
BobJanova29-Nov-12 3:12
BobJanova29-Nov-12 3:12 
GeneralRe: Dynamically loading a plug-in assembly by interface Pin
PIEBALDconsult29-Nov-12 5:58
mvePIEBALDconsult29-Nov-12 5:58 
Questionhandle script error on virtual machine Pin
belea1727-Nov-12 3:35
belea1727-Nov-12 3:35 
AnswerRe: handle script error on virtual machine Pin
Richard MacCutchan27-Nov-12 4:29
mveRichard MacCutchan27-Nov-12 4:29 
GeneralRe: handle script error on virtual machine Pin
belea1727-Nov-12 9:27
belea1727-Nov-12 9:27 
AnswerRe: handle script error on virtual machine Pin
Eddy Vluggen27-Nov-12 13:49
professionalEddy Vluggen27-Nov-12 13:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.