Ejemplo n.º 1
0
        /// <summary>
        /// Formats the string using invariant culture info.
        /// </summary>
        /// <param name="format">The format string.</param>
        /// <param name="args">Arguments for the format string.</param>
        /// <returns>The formatted string.</returns>
        public static string FormatInvariant(this string format, params Object[] args)
        {
            ThrowIf.StringIsNullOrWhiteSpace(format, nameof(format));
            ThrowIf.ArgumentNull(args, nameof(args));

            return(string.Format(CultureInfo.InvariantCulture, format, args));
        }
Ejemplo n.º 2
0
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1720:IdentifiersShouldNotContainTypeNames", MessageId = "string")] // This is a stupid rule.
        public static bool StartsWithInvariant(this string thisString, string searchValue, bool ignoreCase = false)
        {
            ThrowIf.StringIsNullOrWhiteSpace(thisString, nameof(thisString));
            ThrowIf.StringIsNullOrWhiteSpace(searchValue, nameof(searchValue));

            var comparison = ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal;

            return(thisString.StartsWith(searchValue, comparison));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the XML attribute from the specified XmlNode.
        /// </summary>
        /// <param name="node">The XmlNode containing the attribute you want.</param>
        /// <param name="attributeName">The attribute name.</param>
        /// <returns>The xml attribute value.</returns>
        /// <exception cref="XmlException">There was an error parsing the XmlNode.</exception>
        public static string GetXmlAttribute(XmlNode node, string attributeName)
        {
            ThrowIf.ArgumentNull(node, nameof(node));
            ThrowIf.StringIsNullOrWhiteSpace(attributeName, nameof(attributeName));

            if (node.Attributes?[attributeName] == null)
            {
                throw new XmlException(StringUtils.FormatInvariant("No XML attribute named '{0}' was found!", attributeName));
            }

            return(node.Attributes[attributeName].Value);
        }