using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; namespace Common { public class ReflexCls { /// /// /// /// /// 0 Id查询 1非Id查询 /// iType是0的时候strId则有值 /// public static Dictionary method(object[] objs,out int iType,out string strId) { iType = 1; strId = ""; object value; Dictionary dt = new Dictionary(); foreach (object obj in objs) { Type tp = obj.GetType(); if (tp.IsClass) { PropertyInfo[] PropertyInfos1 = obj.GetType().GetProperties(); foreach (PropertyInfo p1 in PropertyInfos1) { value = p1.GetValue(obj, null); if (value != null) { if (!p1.IsDefined(typeof(AttributeID), false)) { dt.Add(p1.Name, value); } else //带了id的情况 { if (objs.Length == 1) //如果只有一个条件且条件是主键则能调用根据主键查询的方法,否则调用全字段查询 { iType = 0; strId = value + ""; dt.Add(p1.Name, value); } else { dt.Add(p1.Name, value); } } } } } } if (dt != null) { if (dt.Where(s => s.Key == "pageNum").Count() == 0) { dt.Add("pageNum", 1); } if (dt.Where(s => s.Key == "pageSize").Count() == 0) { dt.Add("pageSize", 999999); } } return dt; } } }