Table tb=new Table(); Type t = tb.GetType(); System.Reflection.FieldInfo[] fi=t.GetFields(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic); foreach(System.Reflection.FieldInfo fi1 in fi) { Console.WriteLine(fi1.Name); }用FieldInfo才会有userName等等
Table t = new Table(); Field userName = new Field { FieldName = "ss", IsPrimaryKey = true }; t.UserName = userName; t.Group = userName; t.Password = userName; foreach (PropertyInfo item in t.GetType().GetProperties()) { Field temp = t.GetType().GetProperty(item.Name).GetValue(t, null) as Field;
Type t = tb.GetType();
System.Reflection.FieldInfo[] fi=t.GetFields(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
foreach(System.Reflection.FieldInfo fi1 in fi)
{
Console.WriteLine(fi1.Name);
}用FieldInfo才会有userName等等
Table t = new Table(); Field userName = new Field { FieldName = "ss", IsPrimaryKey = true };
t.UserName = userName;
t.Group = userName;
t.Password = userName; foreach (PropertyInfo item in t.GetType().GetProperties())
{
Field temp = t.GetType().GetProperty(item.Name).GetValue(t, null) as Field;
}
xField.IsPrimaryKey 。。
我测试了上面的代码,还是不行呀,或许是小弟道行太浅了,还请高手给出具体的实例,谢谢,不胜感激!