public class School
{
public string Name { get; set; }
public bool Active { get; set; }
public int Children { get; set; }
}
public Func<string, object, object> someMethod = SomeMethod;
public static object SomeMethod(string name, object value)
{
return 1;
}
private void Form1_Load(object sender, EventArgs e)
{
List<School> ls = new List<School>();
School s = new School();
s.Name = "s1";
s.Active = true;
s.Children = 10;
ls.Add(s);
s = new School();
s.Name = "s2";
s.Active = false;
s.Children = 5;
ls.Add(s);
IEnumerable<object> rows = ls;
var result = rows.Select(
x => x.GetType().GetProperties().Select(p => someMethod(p.Name, p.GetValue(x, null))));
}
注意: 行可以是任何东西 结果应该是这样的:
名称活动儿童New_Column s1真10?例如,如果active = true,则显示Ok