views:

212

answers:

1

Hi,

What type of collection would be best in C# to implement the following requirements do you think?

  1. Need to model web file (e.g. class = "webfile"), so one class only preferred
  2. Model parent & child relationship - In terms of associations a webfile can have multiple child webfiles, and child webfiles can have multiple parents. (think of a HTML page that have multiple images, or multiple HTML pages that share the same image)
  3. A file can be both a parent & a child - or in other words a HTML page can have a link to other HTML pages.
  4. There should be no duplicates anywhere, assume that the URI is the key. In a sense I'm wanting to model the files sitting on a web site. There is only one actual copy of image XYZ, however there will be links to it from multiple pages.
  5. The actual webfile class itself would be key'ed of a unique URI, however I envisage other attributes in the class such as lastmodifieddate, size etc.
  6. Oh, and I was going to use XML serialization on the class as well, to save/load the data. Not sure if this affects the answer

What collection do you think would be best? (the code that implements would be great itself, but I'll be happy with just some basic direction). I started using a List however as I go to implement public methods such as "addChild(parent, child)", I find myself having to write code to check for existance of existing webfiles (i.e. URIs), so perhaps using one of the key'ed collection classes would be best here if it would ensure uniqueness for me?

Hope this makes sense.

Tks

+1  A: 

One of the Generic Dictionary's would serve your purpose, or a basic Hashtable.

James Deville