midora Posted March 30, 2013 Share Posted March 30, 2013 I derived a dialog from EffectConfigDialog. The constructor of the dialog gets a description list of controls to create. The list contains the default values of the controls too. What's the right way to access the list in CreateInitialToken() to set the values of the new token to defaults? The problem is that the base class constructor of the dialog seems to call CreateInitialToken() to request the new token. But because this constructor will be executed before I can store the list in the new dialog instance , I don't know how to solve this issue. OK, temporary I'm using a static variable in the dialog class to provide the list to CreateInitialToken(), but this is just to allow me to continue coding... Quote Link to comment Share on other sites More sharing options...
Rick Brewster Posted April 4, 2013 Share Posted April 4, 2013 There's a way to get around this although it's a little wonky. The trick is to use the same pattern that the internal effects use (rather, PropertyBasedEffect) via a separate non-public (internal) constructor. The constructor's parameter isn't interesting other than that it lets you call another method before the base constructor gets called. You can then set the value of a private field and then use it in CreateInitialToken. You'll need to create an additional base class: class DescriptionListOfControlsToCreate { ... } class EffectConfigDialogTrampoline : EffectConfigDialog { protected EffectConfigDialogTrampoline(object context) : base() { // We don't actually do anything with context }} class MyEffectConfigDialog : EffectConfigDialogTrampoline{ private DescriptionListOfControlsToCreate info; private object InitializeStuff(DescriptionListOfControlsToCreate info) { this.info = info; return null; } public MyEffectConfigDialog(DescriptionListOfControlsToCreate info) : base(InitializeStuff(info)) { } protected overried CreateInitialToken() { ... use this.info to do whatever you need }} Quote The Paint.NET Blog: https://blog.getpaint.net/ Donations are always appreciated! https://www.getpaint.net/donate.html Link to comment Share on other sites More sharing options...
Rick Brewster Posted April 4, 2013 Share Posted April 4, 2013 On second thought, that won't work, I think -- I don't think it'll let you call an instance method (InitializeStuff) before the body of your constructor. However, it might give you a kickstart toward finding something that will work? Quote The Paint.NET Blog: https://blog.getpaint.net/ Donations are always appreciated! https://www.getpaint.net/donate.html Link to comment Share on other sites More sharing options...
midora Posted April 8, 2013 Author Share Posted April 8, 2013 Thanks taking the time looking in this issue. It drives me crazy ;-) Nothing is ready during CreateInitialToken. Even the Effect Property of the ConfigDialog is not set at this time. Or the service to access the userdata path. Means PropertyBasedEffect can use an other constructor in the assembly but it is internal and can not be used from dlls? Because I would expect that the PropertyBasedEffect has the same issue to access the list of properties. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.