A
ashraftm
How do I get Array elements value from Reflection..
Here is the C# code..
I have 2 struc
Public struct Address {
public string city;
}
public struct Person {
public Address[] Experience;
}
Person p = new Person();
p.Experience = new Address[2];
p.Experience[0] = "Los Angeles";
p.Experience[1] = "NewYork";
Type personInfo = p.GetType();
FieldInfo[] fieldInfo = personInfo.GetFields();
foreach(FieldInfo info in fieldInfo) {
if (info.FieldType.IsArray) {
Object Temp = (Object)info.GetValue(sender);
int len = ((Array)Temp).Length;
// Error here. Error is cannot convert Address type to Object type
Object[] a = (Object[])Temp;
// If I do like "Address[] a = (Address[])Temp;" then
it works...But this class is a
helper class for serialization like JSON. So Object can be any
type.
for (int i = 0; i < len; i++)
result = a.City;
}
}
Anyone have any better idea.
All I need is to get object field name and its value.
thanks in advance.
achu.
Here is the C# code..
I have 2 struc
Public struct Address {
public string city;
}
public struct Person {
public Address[] Experience;
}
Person p = new Person();
p.Experience = new Address[2];
p.Experience[0] = "Los Angeles";
p.Experience[1] = "NewYork";
Type personInfo = p.GetType();
FieldInfo[] fieldInfo = personInfo.GetFields();
foreach(FieldInfo info in fieldInfo) {
if (info.FieldType.IsArray) {
Object Temp = (Object)info.GetValue(sender);
int len = ((Array)Temp).Length;
// Error here. Error is cannot convert Address type to Object type
Object[] a = (Object[])Temp;
// If I do like "Address[] a = (Address[])Temp;" then
it works...But this class is a
helper class for serialization like JSON. So Object can be any
type.
for (int i = 0; i < len; i++)
result = a.City;
}
}
Anyone have any better idea.
All I need is to get object field name and its value.
thanks in advance.
achu.