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

Specialcase all methods returning disposables in the framework #146

Open
JohanLarsson opened this issue Jan 23, 2019 · 1 comment
Open

Comments

@JohanLarsson
Copy link
Collaborator

JohanLarsson commented Jan 23, 2019

[Test]
public void Dump()
{
    var methods = AppDomain.CurrentDomain
                           .GetAssemblies()
                           .SelectMany(a => a.GetTypes()
                                             .SelectMany(t =>
                                                 t.GetMethods().Where(m =>
                                                     !m.IsSpecialName &&
                                                     typeof(IDisposable).IsAssignableFrom(m.ReturnType) &&
                                                     !typeof(Task).IsAssignableFrom(m.ReturnType))))
                           .Select(x => $"{x.ReflectedType.FullName}.{x.Name}")
                           .Distinct();
    foreach (var method in methods)
    {
        Console.WriteLine(method);
    }
}
@JohanLarsson
Copy link
Collaborator Author

[TestCase(typeof(int))]
public void DumpDisposables(Type type)
{
    var methods = type.Assembly
                      .GetTypes()
                      .SelectMany(t =>
                          t.GetMethods().Where(m =>
                              !m.IsSpecialName &&
                              typeof(IDisposable).IsAssignableFrom(m.ReturnType) &&
                              !typeof(Task).IsAssignableFrom(m.ReturnType) &&
                              !typeof(IEnumerator).IsAssignableFrom(m.ReturnType)))
                      .Select(x => $"{x.ReflectedType.FullName}.{x.Name}")
                      .Distinct();
    foreach (var method in methods)
    {
        Console.WriteLine(method);
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant