C# add event handler to class that has been loaded from an assembly at run time -


as part of evaluating 3rd party dll called "gembox.document", want able run assembly during run time. in order run in trial mode, need use this:

componentinfo.freelimitreached +=      (sender, e) => e.freelimitreachedaction = freelimitreachedaction.continueastrial; 

this standard way if directly reference dll in application. however, want able calling dll @ runtime. correct syntax this?

edit: componentinfo public static class of gembox.document

for future reference, here how can load gembox.document assembly @ run-time , set in trial mode through reflection:

using system; using system.reflection;  class program {     // load gembox.document assembly.     static assembly gemboxassembly = assembly.loadfrom(@"c:\gembox.document.dll");      // create method handling freelimitreached event.     static void handlefreelimit(object sender, eventargs e)     {         // call: e.freelimitreachedaction = freelimitreachedaction.continueastrial         dynamic freelimitargs = e;         freelimitargs.freelimitreachedaction =             (dynamic)enum.parse(                 gemboxassembly.gettype("gembox.document.freelimitreachedaction"),                 "continueastrial");     }      static void main(string[] args)     {         // call: componentinfo.setlicense("free-limited-key")         type componentinfo = gemboxassembly.gettype("gembox.document.componentinfo");         componentinfo.getmethod("setlicense", bindingflags.public | bindingflags.static)             .invoke(null, new object[] {"free-limited-key"});          // handlefreelimit methodinfo.         methodinfo handlefreelimitmethod =             typeof(program).getmethod("handlefreelimit",                 bindingflags.nonpublic | bindingflags.static);          // call: componentinfo.freelimitreached += handlefreelimit         eventinfo freelimitreached = componentinfo.getevent("freelimitreached");         freelimitreached.addeventhandler(null,             delegate.createdelegate(freelimitreached.eventhandlertype,                 handlefreelimitmethod));          // call: documentmodel document = documentmodel.load(@"c:\sample.docx")         type documentmodel = gemboxassembly.gettype("gembox.document.documentmodel");         dynamic document = documentmodel.getmethod("load", new type[]{ typeof(string)})             .invoke(null, new object[] { @"c:\sample.docx" });          // todo: use "document" object needed ...         document.save(@"c:\sample.pdf");     } } 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -