Consider this code:
var e = Enumerable.Range(0, 10);
void Test<T>(IEnumerable<T> e)
R# will flag both usages of 'e' in Test as "Possible multiple enumeration". Yet I want to require that all methods coming into that function already undefer their enums before passing them in. I could put an e = e.ToList() in Test() but what happens if I pass in a Dictionary? It would get undeferred twice and have double the memory usage temporarily.
Proposal: support a new JetBrains.Annotations.UnDeferredAttribute that I can put on the 'e' parameter of Test. This would do two things:
- It would treat the incoming parameter as already undeferred, as if it had ToList()/ToArray() called on it. This would mean the unnecessary multiple enumeration warnings would go away, at least until that code runs the enumerable through a new operator.
- It would require that all functions calling Test would have undeferred their enumerables being passed in, in advance. So it could flag potential errors of where a function is expecting an undeferred enumerable yet callers are not doing this.
What do you think?