using System; using System.Collections.Generic; using System.Reflection; public class Test { interface Col { String Get(Object o); void Set(Object o, String s); } class IntCol : Col { FieldInfo f; public IntCol(FieldInfo f) { this.f = f; } public String Get(Object o) { return "" + f.GetValue(o); } public void Set(Object o, String s) { f.SetValue(o, int.Parse(s)); } } static Col ToCol(Type t, String name) { FieldInfo f = t.GetField(name); if (f.FieldType == typeof(int)) { return new IntCol(f); } throw new Exception("" + t); } class Table where T : class { public List cols = new List(); public List rows = new List(); public String Get(int row, int col) { return cols[col].Get(rows[row]); } public void Set(int row, int col, String s) { cols[col].Set(rows[row], s); } public void AddField(String name) { cols.Add(ToCol(typeof(T), name)); } public void Add(T o) { rows.Add(o); } } class Entry { public int num1; public int num2; public Entry(int n1, int n2) { num1 = n1; num2 = n2; } } public static void Main() { Table t = new Table(); t.AddField("num1"); t.AddField("num2"); t.Add(new Entry(1, 2)); t.Add(new Entry(10, 20)); t.Set(1, 1, "300"); foreach (Entry e in t.rows) { foreach (Col c in t.cols) { Console.Write(c.Get(e) + " "); } Console.WriteLine(); } } }