i have winform-usercontrol generic type control. create instance, changed designer code:
public class timebarform<t> : t : timebarpanel { protected void initializecomponent() { // ... this.m_timebarpanel = (t)activator.createinstance(typeof(t)); // ... } }
this works fine @ compile time on design time it's broken. on timebarform:
failed parse method 'initializecomponent'. parser reported following error 'type parameters not suppported parameter name: typesymbol'. please in task list potential errors.
the derived classes show default designer empty user control.
i tried pass type in constructor vs complains should not touch autogenerated code (it dosn't if-conditions). want generic usercontrol can decide specialization of abstract class/control in derived type , should still able use designer in base class. i'm open other suggestions solve this might not best solution. i'm not used usercontrol-design.
vs 2015/ .net 4.6
i've done dirty workaround can use designer base , derived classes. removed generic , replaced activator-class call constructor. when i'm done designing base class coment line. derived classes call constructor pass instance:
public timebarform(timebarpanel timebarpanel) { this.m_timebarpanel = timebarpanel; initializecomponent(); }
to make designer derived classes happy, second constructor provides default instance:
public timebarform() { this.m_timebarpanel = new timebarpanel(); initializecomponent(); }
not pretty can live it.
Comments
Post a Comment