Reporter | Jesse Plamondon-Willard (Jesse.Plamondon-Willard) |
---|---|
Created | Feb 15, 2012 7:57:38 PM |
Updated | Feb 15, 2012 7:57:38 PM |
Priority | Normal |
Type | Feature |
Fix versions | No Fix versions |
State | Submitted |
Assignee | Evgeny Pasynkov (pasynkov) |
Subsystem | Code Analysis - Find Code Issues |
Affected versions | No Affected versions |
Fixed in build | No Fixed in build |
We use IEnumerable<T> to represent an enumerable set of values, but there's no way to indicate that a method doesn't return a deferred query. For example, ReSharper will raise possible multiple enumeration of IEnumerable warnings for the code below:
This could be fixed by allowing InstantHandleAttribute to be placed on methods, which would indicate that the return values are not deferred:
incorrect multiple enumeration warnings
public IEnumerable<int> GetRandomArray() { return new[] { 4 }; } public void Demo() { IEnumerable<int> values = this.GetRandomArray(); if(values.Any()) Console.WriteLine(values.First()); }
This could be fixed by allowing InstantHandleAttribute to be placed on methods, which would indicate that the return values are not deferred:
proposed attribute usage
[InstantHandle] public IEnumerable<int> GetRandomArray() { return new[] { 4 }; }