为什么 IEntityCollection 是内部的/如何查找 EntityCollection.Count?
在 RIA 服务中,EntityCollection
定义如下:
public sealed class EntityCollection<TEntity> : IEntityCollection,
IEnumerable<TEntity>,
IEnumerable,
INotifyCollectionChanged,
INotifyPropertyChanged where TEntity :
global::System.ServiceModel.DomainServices.Client.Entity
我有一个 Silverlight 转换器,它根据列表中的项目数量设置 Visibility
。
if (value is EntityCollection<CustomerFeedbackDetail>)
{
visible = (value as EntityCollection<CustomerFeedbackDetail>).Count > 0;
}
但是等等 - 我希望它对于任何 EntityCollection 都是通用的。 哦哦 - IEntityCollection
是内部的,我们无法访问。 EntityCollection 甚至没有实现 ICollection。
我是否在不使用反射的情况下陷入困境(我真的不想这样做,因为在某些情况下这可能会每秒被调用多次)。
我很确定我确实必须使用反射来使其通用 - 那么在这种情况下为什么 IEntityCollection
是内部的?监督?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以自己实现该函数,而不是使用反射。您不关心计数,只关心它是否非零。只需重写
Enumberable.Any(IEnumerable)
函数即可获取非泛型IEnumerable
:然后在您的转换器中您将拥有:
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: