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<T> where T : class
{
public List<Col> cols = new List<Col>();
public List<T> rows = new List<T>();
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<Entry> t = new Table<Entry>();
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();
}
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uQ29sbGVjdGlvbnMuR2VuZXJpYzsKdXNpbmcgU3lzdGVtLlJlZmxlY3Rpb247CgpwdWJsaWMgY2xhc3MgVGVzdAp7CglpbnRlcmZhY2UgQ29sCgl7CgkJU3RyaW5nIEdldChPYmplY3Qgbyk7CgkJdm9pZCBTZXQoT2JqZWN0IG8sIFN0cmluZyBzKTsKCX0KCWNsYXNzIEludENvbCA6IENvbAoJewoJCUZpZWxkSW5mbyBmOwoJCXB1YmxpYyBJbnRDb2woRmllbGRJbmZvIGYpCgkJewoJCQl0aGlzLmYgPSBmOwoJCX0KCQlwdWJsaWMgU3RyaW5nIEdldChPYmplY3QgbykgeyByZXR1cm4gIiIgKyBmLkdldFZhbHVlKG8pO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