diff --git a/src/NHibernate.DomainModel/NHSpecific/NullableInt32.cs b/src/NHibernate.DomainModel/NHSpecific/NullableInt32.cs index b0e0eea2a93..89d599183bf 100644 --- a/src/NHibernate.DomainModel/NHSpecific/NullableInt32.cs +++ b/src/NHibernate.DomainModel/NHSpecific/NullableInt32.cs @@ -214,7 +214,7 @@ public int CompareTo(object obj) public static NullableInt32 Parse(string s) { - if ((s == null) || (s.Trim().Length == 0)) + if (string.IsNullOrWhiteSpace(s)) { return new NullableInt32(); } @@ -235,4 +235,4 @@ public static NullableInt32 Parse(string s) #endregion } -} \ No newline at end of file +} diff --git a/src/NHibernate/Async/Tool/hbm2ddl/SchemaExport.cs b/src/NHibernate/Async/Tool/hbm2ddl/SchemaExport.cs index c9a73c99807..f0fa0db18f3 100644 --- a/src/NHibernate/Async/Tool/hbm2ddl/SchemaExport.cs +++ b/src/NHibernate/Async/Tool/hbm2ddl/SchemaExport.cs @@ -37,7 +37,6 @@ public partial class SchemaExport dialect = Dialect.Dialect.GetDialect(configProperties); string autoKeyWordsImport = PropertiesHelper.GetString(Environment.Hbm2ddlKeyWords, configProperties, "not-defined"); - autoKeyWordsImport = autoKeyWordsImport.ToLowerInvariant(); if (autoKeyWordsImport == Hbm2DDLKeyWords.AutoQuote) { await (SchemaMetadataUpdater.UpdateAsync(cfg, dialect, cancellationToken)).ConfigureAwait(false); diff --git a/src/NHibernate/Async/Tool/hbm2ddl/SchemaUpdate.cs b/src/NHibernate/Async/Tool/hbm2ddl/SchemaUpdate.cs index 2f7b5e9098c..29da96ca5f6 100644 --- a/src/NHibernate/Async/Tool/hbm2ddl/SchemaUpdate.cs +++ b/src/NHibernate/Async/Tool/hbm2ddl/SchemaUpdate.cs @@ -32,7 +32,6 @@ public partial class SchemaUpdate } string autoKeyWordsImport = PropertiesHelper.GetString(Environment.Hbm2ddlKeyWords, configuration.Properties, "not-defined"); - autoKeyWordsImport = autoKeyWordsImport.ToLowerInvariant(); if (autoKeyWordsImport == Hbm2DDLKeyWords.AutoQuote) { await (SchemaMetadataUpdater.UpdateAsync(configuration, dialect, cancellationToken)).ConfigureAwait(false); @@ -56,26 +55,26 @@ public partial class SchemaUpdate for (int i = 0; i < args.Length; i++) { - if (args[i].StartsWith("--")) + if (args[i].StartsWith("--", StringComparison.Ordinal)) { if (args[i].Equals("--quiet")) { script = false; } - else if (args[i].StartsWith("--properties=")) + else if (args[i].StartsWith("--properties=", StringComparison.Ordinal)) { throw new NotSupportedException("No properties file for .NET, use app.config instead"); //propFile = args[i].Substring( 13 ); } - else if (args[i].StartsWith("--config=")) + else if (args[i].StartsWith("--config=", StringComparison.Ordinal)) { cfg.Configure(args[i].Substring(9)); } - else if (args[i].StartsWith("--text")) + else if (args[i].StartsWith("--text", StringComparison.Ordinal)) { doUpdate = false; } - else if (args[i].StartsWith("--naming=")) + else if (args[i].StartsWith("--naming=", StringComparison.Ordinal)) { cfg.SetNamingStrategy( (INamingStrategy) diff --git a/src/NHibernate/Async/Tool/hbm2ddl/SchemaValidator.cs b/src/NHibernate/Async/Tool/hbm2ddl/SchemaValidator.cs index 844de97b4d3..adce3ee8e02 100644 --- a/src/NHibernate/Async/Tool/hbm2ddl/SchemaValidator.cs +++ b/src/NHibernate/Async/Tool/hbm2ddl/SchemaValidator.cs @@ -33,18 +33,18 @@ public partial class SchemaValidator for (int i = 0; i < args.Length; i++) { - if (args[i].StartsWith("--")) + if (args[i].StartsWith("--", StringComparison.Ordinal)) { //if (args[i].StartsWith("--properties=")) //{ // propFile = args[i].Substring(13); //} //else - if (args[i].StartsWith("--config=")) + if (args[i].StartsWith("--config=", StringComparison.Ordinal)) { cfg.Configure(args[i].Substring(9)); } - else if (args[i].StartsWith("--naming=")) + else if (args[i].StartsWith("--naming=", StringComparison.Ordinal)) { cfg.SetNamingStrategy( (INamingStrategy) @@ -113,4 +113,4 @@ public partial class SchemaValidator } } } -} \ No newline at end of file +} diff --git a/src/NHibernate/Cfg/ConfigurationSchema/ClassCacheConfiguration.cs b/src/NHibernate/Cfg/ConfigurationSchema/ClassCacheConfiguration.cs index 4c4b080cee9..b5ca288c32b 100644 --- a/src/NHibernate/Cfg/ConfigurationSchema/ClassCacheConfiguration.cs +++ b/src/NHibernate/Cfg/ConfigurationSchema/ClassCacheConfiguration.cs @@ -89,7 +89,7 @@ private void Parse(XPathNavigator classCacheElement) switch (classCacheElement.Name) { case "class": - if (classCacheElement.Value.Trim().Length == 0) + if (string.IsNullOrWhiteSpace(classCacheElement.Value)) throw new HibernateConfigException("Invalid class-cache element; the attribute must be assigned with no empty value"); clazz = classCacheElement.Value; break; diff --git a/src/NHibernate/Cfg/ConfigurationSchema/CollectionCacheConfiguration.cs b/src/NHibernate/Cfg/ConfigurationSchema/CollectionCacheConfiguration.cs index 5d01b808e0c..a87af921140 100644 --- a/src/NHibernate/Cfg/ConfigurationSchema/CollectionCacheConfiguration.cs +++ b/src/NHibernate/Cfg/ConfigurationSchema/CollectionCacheConfiguration.cs @@ -49,7 +49,7 @@ private void Parse(XPathNavigator collectionCacheElement) switch (collectionCacheElement.Name) { case "collection": - if (collectionCacheElement.Value.Trim().Length == 0) + if (string.IsNullOrWhiteSpace(collectionCacheElement.Value)) throw new HibernateConfigException("Invalid collection-cache element; the attribute must be assigned with no empty value"); collection = collectionCacheElement.Value; break; diff --git a/src/NHibernate/Cfg/ConfigurationSchema/ListenerConfiguration.cs b/src/NHibernate/Cfg/ConfigurationSchema/ListenerConfiguration.cs index bde72ba5d7f..4a4fc977cb7 100644 --- a/src/NHibernate/Cfg/ConfigurationSchema/ListenerConfiguration.cs +++ b/src/NHibernate/Cfg/ConfigurationSchema/ListenerConfiguration.cs @@ -53,7 +53,7 @@ private void Parse(XPathNavigator listenerElement) switch (listenerElement.Name) { case "class": - if (listenerElement.Value.Trim().Length == 0) + if (string.IsNullOrWhiteSpace(listenerElement.Value)) throw new HibernateConfigException("Invalid listener element; the attribute must be assigned with no empty value"); clazz = listenerElement.Value; break; diff --git a/src/NHibernate/Cfg/Hbm2ddlKeyWords.cs b/src/NHibernate/Cfg/Hbm2ddlKeyWords.cs index 8114a642b67..2c3e541f698 100644 --- a/src/NHibernate/Cfg/Hbm2ddlKeyWords.cs +++ b/src/NHibernate/Cfg/Hbm2ddlKeyWords.cs @@ -1,3 +1,5 @@ +using System; + namespace NHibernate.Cfg { public class Hbm2DDLKeyWords @@ -33,7 +35,7 @@ public override bool Equals(object obj) public bool Equals(string other) { - return value.Equals(other); + return value.Equals(other, StringComparison.OrdinalIgnoreCase); } public bool Equals(Hbm2DDLKeyWords other) @@ -82,4 +84,4 @@ public override int GetHashCode() public static Hbm2DDLKeyWords Keywords = new Hbm2DDLKeyWords("keywords"); public static Hbm2DDLKeyWords AutoQuote = new Hbm2DDLKeyWords("auto-quote"); } -} \ No newline at end of file +} diff --git a/src/NHibernate/Cfg/Mappings.cs b/src/NHibernate/Cfg/Mappings.cs index 02d5d89fe45..bc1fc54c050 100644 --- a/src/NHibernate/Cfg/Mappings.cs +++ b/src/NHibernate/Cfg/Mappings.cs @@ -19,7 +19,7 @@ public class Mappings [Serializable] public class ColumnNames { - public readonly IDictionary logicalToPhysical = new Dictionary(); + public readonly IDictionary logicalToPhysical = new Dictionary(StringComparer.OrdinalIgnoreCase); public readonly IDictionary physicalToLogical = new Dictionary(); } @@ -536,8 +536,8 @@ public void AddColumnBinding(string logicalName, Column finalColumn, Table table } string oldFinalName; - binding.logicalToPhysical.TryGetValue(logicalName.ToLowerInvariant(), out oldFinalName); - binding.logicalToPhysical[logicalName.ToLowerInvariant()] = finalColumn.GetQuotedName(); + binding.logicalToPhysical.TryGetValue(logicalName, out oldFinalName); + binding.logicalToPhysical[logicalName] = finalColumn.GetQuotedName(); if (oldFinalName != null && !(finalColumn.IsQuoted ? oldFinalName.Equals(finalColumn.GetQuotedName()) @@ -584,7 +584,6 @@ public string GetLogicalColumnName(string physicalName, Table table) public string GetPhysicalColumnName(string logicalName, Table table) { - logicalName = logicalName.ToLowerInvariant(); string finalName = null; Table currentTable = table; do diff --git a/src/NHibernate/Cfg/SettingsFactory.cs b/src/NHibernate/Cfg/SettingsFactory.cs index 612ac4a2acb..d933a8b6240 100644 --- a/src/NHibernate/Cfg/SettingsFactory.cs +++ b/src/NHibernate/Cfg/SettingsFactory.cs @@ -167,7 +167,6 @@ public Settings BuildSettings(IDictionary properties) } string autoKeyWordsImport = PropertiesHelper.GetString(Environment.Hbm2ddlKeyWords, properties, "not-defined"); - autoKeyWordsImport = autoKeyWordsImport.ToLowerInvariant(); if (autoKeyWordsImport == Hbm2DDLKeyWords.None) { settings.IsKeywordsImportEnabled = false; diff --git a/src/NHibernate/Dialect/Function/ClassicAggregateFunction.cs b/src/NHibernate/Dialect/Function/ClassicAggregateFunction.cs index 323c87334f0..61445fe1a8c 100644 --- a/src/NHibernate/Dialect/Function/ClassicAggregateFunction.cs +++ b/src/NHibernate/Dialect/Function/ClassicAggregateFunction.cs @@ -106,8 +106,8 @@ bool IFunctionGrammar.IsSeparator(string token) bool IFunctionGrammar.IsKnownArgument(string token) { - return "distinct".Equals(token.ToLowerInvariant()) || - "all".Equals(token.ToLowerInvariant()); + return "distinct".Equals(token, StringComparison.OrdinalIgnoreCase) || + "all".Equals(token, StringComparison.OrdinalIgnoreCase); } #endregion diff --git a/src/NHibernate/Dialect/Function/SQLFunctionRegistry.cs b/src/NHibernate/Dialect/Function/SQLFunctionRegistry.cs index 858b6227440..701dadd64f7 100644 --- a/src/NHibernate/Dialect/Function/SQLFunctionRegistry.cs +++ b/src/NHibernate/Dialect/Function/SQLFunctionRegistry.cs @@ -12,9 +12,12 @@ public SQLFunctionRegistry(Dialect dialect, IDictionary us { this.dialect = dialect; this.userFunctions = new Dictionary(userFunctions, - StringComparer.InvariantCultureIgnoreCase); + StringComparer.OrdinalIgnoreCase); } + /// + /// Find function by function name ignoring case + /// public ISQLFunction FindSQLFunction(string functionName) { ISQLFunction result; diff --git a/src/NHibernate/Dialect/MsSqlCeDialect.cs b/src/NHibernate/Dialect/MsSqlCeDialect.cs index 4b4f4bb9e1b..8c6a2e94e1b 100644 --- a/src/NHibernate/Dialect/MsSqlCeDialect.cs +++ b/src/NHibernate/Dialect/MsSqlCeDialect.cs @@ -287,12 +287,12 @@ public override string Qualify(string catalog, string schema, string table) var tableName = new StringBuilder(); if (!string.IsNullOrEmpty(schema)) { - if (schema.StartsWith(OpenQuote.ToString())) + if (schema.StartsWith(OpenQuote)) { schema = schema.Substring(1, schema.Length - 1); quoted = true; } - if (schema.EndsWith(CloseQuote.ToString())) + if (schema.EndsWith(CloseQuote)) { schema = schema.Substring(0, schema.Length - 1); quoted = true; @@ -300,12 +300,12 @@ public override string Qualify(string catalog, string schema, string table) tableName.Append(schema).Append(StringHelper.Underscore); } - if (table.StartsWith(OpenQuote.ToString())) + if (table.StartsWith(OpenQuote)) { table = table.Substring(1, table.Length - 1); quoted = true; } - if (table.EndsWith(CloseQuote.ToString())) + if (table.EndsWith(CloseQuote)) { table = table.Substring(0, table.Length - 1); quoted = true; diff --git a/src/NHibernate/Dialect/SQLiteDialect.cs b/src/NHibernate/Dialect/SQLiteDialect.cs index 87904958221..4a0bb5390ff 100644 --- a/src/NHibernate/Dialect/SQLiteDialect.cs +++ b/src/NHibernate/Dialect/SQLiteDialect.cs @@ -277,12 +277,12 @@ public override string Qualify(string catalog, string schema, string table) if (!string.IsNullOrEmpty(catalog)) { - if (catalog.StartsWith(OpenQuote.ToString())) + if (catalog.StartsWith(OpenQuote)) { catalog = catalog.Substring(1, catalog.Length - 1); quoted = true; } - if (catalog.EndsWith(CloseQuote.ToString())) + if (catalog.EndsWith(CloseQuote)) { catalog = catalog.Substring(0, catalog.Length - 1); quoted = true; @@ -291,12 +291,12 @@ public override string Qualify(string catalog, string schema, string table) } if (!string.IsNullOrEmpty(schema)) { - if (schema.StartsWith(OpenQuote.ToString())) + if (schema.StartsWith(OpenQuote)) { schema = schema.Substring(1, schema.Length - 1); quoted = true; } - if (schema.EndsWith(CloseQuote.ToString())) + if (schema.EndsWith(CloseQuote)) { schema = schema.Substring(0, schema.Length - 1); quoted = true; @@ -304,12 +304,12 @@ public override string Qualify(string catalog, string schema, string table) qualifiedName.Append(schema).Append(StringHelper.Underscore); } - if (table.StartsWith(OpenQuote.ToString())) + if (table.StartsWith(OpenQuote)) { table = table.Substring(1, table.Length - 1); quoted = true; } - if (table.EndsWith(CloseQuote.ToString())) + if (table.EndsWith(CloseQuote)) { table = table.Substring(0, table.Length - 1); quoted = true; @@ -420,7 +420,7 @@ protected class SQLiteCastFunction : CastFunction protected override bool CastingIsRequired(string sqlType) { // SQLite doesn't support casting to datetime types. It assumes you want an integer and destroys the date string. - if (sqlType.ToLowerInvariant().Contains("date") || sqlType.ToLowerInvariant().Contains("time")) + if (StringHelper.ContainsCaseInsensitive(sqlType, "date") || StringHelper.ContainsCaseInsensitive(sqlType, "time")) return false; return true; } diff --git a/src/NHibernate/Dialect/Schema/AbstractTableMetadata.cs b/src/NHibernate/Dialect/Schema/AbstractTableMetadata.cs index d76092ab569..193b5ad2b49 100644 --- a/src/NHibernate/Dialect/Schema/AbstractTableMetadata.cs +++ b/src/NHibernate/Dialect/Schema/AbstractTableMetadata.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Data; using NHibernate.Util; @@ -10,9 +11,9 @@ public abstract class AbstractTableMetadata : ITableMetadata private string catalog; private string schema; private string name; - private readonly Dictionary columns = new Dictionary(); - private readonly Dictionary foreignKeys = new Dictionary(); - private readonly Dictionary indexes = new Dictionary(); + private readonly Dictionary columns = new Dictionary(StringComparer.OrdinalIgnoreCase); + private readonly Dictionary foreignKeys = new Dictionary(StringComparer.OrdinalIgnoreCase); + private readonly Dictionary indexes = new Dictionary(StringComparer.OrdinalIgnoreCase); public AbstractTableMetadata(DataRow rs, IDataBaseSchema meta, bool extras) { @@ -71,21 +72,21 @@ public override string ToString() public IColumnMetadata GetColumnMetadata(string columnName) { IColumnMetadata result; - columns.TryGetValue(columnName.ToLowerInvariant(), out result); + columns.TryGetValue(columnName, out result); return result; } public IForeignKeyMetadata GetForeignKeyMetadata(string keyName) { IForeignKeyMetadata result; - foreignKeys.TryGetValue(keyName.ToLowerInvariant(), out result); + foreignKeys.TryGetValue(keyName, out result); return result; } public IIndexMetadata GetIndexMetadata(string indexName) { IIndexMetadata result; - indexes.TryGetValue(indexName.ToLowerInvariant(), out result); + indexes.TryGetValue(indexName, out result); return result; } @@ -105,7 +106,7 @@ private void AddForeignKey(DataRow rs, IDataBaseSchema meta) if (info == null) { info = GetForeignKeyMetadata(rs); - foreignKeys[info.Name.ToLowerInvariant()] = info; + foreignKeys[info.Name] = info; } foreach (DataRow row in meta.GetIndexColumns(catalog, schema, name, fk).Rows) @@ -124,7 +125,7 @@ private void AddIndex(DataRow rs, IDataBaseSchema meta) if (info == null) { info = GetIndexMetadata(rs); - indexes[info.Name.ToLowerInvariant()] = info; + indexes[info.Name] = info; } foreach (DataRow row in meta.GetIndexColumns(catalog, schema, name, index).Rows) @@ -142,7 +143,7 @@ private void AddColumn(DataRow rs) if (GetColumnMetadata(column) == null) { IColumnMetadata info = GetColumnMetadata(rs); - columns[info.Name.ToLowerInvariant()] = info; + columns[info.Name] = info; } } diff --git a/src/NHibernate/Engine/CascadeStyle.cs b/src/NHibernate/Engine/CascadeStyle.cs index 47c60033516..9bb5fb97ec9 100644 --- a/src/NHibernate/Engine/CascadeStyle.cs +++ b/src/NHibernate/Engine/CascadeStyle.cs @@ -78,7 +78,7 @@ public virtual bool HasOrphanDelete #region Static helper methods - private static readonly Dictionary Styles = new Dictionary(); + private static readonly Dictionary Styles = new Dictionary(StringComparer.OrdinalIgnoreCase); private static readonly Dictionary AliasByStyle = new Dictionary(); /// Factory method for obtaining named cascade styles diff --git a/src/NHibernate/Engine/JoinSequence.cs b/src/NHibernate/Engine/JoinSequence.cs index 5036b97ea48..0241d293db5 100644 --- a/src/NHibernate/Engine/JoinSequence.cs +++ b/src/NHibernate/Engine/JoinSequence.cs @@ -248,7 +248,7 @@ private void AddExtraJoins(JoinFragment joinFragment, string alias, IJoinable jo public JoinSequence AddCondition(SqlString condition) { - if (condition.Trim().Length != 0) + if (!condition.IsEmptyOrWhitespace()) { if (!condition.StartsWithCaseInsensitive(" and ")) conditions.Add(" and "); @@ -314,4 +314,4 @@ public interface ISelector bool IncludeSubclasses(string alias); } } -} \ No newline at end of file +} diff --git a/src/NHibernate/Hql/Ast/ANTLR/CollectionProperties.cs b/src/NHibernate/Hql/Ast/ANTLR/CollectionProperties.cs index 34e7ddc45c3..bf1ec84156c 100644 --- a/src/NHibernate/Hql/Ast/ANTLR/CollectionProperties.cs +++ b/src/NHibernate/Hql/Ast/ANTLR/CollectionProperties.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using NHibernate.Persister.Collection; namespace NHibernate.Hql.Ast.ANTLR @@ -11,34 +12,39 @@ namespace NHibernate.Hql.Ast.ANTLR internal static class CollectionProperties { - public static Dictionary HQL_COLLECTION_PROPERTIES; - - private static readonly string COLLECTION_INDEX_LOWER = CollectionPropertyNames.Index.ToLowerInvariant(); + public static readonly Dictionary HQL_COLLECTION_PROPERTIES = new Dictionary(StringComparer.OrdinalIgnoreCase); static CollectionProperties() { - HQL_COLLECTION_PROPERTIES = new Dictionary(); - HQL_COLLECTION_PROPERTIES.Add(CollectionPropertyNames.Elements.ToLowerInvariant(), CollectionPropertyNames.Elements); - HQL_COLLECTION_PROPERTIES.Add(CollectionPropertyNames.Indices.ToLowerInvariant(), CollectionPropertyNames.Indices); - HQL_COLLECTION_PROPERTIES.Add(CollectionPropertyNames.Size.ToLowerInvariant(), CollectionPropertyNames.Size); - HQL_COLLECTION_PROPERTIES.Add(CollectionPropertyNames.MaxIndex.ToLowerInvariant(), CollectionPropertyNames.MaxIndex); - HQL_COLLECTION_PROPERTIES.Add(CollectionPropertyNames.MinIndex.ToLowerInvariant(), CollectionPropertyNames.MinIndex); - HQL_COLLECTION_PROPERTIES.Add(CollectionPropertyNames.MaxElement.ToLowerInvariant(), CollectionPropertyNames.MaxElement); - HQL_COLLECTION_PROPERTIES.Add(CollectionPropertyNames.MinElement.ToLowerInvariant(), CollectionPropertyNames.MinElement); - HQL_COLLECTION_PROPERTIES.Add(COLLECTION_INDEX_LOWER, CollectionPropertyNames.Index); + Init( + CollectionPropertyNames.Elements, + CollectionPropertyNames.Indices, + CollectionPropertyNames.Size, + CollectionPropertyNames.MaxIndex, + CollectionPropertyNames.MinIndex, + CollectionPropertyNames.MaxElement, + CollectionPropertyNames.MinElement, + CollectionPropertyNames.Index); + } + + private static void Init(params string[] names) + { + foreach (var name in names) + { + HQL_COLLECTION_PROPERTIES[name] = name; + } } public static bool IsCollectionProperty(string name) { - string key = name.ToLowerInvariant(); // CollectionPropertyMapping processes everything except 'index'. - if (COLLECTION_INDEX_LOWER == key) + if (string.Equals(CollectionPropertyNames.Index, name, StringComparison.OrdinalIgnoreCase)) { return false; } else { - return HQL_COLLECTION_PROPERTIES.ContainsKey(key); + return HQL_COLLECTION_PROPERTIES.ContainsKey(name); } } @@ -49,8 +55,7 @@ public static string GetNormalizedPropertyName(string name) public static bool IsAnyCollectionProperty(string name) { - string key = name.ToLowerInvariant(); - return HQL_COLLECTION_PROPERTIES.ContainsKey(key); + return HQL_COLLECTION_PROPERTIES.ContainsKey(name); } } } diff --git a/src/NHibernate/Hql/Ast/ANTLR/Hql.g b/src/NHibernate/Hql/Ast/ANTLR/Hql.g index 7d3c2c0222c..bb194bf0f91 100644 --- a/src/NHibernate/Hql/Ast/ANTLR/Hql.g +++ b/src/NHibernate/Hql/Ast/ANTLR/Hql.g @@ -768,11 +768,11 @@ NUM_INT : '.' {_type = DOT;} ( ('0'..'9')+ (EXPONENT)? (f1=FLOAT_SUFFIX {t=f1;})? { - if (t != null && t.Text.ToUpperInvariant().IndexOf('F')>=0) + if (t != null && t.Text.IndexOf("F", System.StringComparison.OrdinalIgnoreCase)>=0) { _type = NUM_FLOAT; } - else if (t != null && t.Text.ToUpperInvariant().IndexOf('M')>=0) + else if (t != null && t.Text.IndexOf("M", System.StringComparison.OrdinalIgnoreCase)>=0) { _type = NUM_DECIMAL; } @@ -806,11 +806,11 @@ NUM_INT | f4=FLOAT_SUFFIX {t=f4;} ) { - if (t != null && t.Text.ToUpperInvariant().IndexOf('F') >= 0) + if (t != null && t.Text.IndexOf("F", System.StringComparison.OrdinalIgnoreCase) >= 0) { _type = NUM_FLOAT; } - else if (t != null && t.Text.ToUpperInvariant().IndexOf('M')>=0) + else if (t != null && t.Text.IndexOf("M", System.StringComparison.OrdinalIgnoreCase)>=0) { _type = NUM_DECIMAL; } diff --git a/src/NHibernate/Hql/Ast/ANTLR/SessionFactoryHelperExtensions.cs b/src/NHibernate/Hql/Ast/ANTLR/SessionFactoryHelperExtensions.cs index 142c8a0c4ab..4681b1d4892 100644 --- a/src/NHibernate/Hql/Ast/ANTLR/SessionFactoryHelperExtensions.cs +++ b/src/NHibernate/Hql/Ast/ANTLR/SessionFactoryHelperExtensions.cs @@ -42,7 +42,7 @@ public ISessionFactoryImplementor Factory /// The sql function, or null if not found. public ISQLFunction FindSQLFunction(string functionName) { - return _sfi.SQLFunctionRegistry.FindSQLFunction(functionName.ToLowerInvariant()); + return _sfi.SQLFunctionRegistry.FindSQLFunction(functionName); } /// diff --git a/src/NHibernate/Hql/Ast/ANTLR/SqlGenerator.cs b/src/NHibernate/Hql/Ast/ANTLR/SqlGenerator.cs index d30f872da8b..a820a08cb01 100644 --- a/src/NHibernate/Hql/Ast/ANTLR/SqlGenerator.cs +++ b/src/NHibernate/Hql/Ast/ANTLR/SqlGenerator.cs @@ -384,7 +384,7 @@ private void Take(IASTNode node) private void BeginBitwiseOp(string op) { - var function = sessionFactory.SQLFunctionRegistry.FindSQLFunction(op.ToLowerInvariant()); + var function = sessionFactory.SQLFunctionRegistry.FindSQLFunction(op); if (function == null) return; @@ -394,7 +394,7 @@ private void BeginBitwiseOp(string op) private void EndBitwiseOp(string op) { - ISQLFunction function = sessionFactory.SQLFunctionRegistry.FindSQLFunction(op.ToLowerInvariant()); + ISQLFunction function = sessionFactory.SQLFunctionRegistry.FindSQLFunction(op); if (function == null) return; @@ -617,4 +617,4 @@ public IList Args #endregion } -} \ No newline at end of file +} diff --git a/src/NHibernate/Hql/Ast/ANTLR/Tree/AbstractNullnessCheckNode.cs b/src/NHibernate/Hql/Ast/ANTLR/Tree/AbstractNullnessCheckNode.cs index c4a2ba78fc6..c836269f0e3 100644 --- a/src/NHibernate/Hql/Ast/ANTLR/Tree/AbstractNullnessCheckNode.cs +++ b/src/NHibernate/Hql/Ast/ANTLR/Tree/AbstractNullnessCheckNode.cs @@ -138,11 +138,11 @@ private static string[] ExtractMutationTexts(IASTNode operand, int count) else if ( operand is SqlNode ) { string nodeText = operand.Text; - if ( nodeText.StartsWith( "(" ) ) + if ( nodeText.StartsWith( '(' ) ) { nodeText = nodeText.Substring( 1 ); } - if ( nodeText.EndsWith( ")" ) ) + if ( nodeText.EndsWith( ')' ) ) { nodeText = nodeText.Substring( 0, nodeText.Length - 1 ); } diff --git a/src/NHibernate/Hql/Ast/ANTLR/Tree/BinaryLogicOperatorNode.cs b/src/NHibernate/Hql/Ast/ANTLR/Tree/BinaryLogicOperatorNode.cs index 827f9b1886a..5dfb42ca7a9 100644 --- a/src/NHibernate/Hql/Ast/ANTLR/Tree/BinaryLogicOperatorNode.cs +++ b/src/NHibernate/Hql/Ast/ANTLR/Tree/BinaryLogicOperatorNode.cs @@ -219,11 +219,11 @@ private static string[] ExtractMutationTexts(IASTNode operand, int count) { string nodeText = operand.Text; - if (nodeText.StartsWith("(")) + if (nodeText.StartsWith('(')) { nodeText = nodeText.Substring(1); } - if (nodeText.EndsWith(")")) + if (nodeText.EndsWith(')')) { nodeText = nodeText.Substring(0, nodeText.Length - 1); } diff --git a/src/NHibernate/Hql/Ast/ANTLR/Tree/CollectionFunction.cs b/src/NHibernate/Hql/Ast/ANTLR/Tree/CollectionFunction.cs index aaaa7bdc547..329049450d0 100644 --- a/src/NHibernate/Hql/Ast/ANTLR/Tree/CollectionFunction.cs +++ b/src/NHibernate/Hql/Ast/ANTLR/Tree/CollectionFunction.cs @@ -1,5 +1,6 @@ using System; using Antlr.Runtime; +using NHibernate.Util; namespace NHibernate.Hql.Ast.ANTLR.Tree { @@ -37,7 +38,7 @@ protected override void PrepareSelectColumns(String[] selectColumns) { // we need to strip off the embedded parens so that sql-gen does not double these up String subselect = selectColumns[0].Trim(); - if ( subselect.StartsWith( "(") && subselect.EndsWith( ")" ) ) + if ( subselect.StartsWith( '(') && subselect.EndsWith( ')' ) ) { subselect = subselect.Substring( 1, subselect.Length -2 ); } diff --git a/src/NHibernate/Hql/Ast/ANTLR/Tree/ConstructorNode.cs b/src/NHibernate/Hql/Ast/ANTLR/Tree/ConstructorNode.cs index 0759c83ad7c..925c0452f88 100644 --- a/src/NHibernate/Hql/Ast/ANTLR/Tree/ConstructorNode.cs +++ b/src/NHibernate/Hql/Ast/ANTLR/Tree/ConstructorNode.cs @@ -116,11 +116,11 @@ public void Prepare() _constructorArgumentTypes = ResolveConstructorArgumentTypes(); string path = ( ( IPathNode ) GetChild(0) ).Path; - if (path.ToLowerInvariant() == "map") + if (string.Equals(path, "map", StringComparison.OrdinalIgnoreCase)) { _isMap = true; } - else if (path.ToLowerInvariant() == "list") + else if (string.Equals(path, "list", StringComparison.OrdinalIgnoreCase)) { _isList = true; } diff --git a/src/NHibernate/Hql/Ast/ANTLR/Util/LiteralProcessor.cs b/src/NHibernate/Hql/Ast/ANTLR/Util/LiteralProcessor.cs index 8e84bd4ff76..18c93dc3903 100644 --- a/src/NHibernate/Hql/Ast/ANTLR/Util/LiteralProcessor.cs +++ b/src/NHibernate/Hql/Ast/ANTLR/Util/LiteralProcessor.cs @@ -123,9 +123,9 @@ public void ProcessBoolean(IASTNode constant) { constant.Text = replacement; } - else + else { - bool value = "true" == constant.Text.ToLowerInvariant(); + bool value = string.Equals("true", constant.Text, StringComparison.OrdinalIgnoreCase); Dialect.Dialect dialect = _walker.SessionFactoryHelper.Factory.Dialect; constant.Text = dialect.ToBooleanValueString(value); } diff --git a/src/NHibernate/Hql/Ast/ANTLR/Util/SyntheticAndFactory.cs b/src/NHibernate/Hql/Ast/ANTLR/Util/SyntheticAndFactory.cs index 2fa366fb1e3..ee44d3b88c5 100644 --- a/src/NHibernate/Hql/Ast/ANTLR/Util/SyntheticAndFactory.cs +++ b/src/NHibernate/Hql/Ast/ANTLR/Util/SyntheticAndFactory.cs @@ -152,7 +152,7 @@ public virtual void AddDiscriminatorWhereFragment(IRestrictableStatement stateme { return; } - if (whereFragment.StartsWith("and")) + if (whereFragment.StartsWith("and", StringComparison.Ordinal)) { whereFragment = whereFragment.Substring(4); } diff --git a/src/NHibernate/Loader/Custom/Sql/SQLQueryParser.cs b/src/NHibernate/Loader/Custom/Sql/SQLQueryParser.cs index 4935d6bfeeb..95943273a32 100644 --- a/src/NHibernate/Loader/Custom/Sql/SQLQueryParser.cs +++ b/src/NHibernate/Loader/Custom/Sql/SQLQueryParser.cs @@ -1,3 +1,4 @@ +using System; using System.Collections; using System.Collections.Generic; using System.Linq; @@ -153,7 +154,7 @@ private string ResolveCollectionProperties(string aliasName, string propertyName : selectFragment; } - if (propertyName.StartsWith("element.")) + if (propertyName.StartsWith("element.", StringComparison.Ordinal)) { string elementPropertyName = propertyName.Substring("element.".Length); diff --git a/src/NHibernate/Loader/Custom/Sql/SQLQueryReturnProcessor.cs b/src/NHibernate/Loader/Custom/Sql/SQLQueryReturnProcessor.cs index 91ac30308b4..94ce34aa2d9 100644 --- a/src/NHibernate/Loader/Custom/Sql/SQLQueryReturnProcessor.cs +++ b/src/NHibernate/Loader/Custom/Sql/SQLQueryReturnProcessor.cs @@ -1,3 +1,4 @@ +using System; using System.Collections; using System.Collections.Generic; @@ -228,7 +229,7 @@ private IDictionary Filter(IDictionary prope foreach (KeyValuePair element in propertyResults) { string path = element.Key; - if (path.StartsWith(keyPrefix)) + if (path.StartsWith(keyPrefix, StringComparison.Ordinal)) { result[path.Substring(keyPrefix.Length)] = element.Value; } diff --git a/src/NHibernate/Loader/GeneratedCollectionAliases.cs b/src/NHibernate/Loader/GeneratedCollectionAliases.cs index e42f631c070..dfed501a48c 100644 --- a/src/NHibernate/Loader/GeneratedCollectionAliases.cs +++ b/src/NHibernate/Loader/GeneratedCollectionAliases.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using NHibernate.Persister.Collection; using NHibernate.Util; @@ -44,7 +45,7 @@ private string[] GetUserProvidedCompositeElementAliases(string[] defaultAliases) var aliases = new List(); foreach (KeyValuePair userProvidedAlias in userProvidedAliases) { - if (userProvidedAlias.Key.StartsWith("element.")) + if (userProvidedAlias.Key.StartsWith("element.", StringComparison.Ordinal)) { aliases.AddRange(userProvidedAlias.Value); } diff --git a/src/NHibernate/Loader/JoinWalker.cs b/src/NHibernate/Loader/JoinWalker.cs index 4dcdd15f832..0f97ec6e0d8 100644 --- a/src/NHibernate/Loader/JoinWalker.cs +++ b/src/NHibernate/Loader/JoinWalker.cs @@ -913,7 +913,7 @@ public string SelectString(IList associations) joinable.SelectFragment(next == null ? null : next.Joinable, next == null ? null : next.RHSAlias, join.RHSAlias, entitySuffix, collectionSuffix, join.JoinType == JoinType.LeftOuterJoin); - if (selectFragment.Trim().Length > 0) + if (!string.IsNullOrWhiteSpace(selectFragment)) { buf.Add(StringHelper.CommaSpace) .Add(selectFragment); diff --git a/src/NHibernate/Logging.cs b/src/NHibernate/Logging.cs index ebccab6bee0..9af1b93590d 100644 --- a/src/NHibernate/Logging.cs +++ b/src/NHibernate/Logging.cs @@ -113,7 +113,7 @@ public static INHibernateLogger For(System.Type type) private static string GetNhibernateLoggerClass() { - var nhibernateLogger = ConfigurationManager.AppSettings.Keys.Cast().FirstOrDefault(k => nhibernateLoggerConfKey.Equals(k.ToLowerInvariant())); + var nhibernateLogger = ConfigurationManager.AppSettings.Keys.Cast().FirstOrDefault(k => nhibernateLoggerConfKey.Equals(k, StringComparison.OrdinalIgnoreCase)); string nhibernateLoggerClass = null; if (string.IsNullOrEmpty(nhibernateLogger)) { diff --git a/src/NHibernate/Mapping/ByCode/Impl/DefaultCandidatePersistentMembersProvider.cs b/src/NHibernate/Mapping/ByCode/Impl/DefaultCandidatePersistentMembersProvider.cs index 1e4118de76a..024a91d7d03 100644 --- a/src/NHibernate/Mapping/ByCode/Impl/DefaultCandidatePersistentMembersProvider.cs +++ b/src/NHibernate/Mapping/ByCode/Impl/DefaultCandidatePersistentMembersProvider.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; +using NHibernate.Util; namespace NHibernate.Mapping.ByCode.Impl { @@ -44,7 +45,7 @@ public IEnumerable GetSubEntityMembers(System.Type entityClass, Syst protected IEnumerable GetUserDeclaredFields(System.Type type) { // can't find another way to exclude fields generated by the compiler (for both auto-properties and anonymous-types) - return type.GetFields(ClassFieldsBindingFlags).Where(x=> !x.Name.StartsWith("<")); + return type.GetFields(ClassFieldsBindingFlags).Where(x=> !x.Name.StartsWith('<')); } public IEnumerable GetComponentMembers(System.Type componentClass) @@ -93,4 +94,4 @@ public int GetHashCode(MemberInfo obj) #endregion } -} \ No newline at end of file +} diff --git a/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs b/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs index 21cfa2cc9b5..992762eb458 100644 --- a/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs +++ b/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs @@ -353,10 +353,10 @@ protected bool CanReadCantWriteInBaseType(PropertyInfo property) protected bool MatchPoIdPattern(MemberInfo subject) { var name = subject.Name; - return name.Equals("id", StringComparison.InvariantCultureIgnoreCase) - || name.Equals("poid", StringComparison.InvariantCultureIgnoreCase) - || name.Equals("oid", StringComparison.InvariantCultureIgnoreCase) - || (name.StartsWith(subject.DeclaringType.Name) && name.Equals(subject.DeclaringType.Name + "id", StringComparison.InvariantCultureIgnoreCase)); + return name.Equals("id", StringComparison.OrdinalIgnoreCase) + || name.Equals("poid", StringComparison.OrdinalIgnoreCase) + || name.Equals("oid", StringComparison.OrdinalIgnoreCase) + || (name.StartsWith(subject.DeclaringType.Name, StringComparison.Ordinal) && name.Equals(subject.DeclaringType.Name + "id", StringComparison.OrdinalIgnoreCase)); } protected bool MatchComponentPattern(System.Type subject) @@ -369,7 +369,7 @@ protected bool MatchComponentPattern(System.Type subject) return false; } var modelInspector = (IModelInspector) this; - return !subject.IsEnum && (subject.Namespace == null || !subject.Namespace.StartsWith("System")) /* hack */ + return !subject.IsEnum && (subject.Namespace == null || !subject.Namespace.StartsWith("System", StringComparison.Ordinal)) /* hack */ && !modelInspector.IsEntity(subject) && !subject.GetProperties(flattenHierarchyMembers).Cast().Concat( subject.GetFields(flattenHierarchyMembers)).Any(m => modelInspector.IsPersistentId(m)); @@ -1083,4 +1083,4 @@ public void IsDynamicComponent(Func match) isDynamicComponent = match; } } -} \ No newline at end of file +} diff --git a/src/NHibernate/Mapping/ByCode/TypeExtensions.cs b/src/NHibernate/Mapping/ByCode/TypeExtensions.cs index 8020adedeb3..7b18cb19407 100644 --- a/src/NHibernate/Mapping/ByCode/TypeExtensions.cs +++ b/src/NHibernate/Mapping/ByCode/TypeExtensions.cs @@ -551,7 +551,7 @@ private static IEnumerable GetFieldsOfHierarchy(this System.Type typ private static IEnumerable GetUserDeclaredFields(System.Type type) { // can't find another way to exclude fields generated by the compiler (for both auto-properties and anonymous-types) - return type.GetFields(PropertiesOrFieldOfClass).Where(x => !x.Name.StartsWith("<")); + return type.GetFields(PropertiesOrFieldOfClass).Where(x => !x.Name.StartsWith('<')); } } } diff --git a/src/NHibernate/Mapping/Column.cs b/src/NHibernate/Mapping/Column.cs index d807125c547..3b051b95896 100644 --- a/src/NHibernate/Mapping/Column.cs +++ b/src/NHibernate/Mapping/Column.cs @@ -280,7 +280,7 @@ public bool Equals(Column column) if (ReferenceEquals(this, column)) return true; - return IsQuoted ? _name.Equals(column._name) : _name.ToLowerInvariant().Equals(column._name.ToLowerInvariant()); + return IsQuoted ? _name.Equals(column._name) : _name.Equals(column._name, StringComparison.OrdinalIgnoreCase); } /// diff --git a/src/NHibernate/Mapping/Property.cs b/src/NHibernate/Mapping/Property.cs index 49d29cac0a4..f02dd580574 100644 --- a/src/NHibernate/Mapping/Property.cs +++ b/src/NHibernate/Mapping/Property.cs @@ -111,7 +111,7 @@ public CascadeStyle CascadeStyle int i = 0; foreach (string token in tokens) { - styles[i++] = CascadeStyle.GetCascadeStyle(token.ToLowerInvariant().Trim()); + styles[i++] = CascadeStyle.GetCascadeStyle(token.Trim()); } if (tokens.Length == 1) return styles[0]; else return new CascadeStyle.MultipleCascadeStyle(styles); diff --git a/src/NHibernate/Mapping/Table.cs b/src/NHibernate/Mapping/Table.cs index a226336771a..9a151673e69 100644 --- a/src/NHibernate/Mapping/Table.cs +++ b/src/NHibernate/Mapping/Table.cs @@ -588,7 +588,7 @@ public string GetQuotedSchemaName(Dialect.Dialect dialect) return null; } - if (schema.StartsWith("`")) + if (schema.StartsWith('`')) { return dialect.QuoteForSchemaName(schema.Substring(1, schema.Length - 2)); } diff --git a/src/NHibernate/Proxy/DefaultDynamicProxyMethodCheckerExtensions.cs b/src/NHibernate/Proxy/DefaultDynamicProxyMethodCheckerExtensions.cs index 5b70fc9b1a6..052833230fe 100644 --- a/src/NHibernate/Proxy/DefaultDynamicProxyMethodCheckerExtensions.cs +++ b/src/NHibernate/Proxy/DefaultDynamicProxyMethodCheckerExtensions.cs @@ -11,7 +11,7 @@ public static bool IsProxiable(this MethodInfo method) { return !method.IsFinal && (method.DeclaringType != typeof(MarshalByRefObject)) - && (method.DeclaringType != typeof(object) || !"finalize".Equals(method.Name.ToLowerInvariant())) + && (method.DeclaringType != typeof(object) || !"finalize".Equals(method.Name, StringComparison.OrdinalIgnoreCase)) && ( ((method.IsPublic || method.IsFamily) && (method.IsVirtual || method.IsAbstract)) // public or protected (virtual) @@ -24,7 +24,7 @@ public static bool ShouldBeProxiable(this MethodInfo method) { // to use only for real methods (no getter/setter) return (method.DeclaringType != typeof (MarshalByRefObject)) && - (method.DeclaringType != typeof (object) || !"finalize".Equals(method.Name.ToLowerInvariant())) && + (method.DeclaringType != typeof (object) || !"finalize".Equals(method.Name, StringComparison.OrdinalIgnoreCase)) && (!(method.DeclaringType == typeof (object) && "GetType".Equals(method.Name))) && (!(method.DeclaringType == typeof (object) && "obj_address".Equals(method.Name))) && // Mono-specific method !IsDisposeMethod(method) && @@ -48,4 +48,4 @@ private static bool IsDisposeMethod(MethodInfo method) // return method.Name.Equals("Dispose") && method.IsMethodOf(typeof(IDisposable)); } } -} \ No newline at end of file +} diff --git a/src/NHibernate/Proxy/DynProxyTypeValidator.cs b/src/NHibernate/Proxy/DynProxyTypeValidator.cs index 03107f52b76..2f0370c3628 100644 --- a/src/NHibernate/Proxy/DynProxyTypeValidator.cs +++ b/src/NHibernate/Proxy/DynProxyTypeValidator.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Reflection; using NHibernate.Util; @@ -87,7 +88,7 @@ protected virtual void CheckAccessibleMembersAreVirtual(System.Type type) private bool IsPropertyMethod(MethodInfo methodInfo) { - return methodInfo.IsSpecialName && (methodInfo.Name.StartsWith("get_") || methodInfo.Name.StartsWith("set_")); + return methodInfo.IsSpecialName && (methodInfo.Name.StartsWith("get_", StringComparison.Ordinal) || methodInfo.Name.StartsWith("set_", StringComparison.Ordinal)); } protected virtual void CheckMethodIsVirtual(System.Type type, MethodInfo method) @@ -122,4 +123,4 @@ protected void CheckNotSealed(System.Type type) } } } -} \ No newline at end of file +} diff --git a/src/NHibernate/SqlCommand/JoinFragment.cs b/src/NHibernate/SqlCommand/JoinFragment.cs index c91e0a7de7a..18b249bd57f 100644 --- a/src/NHibernate/SqlCommand/JoinFragment.cs +++ b/src/NHibernate/SqlCommand/JoinFragment.cs @@ -1,3 +1,4 @@ +using System; using NHibernate.Util; namespace NHibernate.SqlCommand @@ -45,7 +46,7 @@ protected bool AddCondition(SqlStringBuilder buffer, string on) { if (StringHelper.IsNotEmpty(on)) { - if (!on.StartsWith(" and")) + if (!on.StartsWith(" and", StringComparison.Ordinal)) { buffer.Add(" and "); } diff --git a/src/NHibernate/SqlCommand/Parser/SqlTokenizerExtensions.cs b/src/NHibernate/SqlCommand/Parser/SqlTokenizerExtensions.cs index 48ad9849147..01bc98b7d02 100644 --- a/src/NHibernate/SqlCommand/Parser/SqlTokenizerExtensions.cs +++ b/src/NHibernate/SqlCommand/Parser/SqlTokenizerExtensions.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using NHibernate.Util; namespace NHibernate.SqlCommand.Parser { @@ -49,18 +50,18 @@ public static bool TryParseUntilFirstMsSqlSelectColumn(this IEnumerator 0 && + afterFrom.ToSqlString().IndexOfOrdinal(trimCondition) < 0 && + afterWhere.ToSqlString().IndexOfOrdinal(trimCondition) < 0) { - if (!condition.StartsWith(" and ")) + if (!condition.StartsWith(" and ", StringComparison.Ordinal)) { afterWhere.Add(" and "); } @@ -106,9 +106,9 @@ public override bool AddCondition(SqlString condition) { //TODO: this seems hackish var trimCondition = condition.Trim().ToString(); - if ( - afterFrom.ToString().IndexOf(trimCondition) < 0 && - afterWhere.ToString().IndexOf(trimCondition) < 0) + if (trimCondition.Length > 0 && + afterFrom.ToString().IndexOf(trimCondition, StringComparison.Ordinal) < 0 && + afterWhere.ToString().IndexOf(trimCondition, StringComparison.Ordinal) < 0) { if (!condition.StartsWithCaseInsensitive(" and ")) { @@ -132,4 +132,4 @@ public void ClearWherePart() afterWhere.Clear(); } } -} \ No newline at end of file +} diff --git a/src/NHibernate/SqlCommand/QuerySelect.cs b/src/NHibernate/SqlCommand/QuerySelect.cs index f23f86447a5..d7bd3a079e8 100644 --- a/src/NHibernate/SqlCommand/QuerySelect.cs +++ b/src/NHibernate/SqlCommand/QuerySelect.cs @@ -289,7 +289,7 @@ private static void AppendTokens(SqlStringBuilder builder, IEnumerable iter) //TODO: seems HACKish to cast between String and SqlString if (tokenString != null) { - quoted = tokenString.StartsWith("'"); + quoted = tokenString.StartsWith('\''); } else { diff --git a/src/NHibernate/SqlCommand/SqlString.cs b/src/NHibernate/SqlCommand/SqlString.cs index 0bd5bae2f7b..8665c86f18b 100644 --- a/src/NHibernate/SqlCommand/SqlString.cs +++ b/src/NHibernate/SqlCommand/SqlString.cs @@ -652,6 +652,18 @@ public SqlString SubstringStartingWithLast(string text) return lastIndex >= 0 ? Substring(lastIndex) : Empty; } + /// + /// Returns true if content is empty or white space characters only + /// + public bool IsEmptyOrWhitespace() + { + if (Length <= 0) + return true; + + GetTrimmedIndexes(out _, out var newLength); + return newLength <= 0; + } + /// /// Removes all occurrences of white space characters from the beginning and end of this instance. /// @@ -663,6 +675,14 @@ public SqlString Trim() { if (_firstPartIndex < 0) return this; + GetTrimmedIndexes(out var sqlStartIndex, out var length); + return length > 0 + ? new SqlString(this, sqlStartIndex, length) + : Empty; + } + + private void GetTrimmedIndexes(out int sqlStartIndex, out int length) + { var firstPart = _parts[_firstPartIndex]; var firstPartOffset = _sqlStartIndex - firstPart.SqlIndex; var firstPartLength = Math.Min(firstPart.Length - firstPartOffset, _length); @@ -681,11 +701,8 @@ public SqlString Trim() lastPartLength--; } - var sqlStartIndex = firstPart.SqlIndex + firstPartOffset; - var length = lastPart.SqlIndex + lastPartOffset + 1 - sqlStartIndex; - return length > 0 - ? new SqlString(this, sqlStartIndex, length) - : Empty; + sqlStartIndex = firstPart.SqlIndex + firstPartOffset; + length = lastPart.SqlIndex + lastPartOffset + 1 - sqlStartIndex; } public void Visit(ISqlStringVisitor visitor) diff --git a/src/NHibernate/SqlCommand/Template.cs b/src/NHibernate/SqlCommand/Template.cs index b1fc30c1198..efe4169ffc6 100644 --- a/src/NHibernate/SqlCommand/Template.cs +++ b/src/NHibernate/SqlCommand/Template.cs @@ -299,7 +299,7 @@ public static string RenderOrderByStringTemplate(string sqlOrderByString, Dialec private static bool IsNamedParameter(string token) { - return token.StartsWith(":"); + return token.StartsWith(':'); } private static bool IsFunctionOrKeyword(string lcToken, string nextToken, Dialect.Dialect dialect, diff --git a/src/NHibernate/Tool/hbm2ddl/SchemaExport.cs b/src/NHibernate/Tool/hbm2ddl/SchemaExport.cs index 1f4168c95f3..cb6e82557a2 100644 --- a/src/NHibernate/Tool/hbm2ddl/SchemaExport.cs +++ b/src/NHibernate/Tool/hbm2ddl/SchemaExport.cs @@ -59,7 +59,6 @@ private void Initialize() dialect = Dialect.Dialect.GetDialect(configProperties); string autoKeyWordsImport = PropertiesHelper.GetString(Environment.Hbm2ddlKeyWords, configProperties, "not-defined"); - autoKeyWordsImport = autoKeyWordsImport.ToLowerInvariant(); if (autoKeyWordsImport == Hbm2DDLKeyWords.AutoQuote) { SchemaMetadataUpdater.Update(cfg, dialect); diff --git a/src/NHibernate/Tool/hbm2ddl/SchemaUpdate.cs b/src/NHibernate/Tool/hbm2ddl/SchemaUpdate.cs index 1f275c2bfe8..6f0a02793e0 100644 --- a/src/NHibernate/Tool/hbm2ddl/SchemaUpdate.cs +++ b/src/NHibernate/Tool/hbm2ddl/SchemaUpdate.cs @@ -51,7 +51,6 @@ private void Initialize() } string autoKeyWordsImport = PropertiesHelper.GetString(Environment.Hbm2ddlKeyWords, configuration.Properties, "not-defined"); - autoKeyWordsImport = autoKeyWordsImport.ToLowerInvariant(); if (autoKeyWordsImport == Hbm2DDLKeyWords.AutoQuote) { SchemaMetadataUpdater.Update(configuration, dialect); @@ -83,26 +82,26 @@ public static void Main(string[] args) for (int i = 0; i < args.Length; i++) { - if (args[i].StartsWith("--")) + if (args[i].StartsWith("--", StringComparison.Ordinal)) { if (args[i].Equals("--quiet")) { script = false; } - else if (args[i].StartsWith("--properties=")) + else if (args[i].StartsWith("--properties=", StringComparison.Ordinal)) { throw new NotSupportedException("No properties file for .NET, use app.config instead"); //propFile = args[i].Substring( 13 ); } - else if (args[i].StartsWith("--config=")) + else if (args[i].StartsWith("--config=", StringComparison.Ordinal)) { cfg.Configure(args[i].Substring(9)); } - else if (args[i].StartsWith("--text")) + else if (args[i].StartsWith("--text", StringComparison.Ordinal)) { doUpdate = false; } - else if (args[i].StartsWith("--naming=")) + else if (args[i].StartsWith("--naming=", StringComparison.Ordinal)) { cfg.SetNamingStrategy( (INamingStrategy) diff --git a/src/NHibernate/Tool/hbm2ddl/SchemaValidator.cs b/src/NHibernate/Tool/hbm2ddl/SchemaValidator.cs index 89c11c0745a..af202a95d68 100644 --- a/src/NHibernate/Tool/hbm2ddl/SchemaValidator.cs +++ b/src/NHibernate/Tool/hbm2ddl/SchemaValidator.cs @@ -45,18 +45,18 @@ public static void Main(string[] args) for (int i = 0; i < args.Length; i++) { - if (args[i].StartsWith("--")) + if (args[i].StartsWith("--", StringComparison.Ordinal)) { //if (args[i].StartsWith("--properties=")) //{ // propFile = args[i].Substring(13); //} //else - if (args[i].StartsWith("--config=")) + if (args[i].StartsWith("--config=", StringComparison.Ordinal)) { cfg.Configure(args[i].Substring(9)); } - else if (args[i].StartsWith("--naming=")) + else if (args[i].StartsWith("--naming=", StringComparison.Ordinal)) { cfg.SetNamingStrategy( (INamingStrategy) @@ -124,4 +124,4 @@ public void Validate() } } } -} \ No newline at end of file +} diff --git a/src/NHibernate/Util/ReflectHelper.cs b/src/NHibernate/Util/ReflectHelper.cs index b7b159025e6..c1130a31507 100644 --- a/src/NHibernate/Util/ReflectHelper.cs +++ b/src/NHibernate/Util/ReflectHelper.cs @@ -767,12 +767,12 @@ public static IDictionary ToTypeParameters(this object source) public static bool IsPropertyGet(MethodInfo method) { - return method.IsSpecialName && method.Name.StartsWith("get_"); + return method.IsSpecialName && method.Name.StartsWith("get_", StringComparison.Ordinal); } public static bool IsPropertySet(MethodInfo method) { - return method.IsSpecialName && method.Name.StartsWith("set_"); + return method.IsSpecialName && method.Name.StartsWith("set_", StringComparison.Ordinal); } public static string GetPropertyName(MethodInfo method) diff --git a/src/NHibernate/Util/StringHelper.cs b/src/NHibernate/Util/StringHelper.cs index 720b9908f16..bd188d9cdd7 100644 --- a/src/NHibernate/Util/StringHelper.cs +++ b/src/NHibernate/Util/StringHelper.cs @@ -159,7 +159,7 @@ public static string ReplaceOnce(string template, string placeholder, string rep } /// - /// Just a façade for calling string.Split() + /// Just a facade for calling string.Split() /// We don't use our StringTokenizer because string.Split() is /// more efficient (but it only works when we don't want to retrieve the delimiters) /// @@ -365,8 +365,8 @@ internal static bool IsNotRoot(string qualifiedName, out string root) /// public static bool BooleanValue(string value) { - string trimmed = value.Trim().ToLowerInvariant(); - return trimmed.Equals("true") || trimmed.Equals("t"); + string trimmed = value.Trim(); + return trimmed.Equals("true", StringComparison.OrdinalIgnoreCase) || trimmed.Equals("t", StringComparison.OrdinalIgnoreCase); } private static string NullSafeToString(object obj) @@ -641,10 +641,10 @@ private static string GenerateAliasRoot(string description) public static string MoveAndToBeginning(string filter) { - if (filter.Trim().Length > 0) + if (!string.IsNullOrWhiteSpace(filter)) { filter += " and "; - if (filter.StartsWith(" and ")) + if (filter.StartsWith(" and ", StringComparison.Ordinal)) { filter = filter.Substring(4); } @@ -688,6 +688,21 @@ public static bool StartsWithCaseInsensitive(string source, string prefix) return source.StartsWith(prefix, StringComparison.InvariantCultureIgnoreCase); } + internal static bool ContainsCaseInsensitive(string source, string value) + { + return source.IndexOf(value, StringComparison.OrdinalIgnoreCase) >= 0; + } + + internal static bool StartsWith(this string source, char value) + { + return source.Length > 0 && source[0] == value; + } + + internal static bool EndsWith(this string source, char value) + { + return source.Length > 0 && source[source.Length - 1] == value; + } + /// /// Returns the interned string equal to if there is one, or /// otherwise. @@ -735,7 +750,7 @@ public static string ToLowerCase(string str) public static bool IsBackticksEnclosed(string identifier) { - return !string.IsNullOrEmpty(identifier) && identifier.StartsWith("`") && identifier.EndsWith("`"); + return !string.IsNullOrEmpty(identifier) && identifier.StartsWith('`') && identifier.EndsWith('`'); } public static string PurgeBackticksEnclosing(string identifier) diff --git a/src/NHibernate/Util/TypeNameParser.cs b/src/NHibernate/Util/TypeNameParser.cs index aca2a600549..6a56f862fb0 100644 --- a/src/NHibernate/Util/TypeNameParser.cs +++ b/src/NHibernate/Util/TypeNameParser.cs @@ -218,7 +218,7 @@ private static int FindAssemblyQualifiedNameStartIndex(string typeName) private static bool NeedDefaultNamespaceOrDefaultAssembly(string typeFullName) { - return !typeFullName.StartsWith("System."); // ugly + return !typeFullName.StartsWith("System.", StringComparison.Ordinal); // ugly } private static bool NeedDefaultNamespace(string typeFullName)