示例#1
0
 public static bool Contains([NotNull] this string @this,
                             [NotNull] string value, StringComparison comparisonType)
 {
     if (!comparisonType.IsValid())
     {
         throw new ArgumentOutOfRangeException(nameof(comparisonType), comparisonType, null);
     }
     return(@this.IndexOf(value, comparisonType) >= 0);
 }
示例#2
0
        /// <summary>
        /// Returns a value indicating whether a specified substring occurs within this string while also enabling configuration of substring comparison.
        /// </summary>
        /// <param name="input">The input string.</param>
        /// <param name="value">The string to seek.</param>
        /// <param name="comparisonType">The type of substring comparison that should occur.</param>
        /// <returns><c>true</c> if <paramref name="input"/> contains <paramref name="value"/> using the configured <paramref name="comparisonType"/> or if <paramref name="value"/> is empty; otherwise, <c>false</c>.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="input"/> or <paramref name="value"/> is <c>null</c></exception>
        /// <exception cref="ArgumentException"><paramref name="comparisonType"/> is not a valid value.</exception>
        public static bool Contains(this string input, string value, StringComparison comparisonType)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }
            if (!comparisonType.IsValid())
            {
                throw new ArgumentException($"The { nameof(StringComparison) } provided must be a valid enum.", nameof(comparisonType));
            }

            return(input.IndexOf(value, comparisonType) >= 0);
        }
示例#3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="IdentifierComparer"/> class.
        /// </summary>
        /// <param name="comparison">The string comparison method to use.</param>
        /// <param name="defaultServer">The default server to use when missing in an <see cref="Identifier"/>.</param>
        /// <param name="defaultDatabase">The default database to use when missing in an <see cref="Identifier"/>.</param>
        /// <param name="defaultSchema">The default schema to use when missing in an <see cref="Identifier"/>.</param>
        /// <exception cref="ArgumentException"><paramref name="comparison"/> is an invalid value.</exception>
        public IdentifierComparer(StringComparison comparison = StringComparison.OrdinalIgnoreCase, string?defaultServer = null, string?defaultDatabase = null, string?defaultSchema = null)
        {
            if (!comparison.IsValid())
            {
                throw new ArgumentException($"The { nameof(StringComparison) } provided must be a valid enum.", nameof(comparison));
            }

            _comparer = StringComparerLookup[comparison];

            _defaultServer   = defaultServer.IsNullOrWhiteSpace() ? null : defaultServer;
            _defaultDatabase = defaultDatabase.IsNullOrWhiteSpace() ? null : defaultDatabase;
            _defaultSchema   = defaultSchema.IsNullOrWhiteSpace() ? null : defaultSchema;

            _defaultServerHash = _defaultServer != null?_comparer.GetHashCode(_defaultServer) : 0;

            _defaultDatabaseHash = _defaultDatabase != null?_comparer.GetHashCode(_defaultDatabase) : 0;

            _defaultSchemaHash = _defaultSchema != null?_comparer.GetHashCode(_defaultSchema) : 0;
        }