System.Reflection array handling

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dominic Messenger

    #1

    System.Reflection array handling

    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.Arr ay". How do I
    get the type of the members of the array (in this case
    ApplicantClass? ).

    Any help appreciated.

    Dominic
  • Jon Skeet [C# MVP]

    #2
    Re: System.Reflecti on array handling

    Dominic Messenger <dmessenger@ver dantsys.com> wrote:[color=blue]
    > I have a problem with array types (the ApplicantClass[] above). This
    > returns a type of Type.IsArray and Type == "System.Arr ay". How do I
    > get the type of the members of the array (in this case
    > ApplicantClass? ).[/color]

    Use Type.GetElement Type()

    --
    Jon Skeet - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    Working...