对某个类的实例化对象, 遍历获取所有属性(子成员)的方法(采用反射): using (var context = new YZS_TRAEntities()) { ).FirstOrDefault(); Type t = entitys.GetType();//获得该类的Type var pro = t.GetProperties(); //获得此对象的所有字段,字段类型 ; foreach (PropertyInfo pi in pro) //t.GetProperties获得Property
public string GetInsertSqlByModel(Object o) { StringBuilder sbStart = new StringBuilder(); StringBuilder sbFields = new StringBuilder(); StringBuilder sbValues = new StringBuilder(); Type t = o.GetType(); string modelName = t.Name; foreach (PropertyI
遍历一个类/或类对象的属性/值,很有用,看个例子 using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication13 { class Program { static void Main(string[] args) { /