using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[assembly: AsyncEnumerableWrapperFactory<Test1Factory>]
public static void Main()
var files = new List<string>(Directory.GetFiles(RuntimeEnvironment.GetRuntimeDirectory(), "*.dll"));
files.Add(typeof(Program).Assembly.Location);
using var context = new MetadataLoadContext(new PathAssemblyResolver(files));
foreach (var assembly in context.GetAssemblies())
Console.WriteLine($"assembly: {assembly.FullName}");
var asm = context.LoadFromAssemblyName(assembly.GetName());
foreach (var referencedAssembly in asm.GetReferencedAssemblies())
Console.WriteLine($"referenced assembly: {referencedAssembly.FullName}");
Console.WriteLine("---------------");
foreach (var assemblyName in Assembly.GetExecutingAssembly().GetReferencedAssemblies()) {
Console.WriteLine(assemblyName);
Console.WriteLine("---------------");
var factory = typeof(Program).Assembly
.GetCustomAttribute(typeof(AsyncEnumerableWrapperFactoryAttribute<>))
as IAsyncEnumerableWrapperFactory;
var foo = new[] { "a", "b", "c" }.AsQueryable();
Console.WriteLine(nameof(Main));
var a = new StackTrace(false).GetFrames().Select(Foo).ToArray();
public static bool Foo(StackFrame frame)
var method = frame.GetMethod();
var assembly = method.DeclaringType.Assembly.FullName;
Console.WriteLine($"{name} : {assembly}");
[AttributeUsage(AttributeTargets.Assembly, Inherited = false)]
public sealed class AsyncEnumerableWrapperFactoryAttribute<TFactory> : Attribute, IAsyncEnumerableWrapperFactory
where TFactory : IAsyncEnumerableWrapperFactory, new()
public TFactory Factory { get; } = new();
public IAsyncEnumerable<TSource> Create<TSource>(
IQueryable<TSource> source)
=> Factory.Create(source);
public interface IAsyncEnumerableWrapperFactory
public IAsyncEnumerable<TSource> Create<TSource>(IQueryable<TSource> source) where TSource : class;
public sealed class Test1Factory : IAsyncEnumerableWrapperFactory
public IAsyncEnumerable<TSource> Create<TSource>(IQueryable<TSource> source) where TSource : class
Console.WriteLine(nameof(Test1Factory));