views:

451

answers:

1

Hello,

I am trying to use reflection to create object array of the type created from reflection like the folowing:

Client[] newArray = new Client[] {client1, client2};

I need to somehow get the Client object type to create the object so it can be passed through.

Any help would be greatly appreciated.

Cheers, Rob

object clientObject = testAssembly.CreateInstance(".Testing_Automation.Client");        
Type client = testAssembly.GetType(".Testing_Automation.Client");

// Create Client Object Array

Passing to:

public Appointment(IEnumerable<Client> client, string time)
+6  A: 

You should use Array.CreateInstance method:

Array arr = Array.CreateInstance(client, lengthOfArray);
arr.SetValue(client1, 0); // Fill in the array...
arr.SetValue(client2, 1);

To get an IEnumerable<Client> from the array, you could use (IEnumerable<Client>)arr if you know the Client type at compile time. If you don't, which is likely, you should post more info about the possibilites of that method call.

Mehrdad Afshari