예제 #1
0
        /// <summary>
        /// 根据需要的数据获取反射信息
        /// </summary>
        /// <param name="objType"></param>
        /// <param name="propertyCollection"></param>
        /// <returns></returns>
        private static List <EntitySerializerInfo> GetDicInfos(Type objType, IEnumerable <string> propertyCollection)
        {
            List <EntitySerializerInfo> lstInfos = new List <EntitySerializerInfo>(12);

            foreach (string strItem in propertyCollection)
            {
                string[] itemPart = strItem.Split('=');
                if (itemPart.Length < 2)
                {
                    continue;
                }
                EntitySerializerInfo info = new EntitySerializerInfo();

                info.Name         = itemPart[0];
                info.PropertyName = itemPart[1];
                string[] propertyItems = itemPart[1].Split('.');
                Type     curType       = objType;
                foreach (string proName in propertyItems)
                {
                    PropertyInfoHandle pinfo = FastValueGetSet.GetPropertyInfoHandle(proName, curType);
                    info.PropertyInfos.Add(pinfo);
                    curType = pinfo.PropertyType;
                }
                lstInfos.Add(info);
            }
            return(lstInfos);
        }
예제 #2
0
        /// <summary>
        /// 根据反射信息获取值(链式)
        /// </summary>
        /// <param name="info"></param>
        /// <param name="obj"></param>
        /// <returns></returns>
        private static object GetValue(EntitySerializerInfo info, object obj)
        {
            object value = obj;

            foreach (PropertyInfoHandle pHandle in info.PropertyInfos)
            {
                value = pHandle.GetValue(value);
                if (value == null)
                {
                    return(null);
                }
            }
            return(value);
        }
예제 #3
0
        /// <summary>
        /// 获取类型所属的信息
        /// </summary>
        /// <param name="objType">类型</param>
        /// <returns></returns>
        private static List <EntitySerializerInfo> GetTypeInfos(Type objType)
        {
            List <EntitySerializerInfo> lstInfos  = new List <EntitySerializerInfo>(12);
            ClassInfoHandle             classInfo = ClassInfoManager.GetClassHandle(objType);

            foreach (PropertyInfoHandle handle in classInfo.PropertyInfo)
            {
                EntitySerializerInfo info = new EntitySerializerInfo();
                info.PropertyInfos.Add(handle);
                info.Name         = handle.PropertyName;
                info.PropertyName = handle.PropertyName;
                lstInfos.Add(info);
            }
            return(lstInfos);
        }
예제 #4
0
        /// <summary>
        /// 根据反射信息获取值(链式)
        /// </summary>
        /// <param name="info"></param>
        /// <param name="obj"></param>
        /// <returns></returns>
        private static bool SetValue(EntitySerializerInfo info, object obj, object value)
        {
            object tmpObj = obj;
            int    hcount = info.PropertyInfos.Count;

            if (hcount > 1)
            {
                for (int i = 0; i < hcount - 1; i++)
                {
                    PropertyInfoHandle pHandle = info.PropertyInfos[i];
                    tmpObj = pHandle.GetValue(value);
                    if (tmpObj == null)
                    {
                        return(false);
                    }
                }
            }
            PropertyInfoHandle sethandle = info.PropertyInfos[hcount - 1];

            sethandle.SetValue(tmpObj, value);
            return(true);
        }