{"action":"created","issue":{"url":"https://api.github.com/repos/code-cracker/code-cracker/issues/491","labels_url":"https://api.github.com/repos/code-cracker/code-cracker/issues/491/labels{/name}","comments_url":"https://api.github.com/repos/code-cracker/code-cracker/issues/491/comments","events_url":"https://api.github.com/repos/code-cracker/code-cracker/issues/491/events","html_url":"https://github.com/code-cracker/code-cracker/issues/491","id":104259771,"number":491,"title":"IEnumerable possibly being enumerated more than once","user":{"login":"giggio","id":334958,"avatar_url":"https://avatars.githubusercontent.com/u/334958?v=3","gravatar_id":"","url":"https://api.github.com/users/giggio","html_url":"https://github.com/giggio","followers_url":"https://api.github.com/users/giggio/followers","following_url":"https://api.github.com/users/giggio/following{/other_user}","gists_url":"https://api.github.com/users/giggio/gists{/gist_id}","starred_url":"https://api.github.com/users/giggio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/giggio/subscriptions","organizations_url":"https://api.github.com/users/giggio/orgs","repos_url":"https://api.github.com/users/giggio/repos","events_url":"https://api.github.com/users/giggio/events{/privacy}","received_events_url":"https://api.github.com/users/giggio/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/code-cracker/code-cracker/labels/1%20-%20Ready","name":"1 - Ready","color":"CCCCCC"},{"url":"https://api.github.com/repos/code-cracker/code-cracker/labels/analyzer","name":"analyzer","color":"0052cc"},{"url":"https://api.github.com/repos/code-cracker/code-cracker/labels/C%23","name":"C#","color":"5319e7"},{"url":"https://api.github.com/repos/code-cracker/code-cracker/labels/code-fix","name":"code-fix","color":"207de5"},{"url":"https://api.github.com/repos/code-cracker/code-cracker/labels/enhancement","name":"enhancement","color":"84b6eb"},{"url":"https://api.github.com/repos/code-cracker/code-cracker/labels/up-for-grabs","name":"up-for-grabs","color":"006b75"},{"url":"https://api.github.com/repos/code-cracker/code-cracker/labels/VB","name":"VB","color":"d4c5f9"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-09-01T12:56:27Z","updated_at":"2015-12-30T19:40:14Z","closed_at":null,"body":"If an IEnumerable is being enumerated more than once you might have problems. Any calls to linq methods like `Count()` or `Any()` or `Select()` (or use in linq expressions) or calls to `foreach` should trigger this diagnostic on all lines that the enumeration is happening.\r\n\r\nSo this:\r\n\r\n````csharp\r\nvar myEnumerable = GetEnumerable();\r\nvar count = myEnumerable.Count();\r\nvar gtFive = from i in MyEnumerable\r\n             select i;\r\nforeach (var i in myEnumerable)\r\n{}\r\n````\r\n\r\nShould trigger this diagnostic on lines 2, 3 and 5.\r\n\r\nFixes to:\r\n\r\n\r\n````csharp\r\nvar myEnumerable = GetEnumerable();\r\nvar myEnumerableList = myEnumberable.ToList();\r\nvar count = myEnumerableList.Count();\r\nvar gtFive = from i in myEnumerableList\r\n             select i;\r\nforeach (var i in myEnumerableList)\r\n{}\r\n````\r\n\r\n**Notes**:\r\n* Messages should say \"**Might** be enumerated more than once\" because even though the type is an IEnumerable, it could be an IList at runtime.\r\n* `ToList` has to be available, so `System.Linq` has to be available. If is, but the `using` is not present at the `.cs` file, add it.\r\n\r\nDiagnostic id: `CC0100`\r\nSeverity: Information\r\nCategory: Performance"},"comment":{"url":"https://api.github.com/repos/code-cracker/code-cracker/issues/comments/168062160","html_url":"https://github.com/code-cracker/code-cracker/issues/491#issuecomment-168062160","issue_url":"https://api.github.com/repos/code-cracker/code-cracker/issues/491","id":168062160,"user":{"login":"AlbertoMonteiro","id":836496,"avatar_url":"https://avatars.githubusercontent.com/u/836496?v=3","gravatar_id":"","url":"https://api.github.com/users/AlbertoMonteiro","html_url":"https://github.com/AlbertoMonteiro","followers_url":"https://api.github.com/users/AlbertoMonteiro/followers","following_url":"https://api.github.com/users/AlbertoMonteiro/following{/other_user}","gists_url":"https://api.github.com/users/AlbertoMonteiro/gists{/gist_id}","starred_url":"https://api.github.com/users/AlbertoMonteiro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AlbertoMonteiro/subscriptions","organizations_url":"https://api.github.com/users/AlbertoMonteiro/orgs","repos_url":"https://api.github.com/users/AlbertoMonteiro/repos","events_url":"https://api.github.com/users/AlbertoMonteiro/events{/privacy}","received_events_url":"https://api.github.com/users/AlbertoMonteiro/received_events","type":"User","site_admin":false},"created_at":"2015-12-30T19:40:14Z","updated_at":"2015-12-30T19:40:14Z","body":"Ok, I will do it."}}