This is much simpler than you're making it. Note I typed this code right in this code block so beware of stupid typos.
First off, you're not using types, but instead the classes.
Int32
is the class reference for the type of
int
. The same for
String
and
string
.
If your room class is simplified down to:
public class Room : IPrintable
{
public int RoomID { get; set; }
public string RoomDescription {get;set;}
public List<room> ConnectedRooms {get;set;}
private string GetDescriptionById(int roomID)
{
return "A big scary room!";
}
private List<room> GetConnectedRooms(int roomID)
{
return someDatabaseObject.GetRoomsList();
}
public Room()
{
ConnectedRooms = new List<room>();
}
public Room(int _id)
{
ID = _id;
Description = GetDescriptionById(_id);
ConnectedRooms = GetConnectedRoomsById(_id);
}
}
</room></room></room>
Now, because we have that empty constructor, when getting the RoomList you can do some nice magic that has the EMPTY connected room list. That way you don't have to store a huge LinkedLIst type construction.
EDIT: Also notice how (with the anonymous getter and setters) I don't need the private variables explicitly. That's handy.
By attaching the ConnectedRooms to your room class directly, you can specify the List of Connected Rooms directly from any instance of Room.
var r = new Room();
r.ConnectedRooms();