public static T AttributeValue <T>(this StageElement element, string attributeName) { if (element != null) { StageAttribute stageAttribute = element.Attribute(attributeName); if (stageAttribute != null) { return(SerializationMaster.FromString <T>(stageAttribute.@value)); } } throw new ArgumentException(string.Concat("No attribute by that name was found: ", attributeName)); }
public static T ValueOrDefault <T>(this StageItem item, T defaultValue = null) { if (item == null || item is StageNull) { return(defaultValue); } if (item is StageContainer) { return(SerializationMaster.UnstageAndInitialize <T>(item)); } return(SerializationMaster.FromString <T>(((StageValue)item).@value)); }
/// <summary> /// Gets the converted value of the specified attribute. /// </summary> /// <param name="element">The element.</param> /// <param name="attributeName">Name of the attribute.</param> /// <returns>The value of the attribute.</returns> /// <exception cref="System.ArgumentException">If no attribute by that name was found.</exception> public static T AttributeValue <T>(this StageElement element, string attributeName) { if (element != null) { var attrib = element.Attribute(attributeName); if (attrib != null) { return(SerializationMaster.FromString <T>(attrib.value)); } } throw new ArgumentException("No attribute by that name was found: " + attributeName); }
public static T AttributeValueOrDefault <T>(this StageElement element, string attributeName, T defaultValue = null) { if (element == null) { return(defaultValue); } StageAttribute stageAttribute = element.Attribute(attributeName); if (stageAttribute == null) { return(defaultValue); } return(SerializationMaster.FromString <T>(stageAttribute.@value)); }
/// <summary> /// Gets the converted value of the specified attribute, or a default value if the element or the attribute is null or if it has no value. /// </summary> /// <param name="element">The element.</param> /// <param name="attributeName">Name of the attribute.</param> /// <param name="defaultValue">The default value.</param> /// <returns>The value of the attribute, or <paramref name="defaultValue"/> if <paramref name="element"/> or the attribute is <c>null</c> or has no value.</returns> public static T AttributeValueOrDefault <T>(this StageElement element, string attributeName, T defaultValue = default(T)) { if (element == null) { return(defaultValue); } var attrib = element.Attribute(attributeName); if (attrib == null) { return(defaultValue); } return(SerializationMaster.FromString <T>(attrib.value)); }