Property with interface and generics
okay, i'm going try explain best possible.
first show code.
note: i'm manually typing in code! also ignore names of interfaces, i'm aware (i think) there interfaces named these. in code named different there lot of code.
public interface ibuttondesigner { color basecolor { get; set; } color bordercolor { get; set; } }
public interface ibuttonbase { ibuttondesigner normal { get; set; } ibuttondesigner clicked { get; set; } }
public class closebuttonnormal : ibuttondesigner { public color basecolor { get; set; } public color bordercolor { get; set; } }
public class closebuttonclicked : ibuttondesigner { public color basecolor { get; set; } public color bordercolor { get; set; } }
public class closebutton : ibuttonbase { public closebutton() { this.normal = new closebuttonnormal(); this.clicked = new closebuttonclicked(); } public ibuttondesigner normal { get; set; } public ibuttondesigner clicked { get; set; } }
okay, now... i know there lot of code missing make work way i'm explain, wanted keep simple.
this code used customcontrol form, of has work @ design time. i had working before used interface return type each button state (normal, clicked, etc... ) , working mean showed in propertygrid should, using interface, shows how it's supposed except children of closebutton class meaning no values set normal , clicked , type not set.
now i'm thinking because type before assigned of ibuttondesigner makes me believe should use generics after tinkering not able to.
all classes provided have attribute allows them used in propertygrid category or how every explain (location, size, point.. ) , first 1 (closebutton) works without problem, normal , clicked ones wont anymore. if take off interface on closebutton , replace normal , clicked return types types of assigned in constructor, works fine , dandy, other classes.
i hope able explain efficiently enough.
>>the color can't changed?
why?
take @ test follows.
first build component class has closebutton property
public partial class component1 : component { public component1() { initializecomponent(); } public component1(icontainer container) { container.add(this); initializecomponent(); } public closebutton closebut { get; set; } = new closebutton(); }
and. drag component1 form desginer...and propertygrid show follows
the closebut properpties changeable , expandable
if except.
decorate typeconverterattribute interface instead.
don't try hard,the best things come when least expect them to.
Visual Studio Languages , .NET Framework > Visual C#
Comments
Post a Comment