c# - Custom Control in VS Designer: Avoid serialization of Collection properties -
i made new winforms control
public class jwgraph inherits control
this control has bindinglists(of foo)
in them. in order avoid other visual studio errors in regards serialization (error messages) added serializable
attribute foo
, other tags bindinglist(of foo)
.
example:
foo declaration
<serializable> _ public class freemarker
bindinglist(of foo) declaration:
<system.componentmodel.browsable(false)> <editorbrowsable(editorbrowsablestate.never)> <system.componentmodel.designerserializationvisibility(system.componentmodel.designerserializationvisibility.hidden)> public withevents freemarkers bindinglist(of freemarker)
when use control, visual studio adds base64 data ressources form's resx file , lines like
me.jwgraph1.freemarkers = ctype(resources.getobject("jwgraph1.freemarkers"), system.componentmodel.bindinglist(of jwtoollib.jwgraph.freemarker))
to designer. problem is, can't change in control's code after point (or changing assembly) in way, because deserialization fail , have go great lengths running again @ all.
many controls use collections. can't seem find difference between implementations (i tried looking @ basic controls in reflector) , mine, , yet collections not show in designer in such way.
so how can prevent collections being generated binary ressources @ design time? initialized in control's constructor.
my code in vb.net answers in c# welcome.
like always, gray hair 3 hours straight, decide ask, promptly find solution:
as described here http://msdn.microsoft.com/en-us/library/53b8022e%28v=vs.100%29.aspx can add shouldserialize[...]
functions code prevent specific fields being serialized. guess designer evaluates these functions , decides do.
to keep example above:
in addition
<system.componentmodel.browsable(false)> <editorbrowsable(editorbrowsablestate.never)> <system.componentmodel.designerserializationvisibility(system.componentmodel.designerserializationvisibility.hidden)> public withevents freemarkers bindinglist(of freemarker)
add 2 functions class:
public function shouldserializefreemarkers() boolean return false end function public sub resetfreemarkers() series = nothing end sub
and lo , behold: no more design time serialization.
Comments
Post a Comment