【发布时间】:2020-03-23 20:05:09
【问题描述】:
在其中一个预建类中,我有以下场景
[Serializable, XmlInclude(typeof(Child1)), XmlInclude(typeof(Child2)), XmlRoot(IsNullable=false)]
public abstract class Parent
{
}
[Serializable, XmlRoot(IsNullable=false)]
public class Child1: Parent
{
public string C1{get;set;}
}
[Serializable, XmlRoot(IsNullable=false)]
public class Child2: Parent
{
public string C2{get;set;}
}
void Main()
{
System.Collections.ObjectModel.Collection<object> Records = GetDataFromDb();
//above line returns collection of object containing either Child1 or Child2
List<Parent> ToSet = null;//TODO: convert the child object collection to list of parent
}
如何将子类集合转换为父类列表?
【问题讨论】:
标签: c# .net inheritance