?
[STAThread]
static void Main(string[] args)
{
//
// TODO: Fügen Sie hier Code hinzu, um die Anwendung zu starten
//
Auto auto1 = new Auto("Ford", "Mustang");
Auto auto2 = new Auto("IFA", "Trabi");
Autohaus autohaus = new Autohaus();
autohaus.Angebot.Add(auto1);
autohaus.Angebot.Add(auto2);
Auto [] cars = {auto1,auto2};
AutoMarken mengeautos = new AutoMarken(cars);
try
{
XmlSerializer xmls1 = new XmlSerializer(typeof(Autohaus));
XmlSerializer xmls2 = new XmlSerializer(typeof(AutoMarken));
XmlTextWriter xmlw1 = new XmlTextWriter("C:\\autos1.xml",System.Text.Encoding.ASCII);
xmls1.Serialize(xmlw1,autohaus);
XmlTextWriter xmlw2 = new XmlTextWriter("C:\\autos2.xml",System.Text.Encoding.ASCII);
xmls2.Serialize(xmlw2,mengeautos);
xmlw1.Close(); xmlw2.Close();
}
catch(System.Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.ReadLine();
}
}
public class Auto
{
public Auto(string Marke, string Autoname)
{
this.Marke = Marke;
this.Autoname = Autoname;
}
public Auto()
{
Marke = "";
Autoname = "";
}
private string autoname;
private string marke;
[XmlElementAttribute(IsNullable = false)]
public string Marke
{
get
{
return marke;
}
set
{
this.marke = value;
}
}
public string Autoname
{
get
{
return autoname;
}
set
{
this.autoname = value;
}
}
}
public class Autos : CollectionBase
{
public Auto this[ int index ]
{
get
{
return( (Auto) List[index] );
}
set
{
List[index] = value;
}
}
public int Add( Auto value )
{
return( List.Add( value ) );
}
public int IndexOf( Auto value )
{
return(List.IndexOf( value ) );
}
public void Insert( int index, Auto value )
{
List.Insert( index, value );
}
public void Remove( Auto value )
{
List.Remove( value );
}
public bool Contains( Auto value )
{
// If value is not of type Int16, this will return false.
return( List.Contains( value ) );
}
protected override void OnInsert( int index, Object value )
{
if ( (value is Auto) != true )
throw new ArgumentException( "value must be of type Auto.", "value" );
}
protected override void OnRemove( int index, Object value )
{
if ( (value is Auto) != true )
throw new ArgumentException( "value must be of type Auto.", "value" );
}
protected override void OnSet( int index, Object oldValue, Object newValue )
{
if ( (newValue is Auto) != true )
throw new ArgumentException( "newValue must be of type Auto.", "newValue" );
}
protected override void OnValidate( Object value )
{
if ( (value is Auto) != true )
throw new ArgumentException( "value must be of type Auto." );
}
}
public class Autohaus
{
private Autos autos;
[XmlElementAttribute(IsNullable = false)]
public Autos Angebot
{
get
{
return autos;
}
set
{
this.autos = value;
}
}
public Autohaus()
{
autos = new Autos();
}
public Autohaus(Autos autos)
{
Angebot = autos;
}
}
public class AutoMarken
{
private Auto [] autos;
public AutoMarken(Auto [] autos)
{
this.autos = autos;
}
[XmlElementAttribute(IsNullable = false)]
public Auto [] Autos
{
get
{
return autos;
}
set
{
this.autos = null;
this.autos = new Auto [value.Length];
for(int i = 0;i< value.Length;i++)
{
this.autos[i] = value[i];
}
}
}
public AutoMarken()
{
autos = null;
}
}
Viel Spass