newbie question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

What does the [XmlElement("Font")], [XmlIgnore()], [XmlElement("BackColor")]
mean in the following piece of code ? What are they used for ? Thanks for any
help or any URL that explains this.

public class EnoughPIData
{
private int m_digits;
private Color m_backColor;
private FontData m_font;

public EnoughPIData() {}

public EnoughPIData(int digits, Color backColor, Font font)
{
this.Digits = digits;
this.BackColor = backColor;
this.Font = font;
}

public int Digits
{
get { return this.m_digits; }
set { this.m_digits = value; }
}

[XmlIgnore()]
public Color BackColor
{
get { return this.m_backColor; }
set { this.m_backColor = value; }
}

[XmlElement("BackColor")]
public string HtmlBackColor
{
get { return ColorTranslator.ToHtml(this.m_backColor); }
set { this.m_backColor = ColorTranslator.FromHtml(value); }
}

[XmlIgnore()]
public Font Font
{
get
{
return new Font(this.FontData.Name, this.FontData.Size,
(FontStyle) this.FontData.Style);
}
set
{
this.FontData = new FontData();
this.FontData.Name = value.Name;
this.FontData.Size = value.Size;
this.FontData.Style = Convert.ToInt32(value.Style);
}
}

[XmlElement("Font")]
public FontData FontData
{
get { return this.m_font; }
set { this.m_font = value; }
}
}
 
Hi chris.hainlen,

In short, the XmlElementAttribute instructs the runtime to generate an XML
element named "Font" for the property "FontData", "BackColor" for the
property "HtmlBackColor" and NOT to generate any XML for the property
"BackColor" when performing serialization.

Raymond
 
Back
Top