Re: Using assemlby without depending on it by ArthurM
ArthurM
Wed May 11 10:58:01 CDT 2005
You would probably have to deal with Assembly load ether way when you
consider security. You could abstract it to a function, however, i suspect it
would not change the overall requirement to load the assembly (i.e. load
security certificates for it as well).
"mdb" wrote:
> "Bill" <msgdev@hotmail.com> wrote in
> news:eLOm6zjVFHA.2196@TK2MSFTNGP09.phx.gbl:
>
> > I was going to try using the Assembly a = Assembly.Load() but there
> > are a lot or properties and method that I need to use. It would take
> > forever if I manually called GetMethd(), GetProperty(), and Invoke for
> > every value I needed.
> >
>
> I don't think there's a way to simply call the functions directly, but
> there are a couple of ways you could solve this... you should be able to
> write a couple of functions to make it easier. For example, write one
> that starts like this:
>
> private object ExecAssemblyMethod(
> string methodName,
> params object[] methodParams)
> {
> ...
> // Find the function, Invoke it with methodParams
> // and return the result of Invoke
> }
>
> You could also write a wrapper class that matches the functions you want
> to call from the lib so that you can use the Intellisense in the editor.
> You would need to wrap every function that you're going to use, but once
> it's done you wouldn't have to mess with it. For example:
>
> private class LibWrapper
> {
> private bool bLibInitialized = false;
> private void Init3rdPartyLib() { ... Assembly.Load(...); ... }
> private object ExecAssemblyMethod(...) { ... } // from above
>
> private int ThirdPartyFunc(int a, string b)
> {
> if (!bLibInitialized) throw new Exception(...);
> return (int)ExecAssemblyMethod("ThirdPartyFunc", a, b);
> }
> }
>
> Having said this, what are you going to do if the lib isn't available on
> a particular system? The whole idea doesn't really make sense. But if
> you use a wrapper lib you could return default values or throw exceptions
> or something like that.
>
> -mdb
>