Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Problems with dynamically loaded class
Message
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01335836
Message ID:
01335838
Vues:
6
>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.
>

Is sDatabase a public property of this class? What exactly do you know about oClass and which public methods/properties does it expose?

>
>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);
>                }
>            }
>
>        }
>    }
>}
>
>
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform