Reporter | Mauricio Scheffer (mausch) |
---|---|
Created | Feb 20, 2012 7:03:16 AM |
Updated | Feb 20, 2012 7:03:16 AM |
Priority | Normal |
Type | Unspecified |
Fix versions | No Fix versions |
State | Submitted |
Assignee | Unassigned |
Subsystem | No subsystem |
Affected versions | 6.1.1 |
Fixed in build | No Fixed in build |
ReSharper 6.1.42.60. Given this:
ICollection<ICollection<Stream>> Fun() { return new List<List<MemoryStream>>(); }
ReSharper offers this correction:
ICollection<ICollection<Stream>> Fun() { return (ICollection<ICollection<Stream>>) new List<List<MemoryStream>>(); }
or alternatively:
ICollection<ICollection<Stream>> Fun() { return new List<List<MemoryStream>>() as ICollection<ICollection<Stream>>; }
Both compile without errors but are invalid fixes for the problem. The former throws InvalidCastException, the latter always returns null (obviously not the intended behavior).
A solution to this could be:
ICollection<ICollection<Stream>> Fun() { return new List<List<MemoryStream>>() .Select(x => (ICollection<Stream>) x.Select(y => (Stream) y).ToList()).ToList(); }
I'd even prefer if it didn't suggest anything at all instead of suggesting invalid fixes. I can also see this being quite harmful and confusing for C# newbies...