/// <summary> /// Tells if this level is lower than or the same as another level. /// </summary> /// <param name="otherLevel">The Level to test this level against</param> /// <returns>True if this level equals otherLevel or if this level is lower in than otherLevel</returns> public bool IsLowerOrEqualThan(Level otherLevel) { Level next = this; while (next != null) { if ( next == otherLevel ) { return true; } next = next.HigherLevel; } return false; }
/// <summary> /// TODO: What if the level already exists? Adds a level after this level. /// /// </summary> /// <returns>Added level</returns> private Level AddHigherLevel() { //TODO: Should use the same type as parent even if its a derived level type Level lev = Activator.CreateInstance(this.GetType()) as Level; //Not the last in this levels if (LowerLevel != null) { LowerLevel.HigherLevel = lev; lev.LowerLevel = LowerLevel; } this.LowerLevel = lev; lev.HigherLevel = this; return lev; }