Skip to content
Draft
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: 12 additions & 1 deletion src/Zomp.SyncMethodGenerator/AsyncToSyncRewriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1847,7 +1847,18 @@ private InvocationExpressionSyntax UnwrapExtension(InvocationExpressionSyntax ie
var newName = reducedFrom.Name;
newName = changeMemoryToSpan ? GetNewName(reducedFrom) : RemoveAsync(newName);

var fullyQualifiedName = $"{MakeType(reducedFrom.ContainingType)}.{newName}";
var newNameExistsInContainingType = semanticModel.Compilation.References
.Select(semanticModel.Compilation.GetAssemblyOrModuleSymbol)
.Append(semanticModel.Compilation.Assembly)
.OfType<IAssemblySymbol>()
.Select(assemblySymbol => assemblySymbol.GetTypeByMetadataName(reducedFrom.ContainingType.ToString()))
.OfType<INamedTypeSymbol>()
.SelectMany(symbol => symbol.GetMembers(newName))
.Any();

var fullyQualifiedName = newNameExistsInContainingType
? $"{reducedFrom.ContainingType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}.{newName}"
: $"{MakeType(reducedFrom.ContainingType)}.{newName}";

var es = (ies.Expression switch
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System.Linq;
using System.Threading;
using System.Threading;
using System.Threading.Tasks;

namespace Zomp.SyncMethodGenerator.IntegrationTests
namespace GenerationSandbox.Tests
{
using Microsoft.EntityFrameworkCore;

Expand All @@ -14,13 +13,19 @@ public partial class EntityFrameworkQueryableExtensions
/// <summary>
/// Test method.
/// </summary>
/// <param name="source">The source.</param>
/// <param name="dbContext">The db context.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>The result.</returns>
[Zomp.SyncMethodGenerator.CreateSyncVersion]
public async Task<bool> QueryableExtensionAsync(IQueryable<object> source, CancellationToken cancellationToken)
public async Task<int> QueryableExtensionAsync(DbContext dbContext, CancellationToken cancellationToken)
{
return await source.AnyAsync(cancellationToken);
var dbSet = dbContext.Set<object>();
if (await dbSet.AnyAsync(cancellationToken))
{
return await dbSet.ExecuteDeleteAsync(cancellationToken);
}

return 0;
}
}
}
11 changes: 8 additions & 3 deletions tests/Generator.Tests/ExtensionMethodTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ public async IAsyncEnumerable<T> WhereLessThan(T threshold)

[Fact]
public Task EntityFrameworkQueryableExtensions() => """
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

Expand All @@ -132,9 +131,15 @@ namespace Zomp.SyncMethodGenerator.IntegrationTests
public partial class EntityFrameworkQueryableExtensions
{
[Zomp.SyncMethodGenerator.CreateSyncVersion]
public async Task<bool> QueryableExtensionAsync(IQueryable<object> source, CancellationToken cancellationToken)
public async Task<int> QueryableExtensionAsync(DbContext dbContext, CancellationToken cancellationToken)
{
return await source.AnyAsync(cancellationToken);
var dbSet = dbContext.Set<object>();
if (await dbSet.AnyAsync(cancellationToken))
{
return await dbSet.ExecuteDeleteAsync(cancellationToken);
}

return 0;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@ namespace Zomp.SyncMethodGenerator.IntegrationTests
{
public partial class EntityFrameworkQueryableExtensions
{
public bool QueryableExtension(global::System.Linq.IQueryable<object> source)
public int QueryableExtension(global::Microsoft.EntityFrameworkCore.DbContext dbContext)
{
return global::System.Linq.Queryable.Any(source);
var dbSet = dbContext.Set<object>();
if (global::System.Linq.Queryable.Any(dbSet))
{
return global::Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ExecuteDelete(dbSet);
}

return 0;
}
}
}
Loading