/// <summary> /// Requires that the named argument's state is valid (i.e., true). /// </summary> /// <param name="argState">The argument's state.</param> /// <param name="explanation">The explanation to put in the exception.</param> /// <param name="argName">The name of the arg to put in the exception.</param> /// <exception cref="ArgumentException">If <paramref name="argState"/> is false.</exception> public static void RequireArgument([DoesNotReturnIf(false)] bool argState, string explanation, string argName) { if (!argState) { throw Exceptions.NewArgumentException(explanation, argName); } }
/// <summary> /// Gets the specified attribute's value. /// </summary> /// <param name="element">The element to get the attribute from.</param> /// <param name="name">The name of the attribute to read.</param> /// <returns>The value of the attribute. An <see cref="ArgumentException"/> /// is thrown if the specified attribute isn't found.</returns> /// <exception cref="ArgumentException">Throw if either of the arguments are null, /// or if the specified attribute isn't found.</exception> public static string GetAttributeValue(this XElement element, XName name) { string?result = GetAttributeValueN(element, name, null, false); if (result == null) { throw Exceptions.NewArgumentException($"The {element.Name} element does not have a {name} attribute."); } else if (string.IsNullOrEmpty(result)) { throw Exceptions.NewArgumentException($"The {element.Name} element has an empty {name} attribute."); } return(result); }