Click here to Skip to main content
Click here to Skip to main content
Alternative Tip

Tagged as

Go to top

Using Extension Methods To Avoid XML Problems

, 22 May 2010
Rate this:
Please Sign up or sign in to vote.
public static string GetValue(this XElement root, string name, string defaultValue) { XElement el = root.Element(name); return el == null ? defaultValue : el.Value; }I agree, Contains can be omitted, using instead root.Element(name)!=nullsince...
      public static string GetValue(this XElement root, string name, string defaultValue) {
         XElement el = root.Element(name);
         return el == null ? defaultValue : el.Value;
      }
I agree, Contains can be omitted, using instead
root.Element(name)!=null
since root.Element(name) returns null, if name isn't available.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Mr.PoorEnglish

Germany Germany
No Biography provided

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 22 May 2010
Article Copyright 2010 by Mr.PoorEnglish
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid