Created
August 28, 2010 18:10
-
-
Save cz75hiro/555404 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// 抽象再帰クラス | |
/// </summary> | |
public abstract class RecursionBase<T> where T : RecursionBase<T> { | |
#region コンストラクタ | |
protected RecursionBase() { | |
Children = new RecursionCollection(this); | |
} | |
#endregion | |
#region プロパティ | |
/// <summary> 子のコレクションを取得します。 </summary> | |
public RecursionCollection Children { get; protected set; } | |
/// <summary> 親を取得します。階層のトップの場合はnullを返します。 </summary> | |
public RecursionBase<T> Parent { get; protected set; } | |
#endregion | |
#region インナークラス | |
/// <summary> | |
/// 再帰オブジェクトコレクション | |
/// </summary> | |
public class RecursionCollection : Collection<RecursionBase<T>> { | |
#region メンバー変数 | |
/// <summary> 親 </summary> | |
readonly RecursionBase<T> _parent; | |
#endregion | |
#region コンストラクタ | |
/// <summary> | |
/// 再帰オブジェクトコレクション | |
/// </summary> | |
/// <param name="parent"></param> | |
public RecursionCollection(RecursionBase<T> parent) { | |
_parent = parent; | |
} | |
#endregion | |
#region メソッド | |
/// <summary> | |
/// 追加 | |
/// </summary> | |
/// <param name="item"></param> | |
public new void Add(RecursionBase<T> item) { | |
item.Parent = _parent; | |
base.Add(item); | |
} | |
/// <summary> | |
/// 複数追加 | |
/// </summary> | |
/// <param name="collection"></param> | |
public void AddRange(IEnumerable<RecursionBase<T>> collection) { | |
if (collection == null) return; | |
foreach (var item in collection) { | |
this.Add(item); | |
} | |
} | |
#endregion | |
} | |
#endregion | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment