IEnumerable类型转换的问题

lovebaby 2015-10-15 11:33:19
比如我有两个类,这两个类除了类名不一样,其他成员都一样。现在要把其中一个IEnumerable泛型的类转换成另一个IEnumerable泛型类,应该怎么转呢?
IEnumerable<ProductClass> as IEnumerable<Class> //as是不行的
public partial class Category
{
// Primitive properties

public int ClassID { get; set; }
public string ClassName { get; set; }
public Nullable<int> ParentID { get; set; }
public string ParentPath { get; set; }
public Nullable<int> Depth { get; set; }
public Nullable<int> RootID { get; set; }
public Nullable<int> Child { get; set; }
public Nullable<int> PrevID { get; set; }
public Nullable<int> NextID { get; set; }
public Nullable<int> OrderID { get; set; }
public string Title { get; set; }
public string KeyWords { get; set; }
public string Description { get; set; }
public string Content { get; set; }
public Nullable<byte> ShowType { get; set; }
public string LinkUrl { get; set; }
public string Intro { get; set; }
public string ClassPic { get; set; }
public string ItemPic { get; set; }
public Nullable<byte> LanType { get; set; }
public Nullable<bool> IsHome { get; set; }
}
...全文
287 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
wanghui0380 2015-10-15
  • 打赏
  • 举报
回复
请百度“Emit mapper” 或"Automapper"
正怒月神 版主 2015-10-15
  • 打赏
  • 举报
回复
var q = 实体1 .select (x=> new 实体2(){ 属性=实体1.属性 }) 类似这样吧
lovebaby 2015-10-15
  • 打赏
  • 举报
回复
两个类的基于一个需求实现的。请看: http://bbs.csdn.net/topics/391843006?page=1#post-400470623
ajianchina 2015-10-15
  • 打赏
  • 举报
回复
既然成员一样,为何要用两个类呢?或者说其中一个本就是继承类? 如果是继承类,你就直接通过cast转 class aClass class bClass:aClass IEnumerable<aClass> a var c = a.Cast<bClass>();

62,243

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧