Radim Motycka

Radim Motycka

  • NA
  • 31
  • 31.2k

How to make this class better?

Jun 11 2014 6:06 PM

Hi,

Please could you advise? I am not completely happy with this class especially with XmlDocument in foreach loop.

Please do you have any idea how to get rid of it?
 

public class EntryConverter

{

public IEnumerable<Entry> Convert(IsirPub001Data[] rawEntries)

{

foreach (var raw in rawEntries)

{

XmlDocument xmlDocument = new XmlDocument();

xmlDocument.LoadXml(raw.poznamka);

Entry entry = new Entry();

entry.Added = raw.cas;

entry.EntryId = raw.id;

entry.Note = raw.poznamka;

entry.DocumentId = raw.spisZnacka;

entry.TypeId = raw.typ;

entry.TypeDescription = raw.typText;

entry.PersonIdFrom = GetNodeValue(xmlDocument, "//idOsobyPuvodcec/text()");

entry.PersonId = GetNodeValue(xmlDocument, "//osoba/idOsoby/text()");

entry.KindRoleAssignement = GetNodeValue(xmlDocument, "//osoba/druhRoleVRizeni/text()");

entry.Name = GetNodeValue(xmlDocument, "//osoba/nazevOsoby/text()");

entry.CompanyIdentificationNumber = GetNodeValue(xmlDocument, "//osoba/ic/text()");

entry.TaxIdentificationNumber = GetNodeValue(xmlDocument, "//osoba/dic/text()");

entry.PersonalIdentificationNumber = GetNodeValue(xmlDocument, "//osoba/rc/text()");

entry.LawFormKind = GetNodeValue(xmlDocument, "//osoba/druhPravniForma/text()");

yield return entry;

}

}

private static string GetNodeValue(XmlNode document, string xPathQuery)

{

return document.SelectSingleNode(xPathQuery).GetValueOrDefault();

}

}

 
 

Answers (1)