Exemple #1
0
 public static List<object> getCols(ArrayEx arrayEx, string key)
 {
     List<object> ret = new List<object>();
     for (int i = 0; i < arrayEx.Count; i++)
     {
         object item = arrayEx.get(i);
         ArrayEx child = (ArrayEx)item;
         ret.Add(child.get(key));
     }
     return ret;
 }
Exemple #2
0
 /// <summary>
 /// 在主对象中插入关联的子对象。
 /// 通常用于ORM处理,例如:分别查询出主表的记录、相关联表的记录,然后根据主键和外键,关联到主表的记录中。
 /// </summary>
 /// <param name="array">主表的数组</param>
 /// <param name="childArray">关联表的数组</param>
 /// <param name="key">主表中的外键</param>
 /// <param name="childKey">关联表的主键</param>
 /// <param name="assocField">主对象中的子属性</param>
 public static void associate(ArrayEx array, ArrayEx childArray, string key, string childKey, string assocField)
 {
     for (int i = 0; i < array.Count; i++)
     {
         object item = array.get(i);
         ArrayEx arItem = (ArrayEx)item;
         ArrayEx associated = ArrayEx.searchField(childArray, childKey, arItem.get(key));
         if (associated == null)
         {
             continue;
         }
         arItem.set(assocField, associated);
     }
 }
Exemple #3
0
 public static ArrayEx searchField(ArrayEx array, string key, object value)
 {
     for (int i = 0; i < array.Count; i++)
     {
         object item = array.get(i);
         ArrayEx arItem = (ArrayEx)item;
         if (arItem.get(key).Equals(value))
         {
             return arItem;
         }
     }
     return null;
 }
Exemple #4
0
 public static ArrayEx from(List<object> list)
 {
     ArrayEx ret = new ArrayEx();
     ret.import(list);
     return ret;
 }
Exemple #5
0
 public static ArrayEx from(Dictionary<string, object> dict)
 {
     ArrayEx ret = new ArrayEx();
     ret.import(dict);
     return ret;
 }