15.02.2015 Views

C# 4 and .NET 4

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

936 ❘ ChaPTer 33 mAnipulAtinG xml<br />

information that can be retrieved at runtime by the CLR (see Chapter 8, “Delegates, Lambdas, <strong>and</strong> Events,”<br />

for more details). In this case, the attributes describe how the object should be serialized:<br />

//class that will be serialized.<br />

//attributes determine how object is serialized<br />

[System.Xml.Serialization.XmlRootAttribute()]<br />

public class Product {<br />

private int prodId;<br />

private string prodName;<br />

private int suppId;<br />

private int catId;<br />

private string qtyPerUnit;<br />

private Decimal unitPrice;<br />

private short unitsInStock;<br />

private short unitsOnOrder;<br />

private short reorderLvl;<br />

private bool discont;<br />

private int disc;<br />

//added the Discount attribute<br />

[XmlAttributeAttribute(AttributeName="Discount")]<br />

public int Discount {<br />

get {return disc;}<br />

set {disc=value;}<br />

}<br />

[XmlElementAttribute()]<br />

public int ProductID {<br />

get {return prodId;}<br />

set {prodId=value;}<br />

}<br />

[XmlElementAttribute()]<br />

public string ProductName {<br />

get {return prodName;}<br />

set {prodName=value;}<br />

}<br />

[XmlElementAttribute()]<br />

public int SupplierID {<br />

get {return suppId;}<br />

set {suppId=value;}<br />

}<br />

[XmlElementAttribute()]<br />

public int CategoryID {<br />

get {return catId;}<br />

set {catId=value;}<br />

}<br />

[XmlElementAttribute()]<br />

public string QuantityPerUnit {<br />

get {return qtyPerUnit;}<br />

set {qtyPerUnit=value;}<br />

}<br />

[XmlElementAttribute()]<br />

public Decimal UnitPrice {<br />

get {return unitPrice;}<br />

set {unitPrice=value;}<br />

}<br />

[XmlElementAttribute()]<br />

public short UnitsInStock {<br />

get {return unitsInStock;}<br />

set {unitsInStock=value;}<br />

}<br />

[XmlElementAttribute()]<br />

public short UnitsOnOrder {<br />

get {return unitsOnOrder;}<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!