i have this code...
and i have this class
i want to be able to display the contents of the anonymous IEnumerable even though i do not know its field names... can anybody help me?
Code:
List<Sample> list = new List<Sample>();
list.Add(new Sample("balloons"));
list.Add(new Sample("candies"));
IEnumerable sample = list;
Type type = sample.GetType().GetGenericArguments()[0];
FieldInfo[] fieldInfos = type.GetFields();
PropertyInfo[] propertyInfos = type.GetProperties();
foreach (var x in sample)
{
Type a = x.GetType();
Console.WriteLine( a.GetField(fieldInfos[0].Name).GetValue(a));
}
Code:
class Sample
{
public string name;
public string Name
{
get { return name; }
set { name = value; }
}
public Sample(string name)
{
this.name = name;
}
}