c# - XmlConvert and nullable results? -


In my project, I get an XMLElement where I have to parse some properties back into the class.

For these mapping I use the XmlConvert class. But the sources of XML are often empty nodes or nodes which are not readable. Instead, after throwing a bunch of errors, I want to take a null back to store in my class.

I started creating an XmlConvertExtentions class which works in the following emotions:

  public static class XmlConvertExtentions {public static int? ToNullableInt32 (this XmlConvert c, string s) {try {return XmlConvert.ToInt32 (s); } Hold {return tap; }}}  

I am confident that I am not the first developer to require such functionality and I am thinking that I am not yet searching for another wheel.
Besides, I think that I'm actually searching for a ugly wheel. It seems bad to try. Is there a better way?

- Edit
And now I've also found that it does not even work: P I think this is because you are not expanding the stable classes Can be done

If the node is empty or empty, what is s ?

How about the bus:

  if return (string.IsNullOrEmpty (s)) zero; Return XmlConvert.ToInt32 (S);  

Also keep in mind that LINQ-to-XML is more attractive handling of these conversions (via cast).


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -