Click here to Skip to main content
15,916,842 members

Comments by SaiprasadVer (Top 6 by date)

SaiprasadVer 13-Jan-15 6:42am View    
public void WriteResultToXml(List<Object> objTestResults)
{
foreach (var item in objTestResults)
{
PropertyInfo[] propertyList = item.GetType().GetProperties();
foreach (var property in propertyList)
{
object value = Activator.CreateInstance(property.PropertyType);
Console.WriteLine(property.GetValue(value, null));
}
}
Console.ReadLine();
}

I am observing TargetException when i call GetValue() function
SaiprasadVer 13-Jan-15 5:07am View    
Yes. I know I was close. Thank you.
SaiprasadVer 13-Jan-15 4:48am View    
I would like to know how I can access fields of an particular Type which is type casted to Object Type. Suppose I have an and Employee object(Employee class with its members) which is type casted and placed inside an Object type. Using reflection how can i get the values of those members. The function that i define wont be knowing what type the Object variable is holding.
SaiprasadVer 13-Jan-15 4:44am View    
I am new to this. For now, all i want is to just access each item in the List and then print values of each field within that item. Does this explain you my problem statement!!
SaiprasadVer 13-Jan-15 4:35am View    
Code below

object value = new object();
foreach (var item in objTestResults)
{
Type type = item.GetType();
PropertyInfo[] propertyList = type.GetProperties();
foreach (var property in propertyList)
{
Console.WriteLine(property.GetValue(value, new object[] {property}));
}

}

I am figuring it out how i can achieve this. For now, the above code is what i have.