Exemple #1
0
 public static TestRunner.Jargon ToTestRunnerJargon(this XmlVersion version)
 {
     return(version switch
     {
         XmlVersion.NUnitV2 => TestRunner.Jargon.NUnitV2,
         XmlVersion.NUnitV3 => TestRunner.Jargon.NUnitV3,
         XmlVersion.xUnit => TestRunner.Jargon.xUnit,
         _ => throw new ArgumentOutOfRangeException()
     });
Exemple #2
0
        /// <summary>
        /// The contains invalid xml characters.
        /// </summary>
        /// <param name="s">
        /// The s.
        /// </param>
        /// <param name="version">
        /// The version.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        public static bool ContainsInvalidXmlCharacters(this string s, XmlVersion version = 0)
        {
            if (string.IsNullOrEmpty(s))
            {
                return(false);
            }

            return(DoRetreiveXmlInvalidCharactersSet(version).IsMatch(s));
        }
Exemple #3
0
        /// <summary>
        /// The do retreive xml invalid characters set.
        /// </summary>
        /// <param name="version">
        /// The version.
        /// </param>
        /// <returns>
        /// The <see cref="Regex"/>.
        /// </returns>
        /// <exception cref="ArgumentException">
        /// </exception>
        private static Regex DoRetreiveXmlInvalidCharactersSet(XmlVersion version)
        {
            switch (version)
            {
            case XmlVersion.Version_1_0:
                return(regexXmlInvalidCharacters_1_0);

            case XmlVersion.Version_1_1:
                return(regexXmlInvalidCharacters_1_1);
            }

            throw new ArgumentException(string.Format("Версия XML не поддерживается: {0}", version));
        }
Exemple #4
0
        /// <summary>
        /// The replace invalid xml characters.
        /// </summary>
        /// <param name="s">
        /// The s.
        /// </param>
        /// <param name="version">
        /// The version.
        /// </param>
        /// <param name="replacement">
        /// The replacement.
        /// </param>
        /// <param name="allowNull">
        /// The allow null.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        public static string ReplaceInvalidXmlCharacters(
            this string s,
            XmlVersion version = 0,
            string replacement = " ",
            bool allowNull     = false)
        {
            if (!string.IsNullOrEmpty(s))
            {
                return(DoRetreiveXmlInvalidCharactersSet(version).Replace(s, replacement));
            }

            if ((s == null) && allowNull)
            {
                return(null);
            }

            return(string.Empty);
        }