FieldInfo of an Arrayfield with System.Reflection c#

Joined
Oct 6, 2009
Messages
2
Reaction score
0
Hello,

i have a problem look at the following code:

public class FieldInfoClass
{
//This is the member from which I want to get the Type (I want 'int' not 'System.Array')
public int[] myIntArray = new int[0];

public static void Main()
{
object o = new FieldInfoClass();

Type myType = typeof(FieldInfoClass);

// Get the type and fields of FieldInfoClass.
FieldInfo[] myFieldInfo = myType.GetFields();

//There is only one Field in the FieldInfoClass!
FieldInfo fi = myFieldInfo[0];

Type type1 = fi.FieldType;
Debug.Print("type1: " + type1.ToString());
//Output:
//type1: System.Array

//But I want the type 'Int32'!!!

object p = fi.GetValue(o);
Type type2 = p.GetType();
Debug.Print("type2: " + type2.ToString());
//Output:
//type2: System.Int32[]

//But I want the type 'Int32'!!!

//My problem is that FieldInfoClass is a class where the members have no value at this time!
//They should get a value and because of this I want to know the type of the array.
}
}

Has someone a idea how I can get out the type of the array?
 

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