Try our conversational search powered by Generative AI!

Enumerators return wrong object types

Vote:
 
this.CurrentPage.Property contains a EPiServer.Core.ProperyDataCollection. So the Current method in the enumerator for the collection shall intuitivly return a PropertyData object, not a NameObjectEntry as it does today. Else a foreach statement on this object, as in the example below, is not possible, but will give a cast exception: foreach(PropertyData pd in this.CurrentPage.Property){} This is just one example of an enumerator that behaves like this, I'm pretty new to EPiServer (just worked with it a few weeks) so I maybe missunderstand the object model so please correct me if I'm wrong on this ;)
#17353
Mar 02, 2005 9:54
Vote:
 
For other people reading this post, the correct way is: foreach(string propertyName in this.CurrentPage.Property) { PropertyData pd = this.CurrentPage.Property[propertyName]; //do your stuff } The PropertyDataCollection is based on the .NET type NameObjectCollectionBase therefore inheriting it's behaviour. I've heard feedback before that this is not intuitive but this collection is a core concept so we cannot change it's behaviour (even if we would like to). http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemcollectionsspecializednameobjectcollectionbaseclasstopic.asp?frame=true
#18049
Mar 03, 2005 10:55
Vote:
 
Maybe you can make it possible to implicitly cast a ProperyData to a string, then you can make both behaviours possible and still be backwards compatible (?), but I understand that it can produce other problems in this stage... Even if you inherit from NameObjectCollectionBase it is still possible to override the IEnumerator methods and implementing an own enumerator. But I guess you already knew that...
#18050
Mar 04, 2005 10:09
Vote:
 
Personally I don't think the behaviour is that strange since this is a dictionary with key/value pairs and not just a collection of PropertyData items. What I do miss however is the "PropertyData[] Values" property which would allow for simple iterations over the contained values. You have one for the keys so why not add one for the values? Changing the implementation to override the IEnumerator interface at this point is probably not that wise as it would most likely cause problems with backward compatibility.
#18051
Mar 04, 2005 15:32
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.