public static void SetTextAttribute(this StageElement parent, string name, string value, bool removeIfEmpty = true) { bool flag; if (value == null) { flag = true; } else { flag = (!removeIfEmpty ? false : string.IsNullOrEmpty(value)); } bool flag1 = flag; StageAttribute str = parent.Attribute(name); if (str != null) { if (flag1) { str.Remove(); return; } if (!str.isText) { throw new InvalidOperationException("Cannot set a text value on a non-text attribute."); } str.@value = SerializationMaster.ToString(value); } else if (!flag1) { parent.Add(SerializationMaster.ToStageAttribute(name, value)); return; } }
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 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)); }
public static void SetAttribute(this StageElement parent, string name, object value) { bool flag = value == null; StageAttribute str = parent.Attribute(name); if (str != null) { if (flag) { str.Remove(); return; } if (str.isText && !(value is string)) { throw new InvalidOperationException("Use SetTextAttribute to set text attributes."); } str.@value = SerializationMaster.ToString(value); } else if (!flag) { parent.Add(SerializationMaster.ToStageAttribute(name, value)); return; } }