I am trying to sort a List by other values inside the List.
When I am trying to accomplish: When I add a value to list I will be using a method that contains the value, and a string[] of values that represents it's dependencies.
I want to sort the list, by the values in the string[] inside the ListObject
Here is a programmatic example:
public class ListObject {
private string name;
private string[] dependencies;
private object value;
public ListObject(string name, string[] dependencies, object value) {
this.name = name;
this.dependencies = dependencies;
this.value = value;
}
}
public class ExampleClass {
public static void Main(string[] args) {
List<ListObject> list = new List<ListObject>();
list.Add(new ListObject("ran", new string[] { }, "Value"));
list.Add(new ListObject("far", new string[] {"thest"}, "Value"));
list.Add(new ListObject("the", new string[] {"ran"}, "Value"));
list.Add(new ListObject("thest", new string[] {"the", "ran"}, "Value"));
list.Add(new ListObject("man", new string[] {"ran", "thest"}, "Value"));
//What I want the order of the list to become
/* ran
* the
* far
* thest
* man
*/
}
}
More info: I am generating classes at runtime, I need to make sure that if a field has a generated class type, then I need to make sure I generate the class the field depends on before I generate the class the field is located in.