VSDiagnostics icon indicating copy to clipboard operation
VSDiagnostics copied to clipboard

Implement InstantiatedObjectNotUsed

Open Vannevelj opened this issue 8 years ago • 0 comments

When instantiating a new object we expect it to be assigned to something.

Show warnings in case of:

new StringBuilder();

Don't show warnings in case of:

return new StringBuilder();
throw new Exception();

This should only happen for locals that are not passed along as arguments. Take for example this usage of a factory pattern:

void Main()
{
    Factory.Create(() => new string("test".ToCharArray())).Dump();
    Factory.Create(() => new string("test 2".ToCharArray())).Dump();
}

public static class Factory
{
    public static T Create<T>(Func<T> func)
    {
        return func();
    }
}

Vannevelj avatar Apr 08 '16 16:04 Vannevelj