RIA 服务公开属性列表作为 IEnumrable;
我有一个在 RIA 服务中使用的类,其属性类型
List<int>
为 This 被公开
IEnumerable<int>
为 RIA 不能将其公开为 IList 或仅列表的原因是什么?
IEnumerable 不是要公开的预期接口。更糟糕的是,返回的类型是一个数组 int[] ,当我在客户端上转换为 IList 时,它是固定大小的,因此无法添加到其中。
有什么建议吗?
I have a class used in RIA Services with a property of type
List<int>
This is being exposed as
IEnumerable<int>
Any reason why this can't be exposed by RIA as IList or just List?
IEnumerable is not the intended interface to be exposed. Worse yet, the type coming back is an array int[] which when I convert to IList on the client it is of Fixed Size and therefore cannot be added to.
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请发布您的属性声明的副本,或您正在使用的对象的整个对象声明。另外,我建议您使用 IList 而不是 List,因为它更灵活,并且可以在将来为您提供更好的可重用性。
Please post a copy of your property declaration, or the entire object declaration for the object you are working with. Also I would suggest you use an IList rather than List because it is more flexible and may give you a better reusability in the future.
猜测为什么所有内容都公开为 IEnumerable 而不是普通列表或数组,是因为 IEnumerable 具有扩展功能。
将 IEnumerable 转换为所有其他类型的列表(数组)非常容易。
只需添加 System.Linq 命名空间并在任何 IEnumerable 实例上使用 .ToList() 或 .ToArray() 扩展即可。
A guess on why everything is exposed as IEnumerable instead of plain lists or arrays is because of the extended functionalities IEnumerable has.
It is very easy to convert IEnumerable to all other types of lists - arrays.
Just add the System.Linq namespace and use .ToList() or .ToArray() extenions on any IEnumerable instance.