예제 #1
0
        /// <summary>
        /// 根据Reader的内容把数值赋进实体
        /// </summary>
        /// <param name="reader">Reader</param>
        /// <param name="index">当前Reader的索引</param>
        /// <param name="arg">目标对象</param>
        /// <param name="info">目标属性的句柄</param>
        public static void ValueFromReader(IDataReader reader, int index, object arg, EntityPropertyInfo info, bool needChangeType)
        {
            object val = reader.GetValue(index);

            if (needChangeType)
            {
                Type resType = info.RealFieldType;//字段值类型
                val = CommonMethods.ChangeType(val, resType);
            }
            info.SetValue(arg, val);
        }
예제 #2
0
 private void setEntityPropertyValue(Object obj, EntityPropertyInfo p, String postValue)
 {
     if (p.Type == typeof(int))
     {
         p.SetValue(obj, cvt.ToInt(postValue));
     }
     else if (p.Type == typeof(String))
     {
         p.SetValue(obj, getAutoPostString(p.Property, postValue));
     }
     else if (p.Type == typeof(Decimal))
     {
         p.SetValue(obj, cvt.ToDecimal(postValue));
     }
     else if (p.Type == typeof(Double))
     {
         p.SetValue(obj, cvt.ToDouble(postValue));
     }
     else if (p.Type == typeof(DateTime))
     {
         p.SetValue(obj, cvt.ToTime(postValue));
     }
     else if (p.IsEntity)
     {
         IEntity objProperty = Entity.New(p.EntityInfo.FullName);
         objProperty.Id = cvt.ToInt(postValue);
         p.SetValue(obj, objProperty);
     }
 }
예제 #3
0
        private static IEntity toEntityByMap(Type t, Dictionary <String, object> map, Type parentType)
        {
            if (map == null)
            {
                return(null);
            }
            IEntity    result = Entity.New(t.FullName);
            EntityInfo ei     = Entity.GetInfo(t);



            foreach (KeyValuePair <String, object> pair in map)
            {
                String pName  = pair.Key;
                object pValue = pair.Value;


                EntityPropertyInfo p = ei.GetProperty(pName);

                Object objValue = null;

                if (ReflectionUtil.IsBaseType(p.Type))
                {
                    objValue = Convert.ChangeType(pValue, p.Type);
                }
                else if (p.IsList)
                {
                    continue;
                }

                else if (pValue is Dictionary <String, object> )
                {
                    if (p.Type == parentType)
                    {
                        continue;
                    }

                    Dictionary <String, object> dic = pValue as Dictionary <String, object>;
                    if (dic != null && dic.Count > 0)
                    {
                        objValue = toEntityByMap(p.Type, dic, t);
                    }
                }
                else
                {
                    continue;
                }

                p.SetValue(result, objValue);
            }
            return(result);
        }