I have 3 Classes : Masina (Car), Destinatie (Destination) and MasinaDestinatie (CarDestination).
I need the third class to get the values of the car number _nr_masina and the destination _cod_dest through it's own constructor.
I need to make a constructor with parameters in the third class that stores the values of _nr_masina and _cod_dest.
Anyone know how can i do this exactly? I've tried making the private fields public and putting them as parameters but that doesn't work...
The classes:
namespace Problema_test
{
class Masina
{
private string _nr_masina = string.Empty;
private string _valoare = string.Empty;
private string _an_fabricatie = string.Empty;
public Masina(string nr_masina,string valoare, string an_fabricatie)
{
_nr_masina = nr_masina;
_valoare = valoare;
_an_fabricatie = an_fabricatie;
}
public string Numar
{
get { return _nr_masina; }
set { _nr_masina = value; }
}
public string Valoare
{
get { return _valoare; }
set { _valoare = value; }
}
public string Anul
{
get { return _an_fabricatie; }
set { _an_fabricatie = value; }
}
}
class Destinatie
{
private string _cod_destinatie = string.Empty;
private string _adresa = string.Empty;
public Destinatie(string cod_destinatie, string adresa)
{
_cod_destinatie = cod_destinatie;
_adresa = adresa;
}
public string CodDest
{
get { return _cod_destinatie; }
set { _cod_destinatie = value; }
}
public string Adresa
{
get { return _adresa; }
set { _adresa = value; }
}
}
class MasinaDestinatie
{
// how can i make this work?
public MasinaDestinatie(string numarMasina, string codDest)
{
}
}
}
You can store the values inside properties
class MasinaDestinatie
{
public string Numar {get;set;}
public string CodDest {get;set;}
public MasinaDestinatie(string numarMasina, string codDest)
{
Numar = numarMasina;
CodDest = codDest;
}
}
To use the class you have do something like this
var masina = new Masina("Dacia","2000","1992");
var destinatie = new Destinatie("123", "Romania");
var masinaDestinatie = new MasinaDestinatie(masina.Numar, destinatie.CodDest);
Solution 2: As #blas-soriano sugested you can store the reference of the objects (Masina, Destinatie), this way you won't have problems (i.e. CodDest exist only in MasinaDestinatie but not in Destinatie, and many others).
class MasinaDestinatie
{
private Masina _masina {get;set;}
private Destinatie _destinatie {get;set;}
public string Numar { get { return _masina.Numar; } }
public string CodDest { get { return _destinatie.CodDest; } }
public MasinaDestinatie(Masina masina, Destinatie destinatie)
{
_masina = masina;
_destinatie = destinatie;
}
}
To use the class you have do something like this
var masina = new Masina("Dacia","2000","1992");
var destinatie = new Destinatie("123", "Romania");
var masinaDestinatie = new MasinaDestinatie(masina, destinatie);
Related
I have a c# class, I am creating object to put data in class , some data i have no able to do, here is my code
InvoiceType oInvoiceType = new InvoiceType(); // my main object
// using object UBLVersionIDType
UBLVersionIDType oUBLVersionIDType = new UBLVersionIDType();
IdentifierType oIdentifierType = new IdentifierType();
oIdentifierType.Value = "UBL 2.1";
//oUBLVersionIDType.schemeID = oIdentifierType.schemeID;
oUBLVersionIDType.Value = oIdentifierType.Value;
// using object InvoiceTypeCodeType
InvoiceTypeCodeType oInvoiceTypeCode = new InvoiceTypeCodeType();
CodeType oCodeType = new CodeType();
oCodeType.Value = "01";
oInvoiceTypeCode.Value = oCodeType.Value;
// using Note
NoteType oNoteType = new NoteType();
oNoteType.Value = new
TextType oTextType = new TextType(); // this show error
oTextType.Value = "This is a Note 1"; // this show error
oNoteType.Value = oTextType.Value; // this show error
// asign main object
oInvoiceType.UBLVersionID = oUBLVersionIDType;
oInvoiceType.InvoiceTypeCode = oInvoiceTypeCode;
//oInvoiceType.Note = oNoteType; // this show error !!!!!!!!
Next you can see the class
public partial class InvoiceType
{
private UBLVersionIDType uBLVersionIDField;
private InvoiceTypeCodeType invoiceTypeCodeField;
private UBLExtensionType[] uBLExtensionsField;
private NoteType[] noteField;
public UBLVersionIDType UBLVersionID
{
get
{
return this.uBLVersionIDField;
}
set
{
this.uBLVersionIDField = value;
}
}
public InvoiceTypeCodeType InvoiceTypeCode
{
get
{
return this.invoiceTypeCodeField;
}
set
{
this.invoiceTypeCodeField = value;
}
}
public UBLExtensionType[] UBLExtensions
{
get
{
return this.uBLExtensionsField;
}
set
{
this.uBLExtensionsField = value;
}
}
public NoteType[] Note
{
get
{
return this.noteField;
}
set
{
this.noteField = value;
}
}
}
public partial class NoteType : TextType1
{
}
public partial class TextType1 : TextType
{
}
public partial class TextType
{
private string languageIDField;
private string languageLocaleIDField;
private string valueField;
public string languageID
{
get
{
return this.languageIDField;
}
set
{
this.languageIDField = value;
}
}
public string languageLocaleID
{
get
{
return this.languageLocaleIDField;
}
set
{
this.languageLocaleIDField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlTextAttribute()]
public string Value
{
get
{
return this.valueField;
}
set
{
this.valueField = value;
}
}
}
public partial class UBLExtensionType
{
private IDType idField;
private NameType1 nameField;
private System.Xml.XmlElement extensionContentField;
public IDType ID
{
get
{
return this.idField;
}
set
{
this.idField = value;
}
}
public NameType1 Name
{
get
{
return this.nameField;
}
set
{
this.nameField = value;
}
}
public System.Xml.XmlElement ExtensionContent
{
get
{
return this.extensionContentField;
}
set
{
this.extensionContentField = value;
}
}
}
The class "Invoice" has 4 fields to set data
private UBLVersionIDType uBLVersionIDField;
private InvoiceTypeCodeType invoiceTypeCodeField;
private UBLExtensionType[] uBLExtensionsField;
private NoteType[] noteField;
As you can see in the code, I set data to "uBLVersionID" and "InvoiceTypeCode", but I have not been able to assign data to notefield, and I don't know to set "uBLExtensionfield".
Does someone know how to do that?
Code below compiles with no errors. I added missing classes. The line with the ******* is causing issues.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
InvoiceType oInvoiceType = new InvoiceType(); // my main object
// using object UBLVersionIDType
UBLVersionIDType oUBLVersionIDType = new UBLVersionIDType();
IdentifierType oIdentifierType = new IdentifierType();
oIdentifierType.Value = "UBL 2.1";
//oUBLVersionIDType.schemeID = oIdentifierType.schemeID;
oUBLVersionIDType.Value = oIdentifierType.Value;
// using object InvoiceTypeCodeType
InvoiceTypeCodeType oInvoiceTypeCode = new InvoiceTypeCodeType();
CodeType oCodeType = new CodeType();
oCodeType.Value = "01";
oInvoiceTypeCode.Value = oCodeType.Value;
// using Note
NoteType oNoteType = new NoteType();
//oNoteType.Value = new ******************************************** bad
TextType oTextType = new TextType(); // this show error
oTextType.Value = "This is a Note 1"; // this show error
oNoteType.Value = oTextType.Value; // this show error
// asign main object
oInvoiceType.UBLVersionID = oUBLVersionIDType;
oInvoiceType.InvoiceTypeCode = oInvoiceTypeCode;
//oInvoiceType.Note = oNoteType; // this show error !!!!!!!!
}
}
public class CodeType
{
public string Value { get; set; }
}
public class IdentifierType
{
public string Value { get;set;}
}
public class UBLVersionIDType
{
public string Value { get; set; }
}
public class InvoiceTypeCodeType
{
public string Value { get; set; }
}
public partial class InvoiceType
{
private UBLVersionIDType uBLVersionIDField;
private InvoiceTypeCodeType invoiceTypeCodeField;
private UBLExtensionType[] uBLExtensionsField;
private NoteType[] noteField;
public UBLVersionIDType UBLVersionID
{
get
{
return this.uBLVersionIDField;
}
set
{
this.uBLVersionIDField = value;
}
}
public InvoiceTypeCodeType InvoiceTypeCode
{
get
{
return this.invoiceTypeCodeField;
}
set
{
this.invoiceTypeCodeField = value;
}
}
public UBLExtensionType[] UBLExtensions
{
get
{
return this.uBLExtensionsField;
}
set
{
this.uBLExtensionsField = value;
}
}
public NoteType[] Note
{
get
{
return this.noteField;
}
set
{
this.noteField = value;
}
}
}
public partial class NoteType : TextType1
{
}
public partial class TextType1 : TextType
{
}
public partial class TextType
{
private string languageIDField;
private string languageLocaleIDField;
private string valueField;
public string languageID
{
get
{
return this.languageIDField;
}
set
{
this.languageIDField = value;
}
}
public string languageLocaleID
{
get
{
return this.languageLocaleIDField;
}
set
{
this.languageLocaleIDField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlTextAttribute()]
public string Value
{
get
{
return this.valueField;
}
set
{
this.valueField = value;
}
}
}
public class IDType
{
}
public class NameType1
{
}
public partial class UBLExtensionType
{
private IDType idField;
private NameType1 nameField;
private System.Xml.XmlElement extensionContentField;
public IDType ID
{
get
{
return this.idField;
}
set
{
this.idField = value;
}
}
public NameType1 Name
{
get
{
return this.nameField;
}
set
{
this.nameField = value;
}
}
public System.Xml.XmlElement ExtensionContent
{
get
{
return this.extensionContentField;
}
set
{
this.extensionContentField = value;
}
}
}
}
I solved myself, This is the REAL answer and its working fine
NoteType[] arrayNote = new NoteType[3];
NoteType oObj1 = new NoteType();
TextType oTextType = new TextType();
oTextType.Value = "This is Note 1";
oObj1.Value = oTextType.Value;
arrayNote[0] = oObj1;
oObj1.Value = "This is Note 2";
arrayNote[1] = oObj1;
I think I'm getting stupid because I can't get my LINQ query to work as I expect. I have one class that has 3 relationships to other classes.
This is the main class
[Table(Name = "scanResult")]
public class SniffResult
{
public SniffResult()
{
}
public SniffResult(Address address)
{
this.address = address;
}
private int _pk_SniffResult;
[Column(IsPrimaryKey = true, IsDbGenerated = true, Storage = "_pk_SniffResult", Name ="pk_scanResult")]
public int pk_SniffResult { get { return _pk_SniffResult; } set { this._pk_SniffResult = value; } }
private int _fk_scan;
[Column(Storage = "_fk_scan", Name = "scan")]
public int fk_scan { get { return _fk_scan; } set { this._fk_scan = value; } }
private Scan _scan;
[Association(Storage = "_scan", IsForeignKey = true, ThisKey = "fk_scan", OtherKey = "pk_scan")]
public Scan scan { get { return _scan; } set { this._scan = value; } }
private int _fk_address;
[Column(Storage = "_fk_address", Name = "address")]
public int fk_adress { get { return _fk_address; } set { this._fk_address = value; } }
private Address _address;
[Association(Storage ="_address", IsForeignKey = true, ThisKey = "fk_adress", OtherKey = "pk_address")]
public Address address { get { return _address; } set { this._address = value; } }
private string _rawResult;
[Column(Storage = "_rawResult", Name = "raw")]
public string rawResult { get { return _rawResult; } set { this._rawResult = value; } }
private int _code = -5;
[Column(Storage = "_code")]
public int code { get { return _code; } set { this._code = value; } }
private DateTime _scanDate = DateTime.Now;
[Column(Storage = "_scanDate")]
public DateTime scanDate { get { return _scanDate; } set { this._scanDate = value; } }
private int? _fk_proxy;
[Column(Storage = "_fk_proxy", Name = "usedProxy", CanBeNull = true)]
public int? fk_proxy { get { return _fk_proxy; } set { this._fk_proxy = value; } }
private ProxyData _usedProxy;
[Association(Storage = "_usedProxy", IsForeignKey = true, ThisKey = "fk_proxy", OtherKey = "pk_proxy")]
public ProxyData usedProxy { get { return _usedProxy; } set { this._usedProxy = value; } }
public string message { get; set; } = "";
public bool availability { get; set; }
public int planCode { get; set; }
public string planning { get; set; }
public override string ToString()
{
return string.Format("availability={0}, code={1}, message={2}", availability, code, message);
}
}
This is one of the child classes
[Table(Name = "address")]
public class Address
{
private int _pk_address;
[Column(IsPrimaryKey = true, IsDbGenerated = true, Storage = "_pk_address")]
public int pk_address { get { return _pk_address; } set { this._pk_address = value; } }
private string _provId;
[Column(Storage = "_provId")]
public string provId { get { return _provId; } set { this._provId = value; } }
private string _zipcode;
[Column(Storage = "_zipcode")]
public string zipcode { get { return _zipcode; } set { this._zipcode = value; } }
private int _houseNumber;
[Column(Storage = "_houseNumber")]
public int houseNumber { get { return _houseNumber; } set { this._houseNumber = value; } }
private string _addressAddition;
[Column(Storage = "_addressAddition")]
public string addressAddition { get { return _addressAddition; } set { this._addressAddition = value; } }
public string ToAddresString()
{
return string.Format("{0} {1}{2}", this.provId, zipcode, houseNumber, addressAddition);
}
public override string ToString()
{
return string.Format("{0}:\t{1}\t{2}{3}", this.provId, zipcode, houseNumber, addressAddition);
}
}
I want to get SniffResult including the associated fields. But they are all null. This is the code I use:
SniffDAO dao = new SniffDAO();
var test = from sr in dao.SniffResults
where sr.fk_scan == 3
select sr;
foreach (var one in test)
{
Console.WriteLine(one.pk_SniffResult);
Console.WriteLine(one.address);
}
one.address gives me a null, what am I doing wrong?
This is the Dao class
public class SniffDAO
{
private string currentDir;
private DataContext db;
public Table<Scan> Scans { get; set; }
public Table<SniffResult> SniffResults { get; set; }
public Table<Address> Addresses { get; set; }
public SniffDAO()
{
db = new DataContext(#"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=********;Integrated Security=True;Asynchronous Processing=True");
db.ObjectTrackingEnabled = true;
Scans = db.GetTable<Scan>();
SniffResults = db.GetTable<SniffResult>();
Addresses = db.GetTable<Address>();
currentDir = Directory.GetCurrentDirectory();
}
public void save()
{
db.SubmitChanges();
}
}
You need to Include related entities like this:
SniffDAO dao = new SniffDAO();
var test = dao.SniffResults.Include(x=>x.address).Where(sr.fk_scan == 3);
foreach (var one in test)
{
Console.WriteLine(one.pk_SniffResult);
Console.WriteLine(one.address);
}
I found the solution thanks to #Kris. I now use:
DataLoadOptions dlo = new DataLoadOptions();
dlo.LoadWith<SniffResult>(sr => sr.address);
dlo.LoadWith<SniffResult>(sr => sr.usedProxy);
dlo.LoadWith<SniffResult>(sr => sr.scan);
db.LoadOptions = dlo; //db is the DataContext
See https://msdn.microsoft.com/en-us/library/bb548760(v=vs.110).aspx for more info
I have converted the following two classes to c# from vb.net, but get a reference error. Can someone please help or explain why it does not work in c# but does in vb.net?
Member class:
public class Member
{
#region "Fields"
private string fPiecemark;
private string fMemberType;
private string fSize;
private string fTotalWeight;
private int fSheetKey;
private string fDescription;
private string fStructType;
#endregion
private string fMemberSheetIndex;
#region "Constructors"
//Default class Constructor
public Member()
{
fPiecemark = string.Empty;
fMemberType = string.Empty;
fSize = string.Empty;
fTotalWeight = string.Empty;
fSheetKey = 0;
fStructType = string.Empty;
}
public Member(string Piecemark, string MemberType, string Description, string Size, string TotalWeight, string StructType, string MemberSheetIndex, int SheetID)
{
this.Piecemark = Piecemark;
this.MemberType = MemberType;
this.Description = Description;
this.Size = Size;
this.TotalWeight = TotalWeight;
this.StructType = StructType;
this.MemberSheetIndex = MemberSheetIndex;
this.SheetKey = SheetID;
if (!MbrSheet.mSheet.ContainsKey(SheetID))
{
MbrSheet.mSheet.Add(SheetID, new MbrSheet(SheetID));
}
MbrSheet.mSheets[SheetID].Members.Add(this);
}
#endregion
#region "Properties"
public string Piecemark
{
get { return fPiecemark; }
set { fPiecemark = value; }
}
public string MemberType
{
get { return fMemberType; }
set { fMemberType = value; }
}
public string TotalWeight
{
get { return fTotalWeight; }
set { fTotalWeight = value; }
}
public string Size
{
get { return fSize; }
set { fSize = value; }
}
public int SheetKey
{
get { return fSheetKey; }
set { fSheetKey = value; }
}
public string Description
{
get { return fDescription; }
set { fDescription = value; }
}
public string StructType
{
get { return fStructType; }
set { fStructType = value; }
}
public string MemberSheetIndex
{
get { return fMemberSheetIndex; }
set { fMemberSheetIndex = value; }
}
#endregion
}
MbrSheet class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Globalization;
public class MbrSheet
{
public static Dictionary<int, MbrSheet> mSheets = new Dictionary<int, MbrSheet>();
public int mSheet { get; set; }
public List<Member> Members { get; set; }
public MbrSheet(int MbrSheet)
{
Members = new List<Member>();
this.mSheet = MbrSheet;
}
public static decimal WeightByType(string MemberType)
{
var subset = mSheets.Where(kvp => kvp.Value.Members.Where(m => m.MemberType == MemberType).Count() > 0);
decimal wbt = 0;
wbt += mSheets
.Where(kvp => kvp.Value.Members.Where(m => m.MemberType == MemberType).Count() > 0)
.Sum(kvp => kvp.Value.Members.Sum(m => Convert.ToDecimal(m.TotalWeight, CultureInfo.InvariantCulture)));
return wbt;
}
}
I get error but don't know why
An object reference is required for the non-static field, method, or property for MbrSheet.mSheet, but both worked in VB.net
if (!MbrSheet.mSheet.ContainsKey(SheetID)) // Error on !MbrSheet.mSheet
{
MbrSheet.mSheet.Add(SheetID, new MbrSheet(SheetID)); // Error on MbrSheet.mSheet
}
I think you should use this:
if (!MbrSheet.mSheets.ContainsKey(SheetID))
{
MbrSheet.mSheets.Add(SheetID, new MbrSheet(SheetID));
}
Pay attention to mSheets you are using mSheet.
You can also use tools to convert codes:
http://www.developerfusion.com/tools/convert/csharp-to-vb/
http://codeconverter.sharpdevelop.net/SnippetConverter.aspx
I want to add a DisplayAttribute to the Client entity (from another project), but don't want to pollute my entity with attributes specific to MVC or a UI layer. So I planned to add the DisplayAttribute by applying a metadata class to a view model inheriting from the entity
If I inherit from the Client entity and then try to use the MetadataTypeAttribute to add a display attribute, it doesn't show up in the browser. Does anyone know how I can achieve the separation and the functionality of being able to add metadata to my entities?
The Client entity class:
public class Client
{
private string firstName;
private string lastName;
private string homeTelephone;
private string workTelephone;
private string mobileTelephone;
private string emailAddress;
private string notes;
public Title Title { get; set; }
public string FirstName
{
get { return this.firstName ?? string.Empty; }
set { this.firstName = value; }
}
public string LastName
{
get { return this.lastName ?? string.Empty; }
set { this.lastName = value; }
}
public string FullName
{
get
{
List<string> nameParts = new List<string>();
if (this.Title != Title.None)
{
nameParts.Add(this.Title.ToString());
}
if (this.FirstName.Length > 0)
{
nameParts.Add(this.FirstName.ToString());
}
if (this.LastName.Length > 0)
{
nameParts.Add(this.LastName.ToString());
}
return string.Join(" ", nameParts);
}
}
public Address Address { get; set; }
public string HomeTelephone
{
get { return this.homeTelephone ?? string.Empty; }
set { this.homeTelephone = value; }
}
public string WorkTelephone
{
get { return this.workTelephone ?? string.Empty; }
set { this.workTelephone = value; }
}
public string MobileTelephone
{
get { return this.mobileTelephone ?? string.Empty; }
set { this.mobileTelephone = value; }
}
public string EmailAddress
{
get { return this.emailAddress ?? string.Empty; }
set { this.emailAddress = value; }
}
public string Notes
{
get { return this.notes ?? string.Empty; }
set { this.notes = value; }
}
public Client()
{
this.Address = new Address();
}
}
The ClientViewModel view model class:
[MetadataType(typeof(ClientMetaData))]
public class ClientViewModel : Client
{
internal class ClientMetaData
{
[Display(ResourceType = typeof(ResourceStrings), Name = "Client_FirstName_Label")]
public string FirstName { get; set; }
}
}
I think you have change the typeof parameter to:
[MetadataType(typeof(ClientViewModel.ClientMetaData))]
public class ClientViewModel : Client
{
internal class ClientMetaData
{
[Display(ResourceType = typeof(ResourceStrings), Name = "Client_FirstName_Label")]
public string FirstName { get; set; }
}
}
For .Net Core 6.0 use
[ModelMetadataType(typeof(ClientViewModel.ClientMetaData))]
insead of
[MetadataType(typeof(ClientViewModel.ClientMetaData))]
I need to be able to define two nodes with the same name but completely different subnode structures. I didn't design this XML schema but for the time being I'm forced to use it as is. I realize it's a terrible abuse of everything that is XML but there you have it.
What I need it to look like:
<order>
<ItemType type="Clubs">
<Club num="1">
<ClubName>Some Name</ClubName>
<ClubChoice>Something Else</ClubChoice>
</Club>
</ItemType>
<ItemType type="Gift" val="MailGreeting">
<GiftName>MailGreeting</GiftName>
<GiftDescription></GiftDescription>
<GiftQuanity>1</GiftQuanity>
</ItemType
</order>
Of course it's far more complicated than but you get the gist.
I'm using XmlSerializer and would really like to avoid using XDocument but if that's what I need to do then so be it.
If your order contains properties and not a list you can tell the serializer to name the elements like this:
[XmlRoot("order")]
public class Order
{
private Whatever whateverInstance;
[XmlElement("ItemType")]
public Whatever WhateverInstance
{
get { return whateverInstance; }
set { whateverInstance = value; }
}
private Something somethingInstance;
[XmlElement("ItemType")]
public Something SomethingInstance
{
get { return somethingInstance; }
set { somethingInstance = value; }
}
}
If it's a list of things you could get to have a identical element name as well but you will get a redundant xsi:Type attribute:
[XmlRoot("order")]
public class Order
{
private ItemType[] itemTypes;
[XmlElement("ItemType")]
public ItemType[] ItemTypes
{
get { return itemTypes; }
set { itemTypes = value; }
}
}
[XmlInclude(typeof(Clubs))]
[XmlInclude(typeof(Gift))]
public abstract class ItemType
{
private string type = "None";
[XmlAttribute]
public string Type
{
get { return type; }
set { type = value; }
}
}
public class Clubs : ItemType
{
public Clubs()
{
Type = "Clubs";
}
private Club[] clubsArray;
[XmlElement("Club")]
public Club[] ClubsArray
{
get { return clubsArray; }
set { clubsArray = value; }
}
}
public class Club
{
private int num = 0;
[XmlAttribute("num")]
public int Num
{
get { return num; }
set { num = value; }
}
private string clubName = "";
public string ClubName
{
get { return clubName; }
set { clubName = value; }
}
private string clubChoice = "";
public string ClubChoice
{
get { return clubChoice; }
set { clubChoice = value; }
}
}
public class Gift : ItemType
{
public Gift()
{
Type = "Gift";
}
private string val = "";
[XmlAttribute("val")]
public string Val
{
get { return val; }
set { val = value; }
}
private string giftName = "";
public string GiftName
{
get { return giftName; }
set { giftName = value; }
}
private string giftDescription = "";
public string GiftDescription
{
get { return giftDescription; }
set { giftDescription = value; }
}
private int giftQuanity = 0;
public int GiftQuanity
{
get { return giftQuanity; }
set { giftQuanity = value; }
}
}
Test:
List<ItemType> list = new List<ItemType>();
list.Add(new Clubs() { ClubsArray = new Club[] { new Club() { Num = 0, ClubName = "Some Name", ClubChoice = "Something Else" } } });
list.Add(new Gift() { Val = "MailGreeting", GiftName = "MailGreeting", GiftDescription = "GiftDescription", GiftQuanity = 1});
Order order = new Order();
rder.ItemTypes = list.ToArray();
XmlSerializer serializer = new XmlSerializer(typeof(Order));
StreamWriter sw = new StreamWriter(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\Stuff.xml");
serializer.Serialize(sw, order);
sw.Close();
Output:
<order xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<ItemType xsi:type="Clubs" Type="Clubs">
<Club num="0">
<ClubName>Some Name</ClubName>
<ClubChoice>Something Else</ClubChoice>
</Club>
</ItemType>
<ItemType xsi:type="Gift" Type="Gift" val="MailGreeting">
<GiftName>MailGreeting</GiftName>
<GiftDescription>GiftDescription</GiftDescription>
<GiftQuanity>1</GiftQuanity>
</ItemType>
</order>