public static string FormatCommaSeparatedValue(this string value)
#endif
        {
            if (null == value)
            {
                return null;
            }

            if (0 == value.Length)
            {
                return string.Empty;
            }

#if NET20
            value = StringExtensionMethods.Replace(value, "\"", "\"\"", StringComparison.Ordinal);
#else
            value = value.Replace("\"", "\"\"", StringComparison.Ordinal);
#endif

            return ' ' == value[0]
                   || ' ' == value[value.Length - 1]
#if NET20
                   || StringExtensionMethods.ContainsAny(value, ',', '\n', '"')
#else
                   || value.ContainsAny(',', '\n', '"')
#endif
                   || value.Contains(Environment.NewLine)
                       ? string.Concat("\"", value, "\"")
                       : value;
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Determines whether the specified text contains any of the characters of the second parameter.
        /// </summary>
        /// <param name="text">The text.</param>
        /// <param name="characters">The characters.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">characters</exception>
        public static bool ContainsAny(this string text, string characters)
        {
            if (string.IsNullOrWhiteSpace(characters))
                throw new ArgumentNullException("characters");

            return text.ContainsAny(characters.ToCharArray());
        }
Exemplo n.º 3
0
        /// <summary>
        /// Checks input string for any occurence of given character
        /// </summary>
        /// <param name="source">String to check</param>
        /// <param name="character">Character to look for</param>
        /// <returns>True if character found</returns>
        public static bool ContainsAny(this string source, char character)
        {
            Validate.Begin()
                .IsNotNull(source, "source")
                .CheckForExceptions();

            return source.ContainsAny(character.ToEnumerable());
        }
Exemplo n.º 4
0
        public static string SafeToken(this string token)
        {
            if (token.ContainsAny("\"", " ", "-", "+", "\\", "*", "=", "!"))
                throw new InvalidDataException("MetaData is potentially malicious. Expected token, Received: {0}".Fmt(token));

            return token;
        }
        public static string SafeToken(this string token)
        {
            if (!NativeTypesFeature.DisableTokenVerification && token.ContainsAny("\"", "-", "+", "\\", "*", "=", "!"))
                throw new InvalidDataException($"MetaData is potentially malicious. Expected token, Received: {token}");

            return token;
        }
 public static bool ContainsAny(this string value, out string matchedValue, params string[] contains)
 {
     return value.ContainsAny(out matchedValue, StringComparison.Ordinal, contains);
 }
 public static bool ContainsAny(this string value, params string[] contains)
 {
     return value.ContainsAny(StringComparison.Ordinal, contains);
 }