Hi There,
I have a method which uses some values passed in as xml, at times some of the elements in the document will be null. The document itself has many elements and I wanted to handle the null elements by just using a method wrapped around the element itself rather than using if statements. Could someone helpme out with the syntax so that the method returns back the object please?
thanks in advance, sean
this.someNode = handleNull <XmlElement>(re f this.nodeTosele ct,someNode.Sel ectSingleNode(" anodetoselect") as XmlElement);
protected T handleNull<T>(r ef T val,XmlElement elmToParse)
{
if (elmToParse != null && !string.IsNullO rEmpty(elmToPar se.InnerText))
{
val = (T)Convert.Chan geType(elmToPar se, typeof(T));
return val;
}
val = (T)Convert.Chan geType(elmToPar se, typeof(XmlEleme nt));
return val;
}
I have a method which uses some values passed in as xml, at times some of the elements in the document will be null. The document itself has many elements and I wanted to handle the null elements by just using a method wrapped around the element itself rather than using if statements. Could someone helpme out with the syntax so that the method returns back the object please?
thanks in advance, sean
this.someNode = handleNull <XmlElement>(re f this.nodeTosele ct,someNode.Sel ectSingleNode(" anodetoselect") as XmlElement);
protected T handleNull<T>(r ef T val,XmlElement elmToParse)
{
if (elmToParse != null && !string.IsNullO rEmpty(elmToPar se.InnerText))
{
val = (T)Convert.Chan geType(elmToPar se, typeof(T));
return val;
}
val = (T)Convert.Chan geType(elmToPar se, typeof(XmlEleme nt));
return val;
}
Comment