Witam,
w C# nie jestem specem ale od czasu do czasu w razie potrzeby potrafię dojść do celu.
Piszę aplikację konsolową, której zadaniem jest odczytanie paru tagów z pliku xml i na tej podstawie zapisanie pewnym informacji do bazy danych.
Na początek jednak, aby wszystko miało ręce i nogi i było zgodne z dobrym "kodowym" gustem, proszę o wskazówki. Otóż mój prosty kod poniżej. Chciałym uzyskać prostą sytuację by w Main móc ładnie odczytywać to co zwóciła mi moja metoda razem z ewentualnym wyjątkiem. Znowu mam zadeklarować hashTable i przypisać do niej metodę? Proszę o wskazówki/poprawę mojego kodu ( reszta w komentarzach w kodzie )
class Program
{
private string filter;
private string Server;
private string Database;
private short Typ;
private int Numer;
static void Main(string[] args)
{
Console.WriteLine(args[0]);
Console.ReadKey();
Console.WriteLine("-----------------------");
new Program().getXml(args[0]);
}
private Hashtable getXml(string arg)
{
XmlDocument xmlDocument = new XmlDocument();
try
{
xmlDocument.Load(arg);
this.Database = xmlDocument.DocumentElement["database"].InnerText;
this.Server = xmlDocument.DocumentElement["server"].InnerText;
this.filter = xmlDocument.DocumentElement["parameters"]["filter"].InnerText;
string[] filterNodeArray = this.filter.Split(new char[1]
{
'='
});
this.GIDTyp = short.Parse(filterNodeArray[1].Substring(0, filterNodeArray[1].IndexOf(' ')));
this.GIDNumer = int.Parse(filterNodeArray[2]);
Hashtable xmlHashTable = new Hashtable();
// jak ładniej dodać te wartości do hashTable?
xmlHashTable.Add(0, this.xlServer);
xmlHashTable.Add(1, this.xlDatabase);
xmlHashTable.Add(2, this.GIDTyp);
xmlHashTable.Add(3, this.GIDNumer);
return xmlHashTable;
}
catch(FileLoadException ex)
{
// tutaj moja radosna twórczość bo metoda zwraca hashTable to tutaj też musi - chyba?
Hashtable exMessage = new Hashtable();
exMessage.Add("exceptionMessage", ex.Message);
return exMessage;
}
}
}