VS2010 extension, OptionPage, readout values
I'm currently writing an editor margin using the new VSX MEF extension framework. I didn't found a counterpart for the VSPackage-OptionPage stuff and I'm therefore using the old framework for the settings.
Now I face the problem to readout the settings values from within a MEF component. I can't call GetDialogPage() from there. Is it a good idea to have code like this:
public static MyPackage Instance;
public MyPackage () { Instance = this; } // Hopefully called only once?
public bool MyBoolOption { get { var opts = GetDialogPage(...) as ...; return opts.MyBoolOption; } }
I am not sure if this is "clean" code.
Even more pr开发者_如何学Pythonoblematic is to inform my MEF components that something has changed. E.g. what to do in OnApply() to inform a MEF component "Hey, it's time to update because XYZ has changed!".
How to do that in a clean way?
Best regards, D.R.
You can put [Export]
attribute on your package class (MyPackage), and then import it in your MEF component using [Import]:
[Export]
public class MyPackage : Package
{
}
[Export]
public class EditorExtension
{
[Import]
private MyPackage package = null;
}
You can also have events on your package when properties change or OnApply is called.
精彩评论