【发布时间】:2013-06-26 20:28:19
【问题描述】:
我知道在创建继承自 List<T> 或 ICollection<T> 并带有其他自定义属性的自定义集合时会出现问题:
public class MyCollection: List<int>
{
public string MyCustomProperty { get; set; }
}
据我所知,此类集合将通过 throw WCF 作为 ArrayOfInt 并且 WCF 不会序列化我的自定义属性。解决方案是创建将管理内部集合并具有自定义属性的包装类。
我想根据自己的需要制定一个更好的解决方法...IEnumerable<T> 会遇到同样的问题吗?
public class MyCollection: IEnumerable<int>
{
/**************/
/* Code that implements IEnumerable<int> and manages the internal List<T> */
/* I know I will not able to cast it to List<T>, but I don't need it. */
/* If I will need it, I will implement cast operators later */
/**************/
public string MyCustomProperty { get; set; }
}
上面的类是否会通过 throw WCF 包含 MyCustomProperty 值?
谢谢
【问题讨论】:
标签: wcf serialization ienumerable icollection