J
Jordan S.
Using .NET 3.5... I have the following class:
class NodeDescriptor
{
// Properties only in this class
public int NodeID { get; private set; }
public int ParentNodeID { get; private set; }
public string SomeStringValue { get; set; }
// etc... (2 more int and 7 more string properties, that's all.)
}
I need to create a collection of these NodeDescriptor objects. My question
is about how to best implement this collection. This collection needs to
expose a method (named something like GetChildNodes()) that returns all of
the immediate child nodes of a given node. So, for example, if the
collection contains 5 NodeDescriptor instances with the following property
values...
NodeID -- ParentNodeID -- SomeStringValue
23 -- null -- "some string"
37 -- 23 -- "another string"
19 -- 23 -- "yet another"
94 -- 37 -- "okey dokey"
51 -- 23 -- "yes, of course"
.... the GetChildNodes() method would return the NodeDescriptor instances
with NodeID = 37, 19, and 51 when passed NodeID = 23 (because the
parentNodeID = 23 for each of these NodeDescriptor objects).
How can I best implement this collection - given the objectives of NOT
looping through each contained NodeDescriptor instance? List<NodeDescriptor>
would not work for me because I'd have to loop through it, as far as I know,
and I don't want to loop. Can LINQ be used here - or would that be overkill?
If possible I'd like the GetChildNodes() method to return a collection of
NodeDescriptor objects.
A couple of relevant considerations:
1. Only imediate child nodes, and *not* grand child nodes, are to be
returned. So the NodeDescriptor instance with NodeID = 94 would not be
returned when the GetChildNodes() method is passed NodeID = 23 (because it's
ParentNodeID is 37).
2. This collection will typically contain 5-8 (rarely more than 12, and
never more than 30) NodeDescriptor instances.
3. The NodeDescriptor instances should be able to be inserted into this
collection collection in any arbitrary sequence (i.e., no particular
sequence is assumed).
Thanks!
class NodeDescriptor
{
// Properties only in this class
public int NodeID { get; private set; }
public int ParentNodeID { get; private set; }
public string SomeStringValue { get; set; }
// etc... (2 more int and 7 more string properties, that's all.)
}
I need to create a collection of these NodeDescriptor objects. My question
is about how to best implement this collection. This collection needs to
expose a method (named something like GetChildNodes()) that returns all of
the immediate child nodes of a given node. So, for example, if the
collection contains 5 NodeDescriptor instances with the following property
values...
NodeID -- ParentNodeID -- SomeStringValue
23 -- null -- "some string"
37 -- 23 -- "another string"
19 -- 23 -- "yet another"
94 -- 37 -- "okey dokey"
51 -- 23 -- "yes, of course"
.... the GetChildNodes() method would return the NodeDescriptor instances
with NodeID = 37, 19, and 51 when passed NodeID = 23 (because the
parentNodeID = 23 for each of these NodeDescriptor objects).
How can I best implement this collection - given the objectives of NOT
looping through each contained NodeDescriptor instance? List<NodeDescriptor>
would not work for me because I'd have to loop through it, as far as I know,
and I don't want to loop. Can LINQ be used here - or would that be overkill?
If possible I'd like the GetChildNodes() method to return a collection of
NodeDescriptor objects.
A couple of relevant considerations:
1. Only imediate child nodes, and *not* grand child nodes, are to be
returned. So the NodeDescriptor instance with NodeID = 94 would not be
returned when the GetChildNodes() method is passed NodeID = 23 (because it's
ParentNodeID is 37).
2. This collection will typically contain 5-8 (rarely more than 12, and
never more than 30) NodeDescriptor instances.
3. The NodeDescriptor instances should be able to be inserted into this
collection collection in any arbitrary sequence (i.e., no particular
sequence is assumed).
Thanks!