public static GetValueResult TryGetValueResult <T>(this XmlNode node, string attributeName, out T result, T defaultValue = default(T)) { result = defaultValue; string value; try { value = node.Attributes[attributeName].Value; } catch { return(GetValueResult.Missing); } var serializer = new XmlValueSerializer(); return(serializer.Deserialize(value, out result)); }
public static T GetAttributeValue <T>(this XmlNode node, string attributeName) { string value; try { value = node.Attributes[attributeName].Value; } catch { throw new ArgumentException("Could get attribute: ", attributeName); } var serializer = new XmlValueSerializer(); if (serializer.Deserialize(value, out var result, default(T)) != GetValueResult.Success) { throw new ArgumentException($"Could get parse attribute to type {typeof(T).FullName}: ", attributeName); } return(result); }