Created
February 7, 2012 17:48
-
-
Save AlphaGit/1760972 to your computer and use it in GitHub Desktop.
StackOverflow on GetEnumerator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TableCountryMappingCollection : ConfigurationElementCollection, IList<TableCountryMapping> | |
{ | |
//... | |
IEnumerator<TableCountryMapping> IEnumerable<TableCountryMapping>.GetEnumerator() | |
{ | |
foreach (var item in ((System.Collections.IEnumerable)this).Cast<TableCountryMapping>()) | |
yield return item; | |
} | |
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() | |
{ | |
return base.GetEnumerator(); | |
} | |
} |
Con this.Select(x => x)
o con ((System.Collections.IEnumerable)this).Cast<TableCountryMapping>()
también estabas accediendo al GetEnumerator()
de TableCountryMappingCollection
ya que Linq accede al GetEnumerator()
por reflection y no por polimorfismo como si hace el foreach
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
El problema era que al utilizar
foreach (var item in this)
estabas accediendo alGetEnumerator()
deTableCountryMappingCollection
en lugar del deConfigurationElementCollection
. Esta es la correción: