System.Reflection array handling

D

Dominic Messenger

I am writing a generic XML parser to fill a set of classes that map
directly to an XML Schema. I am not using the XML Designer as it
doesn't handle elements over attributes too well.

I have, for example, a class that looks like this:

public class ApplicantsClass
{
public ApplicantClass [] Applicant = new ApplicantClass[4];
public class ApplicantClass
{
public String Uid = null;
public Int32 Index = new Int32();
}
}

My code simply maps the xml field to a field name in the class, and
using FieldInfo, locates the appropriate field and sets it's value.
Works fine for all primitive types.
I have a problem with array types (the ApplicantClass[] above). This
returns a type of Type.IsArray and Type == "System.Array". How do I
get the type of the members of the array (in this case
ApplicantClass?).

Any help appreciated.

Dominic
 
J

Jon Skeet [C# MVP]

Dominic Messenger said:
I have a problem with array types (the ApplicantClass[] above). This
returns a type of Type.IsArray and Type == "System.Array". How do I
get the type of the members of the array (in this case
ApplicantClass?).

Use Type.GetElementType()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top