It don't sound like something that should be possible, but I'd like to ask prior to writing it off.
I am writing an app with a plugin system, I would like to get the properties contained inside the plugin class prior to initializing or constructing it
Interface:
public interface IMPlugin
{
string PluginName { get; }
string PluginSafeName { get; }
string PluginDescription { get; }
Version PluginVersion { get; }
string PluginAuthorName { get; }
[DefaultValue(null)]
string PluginAuthorEmail { get; }
[DefaultValue(null)]
string PluginAuthorURL { get; }
[DefaultValue(false)]
bool PluginActive { get; set; }
/// <summary>
/// Plugin ID issued by InputMapper. Used for updates. </summary>
int PluginID { get; }
}
Plugin:
public class InputMonitor : IMPlugin,ApplicationPlugin
{
public string PluginName { get { return "My Plugin"; } }
public string PluginSafeName { get { return "MyPlugin"; } }
public string PluginDescription { get { return "My Plugin."; } }
public Version PluginVersion { get { return new Version("0.1.0.0"); } }
public string PluginAuthorName { get { return "John Doe"; } }
public string PluginAuthorEmail { get { return "foo@bar.com"; } }
public string PluginAuthorURL { get { return ""; } }
public int PluginID { get { return 0; } }
public bool PluginActive { get; set; }
public InputMonitor()
{
}
}
My issue is I want my application to be able to retrieve the plugin info prior to initializing it so users can activate and deactivate plugins at will but the details of the plugin still be visible in a plugin browser. But I don't want to have to rely on the plugin developers to not do anything in their constructor and only put their code in other interfaced methods.
Can a object be initialized and forcibly have its constructor ignored, or is there something to disallow constructors all together?
It sounds like your plugins should be configured via attributes rather than via exposing properties:
[Plugin(Name = "My Plugin", SafeName = "MyPlugin" ...)]
public class InputMonitor
You can access the attributes via reflection without creating an instance of the class.
After all, this is metadata about the type - not information about any one instance of the type.
See more on this question at Stackoverflow