I am trying to do data binding for MVC controller,
therefore i need a generic class that will turn my classes from:
public class Subsystem
{
public int Id { get; set; }
public string Name { get; set; }
}
I need a generic method that will turn this:
public Subsystem[] GetSubsystems()
{
return new Subsystem[]
{
new Subsystem() {Id=1, Name = "A"},
new Subsystem() {Id=2, Name = "B"},
new Subsystem() {Id=3, Name = "C"}
};
}
into this:
public object[] GetSubsystems()
{
return new object[]
{
new object[] {Id=1, Name = "A"},
new object[] {Id=2, Name = "B"},
new object[] {Id=3, Name = "C"}
};
}
I still think this may not be the best solution for what you’re really after, but you can use Linq to transform it to an array of anonymous objects:
What you have in your “this” is not actually possible, your result from the Linq query I gave would be equivalent to: