/// <summary> /// 演示用的补充方法:实现迭代器,并且对容器对象实现隐性递归 /// </summary> /// <returns></returns> public virtual IEnumerable <Component> Enumerate(IMatchRule rule) { if ((rule == null) || (rule.IsMatch(this))) { yield return(this); } if ((children != null) && (children.Count > 0)) { foreach (Component child in children) { foreach (Component item in child.Enumerate(rule)) { if ((rule == null) || (rule.IsMatch(item))) { yield return(item); } } } } }
public virtual void GetNameList(List <string> names, IMatchRule rule) { if (rule == null || rule.IsMatch(this)) { names.Add(this.Name); } if (children != null && children.Count > 0) { foreach (Component child in children) { child.GetNameList(names, rule); } } }