Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More optimal use of methods String.StartsWith and String.EndsWith #844

Merged
merged 1 commit into from
Jul 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions RepoDb.Core/RepoDb/Extensions/StringExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,17 +201,18 @@ private static string AsQuotedForDatabaseSchemaTableInternal(this string value,
{
if (!string.IsNullOrWhiteSpace(current))
{
if (current.StartsWith(dbSetting.OpeningQuote) && item.EndsWith(dbSetting.ClosingQuote))
if (current.StartsWith(dbSetting.OpeningQuote, StringComparison.OrdinalIgnoreCase)
&& item.EndsWith(dbSetting.ClosingQuote, StringComparison.OrdinalIgnoreCase))
{
list.Add(string.Concat(current, StringConstant.Period, item));
current = null;
}
}
else
{
if (item.StartsWith(dbSetting.OpeningQuote))
if (item.StartsWith(dbSetting.OpeningQuote, StringComparison.OrdinalIgnoreCase))
{
if (item.EndsWith(dbSetting.ClosingQuote))
if (item.EndsWith(dbSetting.ClosingQuote, StringComparison.OrdinalIgnoreCase))
{
list.Add(item.AsQuotedInternal(dbSetting));
}
Expand Down Expand Up @@ -247,11 +248,11 @@ private static string AsQuotedForDatabaseSchemaTableInternal(this string value,
private static string AsQuotedInternal(this string value,
IDbSetting dbSetting)
{
if (!value.StartsWith(dbSetting.OpeningQuote))
if (!value.StartsWith(dbSetting.OpeningQuote, StringComparison.OrdinalIgnoreCase))
{
value = string.Concat(dbSetting.OpeningQuote, value);
}
if (!value.EndsWith(dbSetting.ClosingQuote))
if (!value.EndsWith(dbSetting.ClosingQuote, StringComparison.OrdinalIgnoreCase))
{
value = string.Concat(value, dbSetting.ClosingQuote);
}
Expand Down Expand Up @@ -292,7 +293,7 @@ public static string AsParameter(this string value,
if (dbSetting != null)
{
value = string.Concat(dbSetting.ParameterPrefix,
(value.StartsWith(dbSetting.ParameterPrefix) ? value.Substring(1) : value)
(value.StartsWith(dbSetting.ParameterPrefix, StringComparison.OrdinalIgnoreCase) ? value.Substring(1) : value)
.AsUnquoted(true, dbSetting).AsAlphaNumeric());
}
return index > 0 ? string.Concat(value, "_", index.ToString()) : value;
Expand Down
2 changes: 1 addition & 1 deletion RepoDb.Core/RepoDb/Extensions/TypeExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static bool IsClassType(this Type type) =>
/// <param name="type">The current type.</param>
/// <returns>Returns true if the current type is an anonymous class.</returns>
public static bool IsAnonymousType(this Type type) =>
type.FullName.StartsWith("<>f__AnonymousType");
type.FullName.StartsWith("<>f__AnonymousType", StringComparison.OrdinalIgnoreCase);

/// <summary>
/// Checks whether the current type is of type <see cref="IDictionary{TKey, TValue}"/> (with string/object key-value-pair).
Expand Down
2 changes: 1 addition & 1 deletion RepoDb.Core/RepoDb/Parameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public Parameter(string name,
/// </summary>
internal void PrependAnUnderscore()
{
if (!Name.StartsWith("_"))
if (!Name.StartsWith("_", StringComparison.OrdinalIgnoreCase))
{
Name = string.Concat("_", Name);
}
Expand Down
8 changes: 4 additions & 4 deletions RepoDb.Core/RepoDb/QueryField/ParseExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,16 @@ private static string ConvertToLikeableValue(string methodName,
{
if (methodName == "Contains")
{
value = value.StartsWith("%") ? value : string.Concat("%", value);
value = value.EndsWith("%") ? value : string.Concat(value, "%");
value = value.StartsWith("%", StringComparison.OrdinalIgnoreCase) ? value : string.Concat("%", value);
value = value.EndsWith("%", StringComparison.OrdinalIgnoreCase) ? value : string.Concat(value, "%");
}
else if (methodName == "StartsWith")
{
value = value.EndsWith("%") ? value : string.Concat(value, "%");
value = value.EndsWith("%", StringComparison.OrdinalIgnoreCase) ? value : string.Concat(value, "%");
}
else if (methodName == "EndsWith")
{
value = value.StartsWith("%") ? value : string.Concat("%", value);
value = value.StartsWith("%", StringComparison.OrdinalIgnoreCase) ? value : string.Concat("%", value);
}
return value;
}
Expand Down