Example #1
0
        /// <summary>
        /// Gets the value of the XAttribute as double.
        /// </summary>
        /// <param name="attribute">The XAttribute.</param>
        /// <returns>The XAttribute value as double or null.</returns>
        public static double?GetValueAsDouble(this XAttribute attribute)
        {
            double result;

            if (attribute != null && double.TryParse(attribute.GetValue(), out result))
            {
                return(result);
            }

            return(null);
        }
Example #2
0
 /// <summary>
 /// Gets the value of the XAttribute as Guid.
 /// </summary>
 /// <param name="attribute">The XAttribute.</param>
 /// <returns>The XAttribute value as Guid or a emtpy Guid.</returns>
 public static Guid GetValueAsGuid(this XAttribute attribute)
 {
     try
     {
         return(new Guid(attribute.GetValue()));
     }
     catch
     {
         return(Guid.Empty);
     }
 }
Example #3
0
        /// <summary>
        /// Gets the value of the XAttribute as double.
        /// </summary>
        /// <param name="attribute">The XAttribute.</param>
        /// <returns>The XAttribute value as double or null.</returns>
        public static double?GetValueAsDouble(this XAttribute attribute)
        {
            double result;

            if (attribute != null && double.TryParse(attribute.GetValue(), System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out result))
            {
                return(result);
            }

            return(null);
        }
Example #4
0
        /// <summary>
        /// Gets the value of the XAttribute as long.
        /// </summary>
        /// <param name="attribute">The XAttribute.</param>
        /// <returns>The XAttribute value as long or null.</returns>
        public static long?GetValueAsLong(this XAttribute attribute)
        {
            long result;

            if (attribute != null && long.TryParse(attribute.GetValue(), out result))
            {
                return(result);
            }

            return(null);
        }
Example #5
0
        /// <summary>
        /// Gets the value of the XElement as Uri.
        /// </summary>
        /// <param name="attribute">The XElement.</param>
        /// <param name="uriKind">The UriKind used to try to create the Uri.</param>
        /// <returns>The XElement value as Uri or null.</returns>
        public static Uri GetValueAsUri(this XAttribute attribute, UriKind uriKind)
        {
            Uri uri;

            if (attribute != null && Uri.TryCreate(attribute.GetValue(), uriKind, out uri))
            {
                return(uri);
            }

            return(null);
        }
Example #6
0
        /// <summary>
        /// Gets the value of the XElement as int.
        /// </summary>
        /// <param name="attribute">The XElement.</param>
        /// <returns>The XElement value as int or null.</returns>
        public static bool?GetValueAsBoolean(this XAttribute attribute)
        {
            bool result;

            if (attribute != null && bool.TryParse(attribute.GetValue(), out result))
            {
                return(result);
            }

            return(null);
        }
Example #7
0
        /// <summary>
        /// Gets the value of the XElement as int.
        /// </summary>
        /// <param name="attribute">The XElement.</param>
        /// <returns>The XElement value as int or null.</returns>
        public static int?GetValueAsInt(this XAttribute attribute)
        {
            int result;

            if (attribute != null && int.TryParse(attribute.GetValue(), out result))
            {
                return(result);
            }

            return(null);
        }
 public static string GetValue(this XAttribute element)
 {
     return(element.GetValue(string.Empty));
 }
Example #9
0
        public static Uri GetValueAsUri(this XAttribute attribute)
        {
            Uri result;

            return((Uri.TryCreate(attribute.GetValue(), UriKind.RelativeOrAbsolute, out result)) ? result : null);
        }
Example #10
0
        public static TimeSpan?GetValueAsTimeSpan(this XAttribute attribute)
        {
            TimeSpan result;

            return((TimeSpan.TryParse(attribute.GetValue(), out result)) ? result : (TimeSpan?)null);
        }
Example #11
0
        public static string GetValue(this XAttribute attribute, string defaultValue)
        {
            string value = attribute.GetValue();

            return(value ?? defaultValue);
        }