System.Reflection array handling

  • Thread starter Thread starter Dominic Messenger
  • Start date Start date
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
 
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()
 
Back
Top