This seems to be simple enough, but I'm having a hard time getting free of the mental block on this one.
I've got a list of names and the items are ordered specifically based on some business rule. This is the order that is considered correct for some given situation.
So
string [] original = {"Bob","Jim","Kat","Nat","Kim","Ant"};
I've got a Person type that contains a field Name, which will have one of the above values.
So,
class Person {
...
public string Name; //Name will be one of the above values.
...
}
and I've got a bunch of these person objects, in a collection.
PersonCollection p = new PersonCollection
{ new Person{ .. Name = "Kat"..},
new Person {.. "Kim" ..} ...
} etc.;
I know that all of these objects will have names that only contain the values from the above list, there aren't even going to be duplicates. I need to arrange this collection of persons, by the order of the names supplied in the master list (i.e the "original" array above).
Straightforward so far, but here is the tricky bit.
By virtue of the way the Person Class is defined, and I cannot go in and change this, unfortunately, we only have the following available methods in the person object that
move the items.
MoveToFirst(PersonCollection collection) // Move to the first of the given collection
MoveToLast(PersonCollection collection) // Move to the last of the given collection
MoveAfter(PersonCollection collection, Person previousPerson) //places the object after another person item, which is present in the list.
Anyone? By the way, as you can probably tell, this is a "hypothetical" representaion of a problem, I cannot post or discuss the actual production code here, unfortunately. I hope someone else has encountered something similar before.
Dictonaryif it is large use database table with index.