RIA 服务公开属性列表作为 IEnumrable;

发布于 2024-12-17 19:31:12 字数 290 浏览 6 评论 0原文

我有一个在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

故笙诉离歌 2024-12-24 19:31:12

请发布您的属性声明的副本,或您正在使用的对象的整个对象声明。另外,我建议您使用 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.

如梦亦如幻 2024-12-24 19:31:12

猜测为什么所有内容都公开为 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文