samedi 26 mars 2016

Selected Item Is Null

I am making a plugin system for my application and I am using reflection to add controls to a TabPage. For the controls that have a SelectedItem attribute it is always null even if an item is selected.

Here is the code I am using to load the plugins:

                Assembly assembly = Assembly.LoadFrom(file);
                Type[] types = assembly.GetTypes();
                Boolean ContainsIPlugin = false;
                String pluginname = file.Substring(file.LastIndexOf("\\") + 1);
                pluginname = pluginname.Substring(0, pluginname.LastIndexOf("."));
                foreach (Type type in types)
                {
                    // if we found our interface, verify attributes
                    if (type.GetInterface("IPlugin") != null)
                    {
                        ContainsIPlugin = true;

                        MethodInfo methodInfo = type.GetMethod("LoadPlugin");

                        // create the plugin using reflection
                        IPlugin pluginobj = Activator.CreateInstance(type) as IPlugin;

                        var result = methodInfo.Invoke(pluginobj, null);

                        // get custom attributes from plugin
                        UTCPlugin newplugin = new UTCPlugin(pluginobj);
                        newplugin.name = pluginobj.PluginDisplayName;
                        newplugin.version = pluginobj.PluginVersion;
                        newplugin.description = pluginobj.PluginDescription;
                        newplugin.author = pluginobj.PluginAuthor;

                        loadedPlugins.Add(newplugin);
                    }
                }

If I could get some help fixing this that would be a big help. Thanks!





Aucun commentaire:

Enregistrer un commentaire