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:
01335842
Views:
15
>Is sDatabase a public property of this class? What exactly do you know about oClass and which public methods/properties does it expose?

I wrote the class I'm trying to load. It's a test class. The sDatabase property is public.

The problem seems to be that at compile time the sDatabase property isnt' available.



>>What I'm trying to create add-ins for my product. The customer will purchase add-ins and the product will load them on startup.
>>Information about the addins is stored in an encrypted file, which the product will decrypt and parse.
>>
>>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.
>>
>

>
>>
>>using System;
>>using System.Collections.Generic;
>>using System.Linq;
>>using System.Text;
>>using System.Reflection;
>>
>>namespace Test3
>>{
>>    class Program
>>    {
>>        private object oClass = null;
>>        private string sFileName = @"d:\projects\test\test.dll";
>>
>>        static void Main(string[] args)
>>        {
>>            Program o = new Program();
>>            o.GetModule();
>>
>>            // This line won't compile
>>            o.oClass.sDatabase = "prod1";
>>        }
>>
>>        private void GetModule()
>>        {
>>            /* Load in the assembly. */
>>            Assembly moduleAssembly = Assembly.LoadFrom(sFileName);
>>
>>            /* Get the types of classes that are in this assembly.*/
>>            Type[] types = moduleAssembly.GetTypes();
>>
>>            /* Loop through the types in the assembly until we find
>>             * a class that implements a Module.*/
>>            foreach (Type type in types)
>>            {
>>                if (type.FullName.EndsWith(".MyClass"))
>>                {
>>                    /* Create a new instance of the 'Module'. */
>>                    oClass = Activator.CreateInstance(type);
>>                }
>>            }
>>
>>        }
>>    }
>>}
>>
>>
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform