In RIA services the EntityCollection<T> class is defined as follows :
public sealed class EntityCollection<TEntity> : IEntityCollection,
IEnumerable<TEntity>,
IEnumerable,
INotifyCollectionChanged,
INotifyPropertyChanged where TEntity :
global::System.ServiceModel.DomainServices.Client.Entity
I have a Silverlight converter which sets Visibility dependent upon the number of items in a list.
if (value is EntityCollection<CustomerFeedbackDetail>)
{
visible = (value as EntityCollection<CustomerFeedbackDetail>).Count > 0;
}
But wait – I want it to be generic for any EntityCollection. Uh oh – IEntityCollection is internal and not accessible to us. EntityCollection doesn’t even implement ICollection.
Am I stuck without using reflection (which I really would rather not do since this may get called many times a second in some cases).
I’m pretty sure I do have to use reflection to make this generic – so in that case why would IEntityCollection be internal? Oversight?
Rather than using reflection, you could just implement the function yourself. You don’t care about the count, just that it’s non-zero. Simply rewrite the
Enumberable.Any(IEnumerable<T>)function to take non-genericIEnumerable:Then in your converter you would have: