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

Add .IsNullOrEmpty(this string) extension for static-typing efficiency #336

Merged
merged 6 commits into from
Jan 15, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public static LocalizationConfiguration Load(IConfiguration configuration, strin
return new LocalizationConfigurationReader().Read(configurationRoot, sectionName ?? DefaultSectionName);
}
else if (configuration is IConfigurationSection configurationSection) {
return sectionName.IsNullOrEmpty()
return string.IsNullOrEmpty(sectionName)
? new LocalizationConfigurationReader().Read(configurationSection)
: new LocalizationConfigurationReader().Read(configurationSection.GetSection(sectionName));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private LocalizationConfiguration ReadInternal(IConfigurationSection configurati
}
}
}
if(!cultureName.IsNullOrEmpty()) {
if(!string.IsNullOrEmpty(cultureName)) {
try {
defaultCulture = CultureInfo.GetCultureInfo(cultureName);
}
Expand All @@ -64,4 +64,4 @@ private LocalizationConfiguration ReadInternal(IConfigurationSection configurati
return new LocalizationConfiguration() { DefaultCulture = defaultCulture };
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ protected override SecurityConfiguration ReadInternal(IConfigurationSection conf
}
if ((hashingServiceName ?? authenticationServiceName) != null) {
var securityConfiguration = new SecurityConfiguration(true);
if (!hashingServiceName.IsNullOrEmpty()) {
if (!string.IsNullOrEmpty(hashingServiceName)) {
securityConfiguration.HashingServiceName = hashingServiceName.ToLowerInvariant();
}

if (!authenticationServiceName.IsNullOrEmpty()) {
if (!string.IsNullOrEmpty(authenticationServiceName)) {
securityConfiguration.AuthenticationServiceName = authenticationServiceName.ToLowerInvariant();
}

Expand Down
4 changes: 2 additions & 2 deletions Orm/Xtensive.Orm.Oracle/Sql.Drivers.Oracle/v09/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ public override void Visit(SqlFastFirstRowsHint node) =>

public override void Visit(SqlForceJoinOrderHint node)
{
if (node.Tables.IsNullOrEmpty()) {
if (!(node.Tables?.Count > 0)) {
_ = context.Output.Append("ORDERED");
}
else {
Expand Down Expand Up @@ -583,4 +583,4 @@ protected internal Compiler(SqlDriver driver)
{
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,7 @@ public void AllByFieldOfPoco01Test()
using (var transaction = session.OpenTransaction()) {
_ = session.Query.All<TestEntity>()
.Select(e => new Poco { Name = e.Name })
.All(el => el.Name.IsNullOrEmpty());
.All(el => string.IsNullOrEmpty(el.Name));
}
}

Expand All @@ -1144,7 +1144,7 @@ public void AllByFieldOfPoco02Test()
using (var transaction = session.OpenTransaction()) {
_ = session.Query.All<TestEntity>()
.Select(e => new Poco { Name = e.Name, BaseName = e.Name })
.All(el => el.Name.IsNullOrEmpty());
.All(el => string.IsNullOrEmpty(el.Name));
}
}

Expand All @@ -1155,7 +1155,7 @@ public void AllByFieldOfPoco03Test()
using (var transaction = session.OpenTransaction()) {
_ = session.Query.All<TestEntity>()
.Select(e => new Poco { Name = e.Name, BaseName = e.Name })
.All(el => el.Name.IsNullOrEmpty());
.All(el => string.IsNullOrEmpty(el.Name));
}
}

Expand All @@ -1166,7 +1166,7 @@ public void AllByFieldOfPoco04Test()
using (var transaction = session.OpenTransaction()) {
_ = Assert.Throws<QueryTranslationException>(() => session.Query.All<TestEntity>()
.Select(e => new Poco { BaseName = e.Name })
.All(el => el.Name.IsNullOrEmpty()));
.All(el => string.IsNullOrEmpty(el.Name)));
}
}

Expand All @@ -1177,7 +1177,7 @@ public void AllByFieldOfPoco05Test()
using (var transaction = session.OpenTransaction()) {
_ = session.Query.All<TestEntity>()
.Select(e => new Poco())
.All(el => el.Name.IsNullOrEmpty());
.All(el => string.IsNullOrEmpty(el.Name));
}
}

Expand All @@ -1189,7 +1189,7 @@ public void AnyByFieldOfPoco01Test()
using (var transaction = session.OpenTransaction()) {
_ = session.Query.All<TestEntity>()
.Select(e => new Poco { Name = e.Name })
.Any(el => el.Name.IsNullOrEmpty());
.Any(el => string.IsNullOrEmpty(el.Name));
}
}

Expand All @@ -1200,7 +1200,7 @@ public void AnyByFieldOfPoco02Test()
using (var transaction = session.OpenTransaction()) {
_ = session.Query.All<TestEntity>()
.Select(e => new Poco { Name = e.Name, BaseName = e.Name })
.Any(el => el.Name.IsNullOrEmpty());
.Any(el => string.IsNullOrEmpty(el.Name));
}
}

Expand All @@ -1211,7 +1211,7 @@ public void AnyByFieldOfPoco03Test()
using (var transaction = session.OpenTransaction()) {
_ = session.Query.All<TestEntity>()
.Select(e => new Poco { Name = e.Name, BaseName = e.Name })
.Any(el => el.BaseName.IsNullOrEmpty());
.Any(el => string.IsNullOrEmpty(el.BaseName));
}
}

Expand All @@ -1222,7 +1222,7 @@ public void AnyByFieldOfPoco04Test()
using (var transaction = session.OpenTransaction()) {
_ = session.Query.All<TestEntity>()
.Select(e => new Poco { BaseName = e.Name })
.Any(el => el.BaseName.IsNullOrEmpty());
.Any(el => string.IsNullOrEmpty(el.BaseName));
}
}

Expand All @@ -1233,7 +1233,7 @@ public void AnyByFieldOfPoco05Test()
using (var transaction = session.OpenTransaction()) {
_ = session.Query.All<TestEntity>()
.Select(e => new Poco())
.Any(el => el.Name.IsNullOrEmpty());
.Any(el => string.IsNullOrEmpty(el.Name));
}
}

Expand Down Expand Up @@ -1347,7 +1347,7 @@ public void CountByFieldOfPoco01Test()
using (var transaction = session.OpenTransaction()) {
_ = session.Query.All<TestEntity>()
.Select(e => new Poco { Name = e.Name })
.Count(el => el.Name.IsNullOrEmpty());
.Count(el => string.IsNullOrEmpty(el.Name));
}
}

Expand All @@ -1358,7 +1358,7 @@ public void CountByFieldOfPoco02Test()
using (var transaction = session.OpenTransaction()) {
_ = session.Query.All<TestEntity>()
.Select(e => new Poco { Name = e.Name, BaseName = e.Name })
.Count(el => el.Name.IsNullOrEmpty());
.Count(el => string.IsNullOrEmpty(el.Name));
}
}

Expand All @@ -1369,7 +1369,7 @@ public void CountByFieldOfPoco03Test()
using (var transaction = session.OpenTransaction()) {
_ = session.Query.All<TestEntity>()
.Select(e => new Poco { Name = e.Name, BaseName = e.Name })
.Count(el => el.BaseName.IsNullOrEmpty());
.Count(el => string.IsNullOrEmpty(el.BaseName));
}
}

Expand All @@ -1380,7 +1380,7 @@ public void CountByFieldOfPoco04Test()
using (var transaction = session.OpenTransaction()) {
_ = session.Query.All<TestEntity>()
.Select(e => new Poco { BaseName = e.Name })
.Count(el => el.BaseName.IsNullOrEmpty());
.Count(el => string.IsNullOrEmpty(el.BaseName));
}
}

Expand All @@ -1391,7 +1391,7 @@ public void CountByFieldOfPoco05Test()
using (var transaction = session.OpenTransaction()) {
_ = session.Query.All<TestEntity>()
.Select(e => new Poco())
.Count(el => el.Name.IsNullOrEmpty());
.Count(el => string.IsNullOrEmpty(el.Name));
}
}

Expand Down
5 changes: 4 additions & 1 deletion Orm/Xtensive.Orm/Core/Extensions/EnumerableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public static class EnumerableExtensions
private const int defaultMaximalBatchSize = 1024;
private const int defaultFirstFastCount = 0;

[Obsolete("Use string.IsNullOrEmpty()")]
internal static bool IsNullOrEmpty(this string s) => string.IsNullOrEmpty(s);

/// <summary>
/// Indicates whether enumerable is empty or not
/// by attempting to cast it to <see cref="ICollection{T}"/> and <see cref="IQueryable{T}"/>.
Expand All @@ -35,7 +38,7 @@ public static class EnumerableExtensions
/// <returns><see langword="True"/> if collection is definitely <see langword="null"/> or empty;
/// otherwise, <see langword="false"/>.</returns>
[Obsolete("Don't use Xtensive.Core for 'collection is empty' checking")]
public static bool IsNullOrEmpty<TItem>(this IEnumerable<TItem> items)
internal static bool IsNullOrEmpty<TItem>(this IEnumerable<TItem> items)
{
if (items==null)
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ private static (MemberInfo targetMember, Delegate compilerInvoker) ProcessCompil
Strings.ExCompilerXHasInvalidTargetType, compiler.GetFullName(true)));

var parameterTypes = ValidateCompilerParametersAndExtractTargetSignature(compiler, isGeneric);
var bindingFlags = BindingFlags.Public;
var bindingFlags = BindingFlags.Public | BindingFlags.NonPublic;

if (isCtor)
bindingFlags |= BindingFlags.Instance;
Expand Down
8 changes: 3 additions & 5 deletions Orm/Xtensive.Orm/Sql/Dml/Hints/SqlForceJoinOrderHint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@ namespace Xtensive.Sql.Dml
[Serializable]
public class SqlForceJoinOrderHint : SqlHint
{
private SqlTable[] tables;

/// <summary>
/// Gets the corresponding tables.
/// </summary>
public IEnumerable<SqlTable> Tables { get { return tables; } }
public IReadOnlyList<SqlTable> Tables { get; }

internal override SqlForceJoinOrderHint Clone(SqlNodeCloneContext? context = null) =>
context.GetOrAdd(this, static (t, c) =>
new(t.tables?.Select(table => table.Clone()).ToArray(t.tables.Length)));
new(t.Tables?.Select(table => table.Clone()).ToArray(t.Tables.Count)));

public override void AcceptVisitor(ISqlVisitor visitor)
{
Expand All @@ -36,7 +34,7 @@ internal SqlForceJoinOrderHint()

internal SqlForceJoinOrderHint(SqlTable[] tables)
{
this.tables = tables;
Tables = tables;
}
}
}
Loading