Groups | Blog | Home
all groups > dotnet windows forms designtime > october 2004 >

dotnet windows forms designtime : Problems with codedom serialization



Frank Hileman
10/16/2004 3:13:09 PM
DesignerSerializationVisibility is to specify if something should be
serialized at all, or if set to "Content", it means you should serialize the
things "inside" and not the thing itself. For example, the Controls
collection would be Content, as the collection itself is not serialized, but
the objects in it are.

ShouldSerialize (and Reset if you want to be friendly) are needed if the
"default" value cannot be expressed as a constant, either because it is an
object reference, or because it is determined dynamically.

There are articles in the MSDN discussing these.

Regards,
Frank Hileman

check out VG.net: www.vgdotnet.com
Animated vector graphics system
Integrated Visual Studio .NET graphics editor

[quoted text, click to view]

Andrea Gelati \(Protocube Team\)
10/16/2004 5:23:38 PM
Hi,

Actually have try to redefine the BackColor and ForeColor of the Control
class using the key 'new' with the DesignerSerializationVisibility.Content
attrubute. Well, the desinger not serialize this property.

Any ideas about?

Thank's in advance!.

-- Andrea Gelati
Protocube Team
www.protocube.com

Mick Doherty
10/16/2004 6:05:55 PM
\\\
private Color faceColor = Color.Empty;

[AmbientValue(typeof(Color),"Empty")]
public new Color BackColor
{
get
{
if (faceColor == Color.Empty && Parent != null)
return Parent.BackColor;
return faceColor;
}
set
{
faceColor = value;
this.Invalidate();
}
}
private bool ShouldSerializeBackColor()
{
return faceColor != Color.Empty;
}
private new void ResetBackColor()
{
faceColor = Color.Empty;
}
///

The above property serializes just fine without the
DesignerSerializationVisibility attribute.

base.BackColor and this.BackColor will return different results, so just
watch which one you ask for.

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html


[quoted text, click to view]


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.775 / Virus Database: 522 - Release Date: 08/10/2004

Andrea Gelati \(Protocube Team\)
10/16/2004 7:22:40 PM
Hi Mick,

Well, now run as well but for me is clear why.

Is possible explains me and at the group when is possible use the
DesignerSerializationVisibility and the SouldSerializeMethod ways?

I think the second the have necessity to redefine a base.Method?

Thank's in advance,

-- Andrea Gelati


"Mick Doherty"
<EXCHANGE#WITH@AND.REMOVE.SQUAREBRACKETS.[mdaudi100#ntlworld.com]> wrote in
message news:O2MlqJ6sEHA.2956@TK2MSFTNGP12.phx.gbl...
[quoted text, click to view]

Mick Doherty
10/16/2004 11:48:31 PM
We used the ShouldSerialize method because we wanted Ambient property
behaviour. In other words we want our BackColor property to return the
parent controls BackColor if we do not specify a color. We supplied the
AmbientValue attribute to the property for proper behaviour in the IDE.
Comment out the attribute, rebuild the control and change the property in
the IDE. You should visually see the result in your control. Now right click
on the property and choose Reset. The property will reset to the parent's
BackColor, but you will see no Visual effect of this in your control until
it is invalidated. Now uncomment the attribute and repeat these same steps
and you should see the Control is invalidated upon Reset.

In the following example we do not use the ShouldSerialize method but the
property is serialized if it is not at it's default value of
SystemColors.Control. If we do not supply the DefaultValue attribute then
the property will always be serialized.
Also note that this property does not follow the Parents Background property
since we have used a static value to define the default value.

\\\
private Color faceColor = SystemColors.Control;

[DefaultValue(typeof(Color),"Control")]
public new Color BackColor
{
get
{
return faceColor;
}
set
{
faceColor = value;
this.Invalidate();
}
}
///

Use the DesignerSerializationVisibility attribute to get the code generator
to serialize your property if it returns a type that does not have a
serializer.

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html


[quoted text, click to view]


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.775 / Virus Database: 522 - Release Date: 08/10/2004

AddThis Social Bookmark Button