Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Problems with dynamically loaded class
Message
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01335836
Message ID:
01335973
Views:
13
>>>I have created an AddIn class that holds the addin object and additional properties. Each addin will then be instantiated into the AddIn class which is then stored in a collection. Most of this is already in place and working.
>>>
>>>I wrote the following code which dynamically loads a class from an external DLL. The GetModule method works fine and creates and stores an instance of the desired class.
>>
>>>The problem is that I need to be able to set properties on the addin, and I'm unsure how to do all this. In the code below, the line where the database is being set won't compile.
>>
>>What type is the oClass property? Object? You will need to cast oClass to the correct type or interface before accessing it's properties (so the compiler knows what type/interface is available).
>
>But how do I specifiy what the correct type is? Thee class is in a different assemby.

To really make this work you need to implement a common interface between all of the different types you're going to be loading. So if you have one property and one method you always need to call to "kick off" things, you would define the interface type, then make sure you inherit it from it (and implement it) in all of your classes. Then set the type of oClass to that interface type. Now you should be able to access the one property and method from your code.
    public interface IAddIn
    {
        string sDatabase { get; set; }
        void Go();
    }
    public class Class1 : IAddIn
    {
        public string sDatabase { get; set; }
        public void Go()
        {
        }
    }
-Paul

RCS Solutions, Inc.
Blog
Twitter
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform