日期:2014-05-18 浏览次数:20804 次
public class DNodeCollection<T> : List<TreeStructure<T>> { public DNodeCollection(TreeStructure<T> belongTo) { Belongto = belongTo; } public TreeStructure<T> Belongto { get; set; } public new void Add(TreeStructure<T> node) { node.Level = Belongto.Level + 1; node.Parent = Belongto; base.Add(node); } }
object obj = Activator.CreateInstance((typeof(List<>).MakeGenericType(type.GetGenericArguments()))); IList iList = (IList)obj; obj.Add(new TreeStructure<string>);//报错,Add方法里,必须是String类型,因为DNodeCollection<T>为DNodeCollection<String>