示例#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
        private static readonly Type compareType = typeof(IComparable);//可比较对象的接口类型

        /// <summary>
        /// 过滤集合
        /// </summary>
        /// <param name="sourceList">源集合</param>
        /// <param name="lstScope">过滤条件</param>
        /// <returns></returns>
        public static IList RowFilter(IList sourceList, ScopeList lstScope)
        {
            if (sourceList.Count <= 0)
            {
                return(sourceList);
            }
            IList retLst  = (IList)Activator.CreateInstance(sourceList.GetType());
            Type  objType = sourceList[0].GetType();
            //初始化属性信息列表
            List <CompareItemInfo> infos = new List <CompareItemInfo>();

            foreach (Scope objScope in lstScope)
            {
                PropertyInfoHandle pInfo = FastValueGetSet.GetPropertyInfoHandle(objScope.PropertyName, objType);
                infos.Add(new CompareItemInfo(pInfo, objScope));
            }
            foreach (object obj in sourceList)
            {
                List <CompareItem> lstCompareItem = new List <CompareItem>();
                //Dictionary<string, Scope>.Enumerator enums = lstScope.GetEnumerator();
                foreach (CompareItemInfo itemInfo in infos)
                {
                    bool resault = IsAccord(itemInfo.PropertyInfo.GetValue(obj), itemInfo.ScopeInfo);
                    lstCompareItem.Add(new CompareItem(resault, itemInfo.ScopeInfo.ConnectType));
                }
                if (IsAllAccord(lstCompareItem))
                {
                    retLst.Add(obj);
                }
            }
            return(retLst);
        }
示例#3
0
        /// <summary>
        /// 收集集合里边所有对应属性的值
        /// </summary>
        /// <param name="list">集合</param>
        /// <param name="propertyName">属性名</param>
        /// <returns></returns>
        public static ArrayList CollectValues(IEnumerable list, string propertyName)
        {
            ArrayList lst = new ArrayList();


            PropertyInfoHandle pInfo = null;

            //PropertyInfoHandle pInfo = FastValueGetSet.GetPropertyInfoHandle(propertyName, objType);
            //if (pInfo == null)
            //{
            //    throw new Exception("找不到该属性");
            //}
            foreach (object obj in list)
            {
                if (pInfo == null)
                {
                    Type objType = obj.GetType();
                    pInfo = FastValueGetSet.GetPropertyInfoHandle(propertyName, objType);
                    if (pInfo == null)
                    {
                        throw new Exception("找不到该属性");
                    }
                }
                lst.Add(pInfo.GetValue(obj));
            }
            return(lst);
        }
示例#4
0
        /// <summary>
        /// 填充实体
        /// </summary>
        /// <param name="dic">字典</param>
        /// <param name="model">实体</param>
        /// <param name="type">字典中的键类型</param>
        /// <param name="formatHandle">格式化信息</param>
        public static void UpdateModel(IDictionary <string, object> dic,
                                       object model, PrefixType type, DelUpdateModelFormatValue formatHandle)
        {
            Type objType = model.GetType();

            foreach (KeyValuePair <string, object> kvp in dic)
            {
                string             key    = kvp.Key;
                string             pName  = UpdateModelInfo.GetKey(key, type);
                PropertyInfoHandle handle = FastValueGetSet.GetPropertyInfoHandle(pName, objType);
                if (handle != null && handle.HasSetHandle)
                {
                    object value = kvp.Value;
                    if (formatHandle != null)
                    {
                        value = formatHandle(handle, model, value);
                    }
                    else if (value.GetType() != handle.PropertyType)
                    {
                        value = Convert.ChangeType(value, handle.PropertyType);
                    }
                    handle.SetValue(model, value);
                }
            }
        }
示例#5
0
        public void Init(HttpApplication context)
        {
            PropertyInfoHandle  fileChangesMonitorGet = FastValueGetSet.GetPropertyInfoHandle("FileChangesMonitor", typeof(HttpRuntime));
            object              o       = fileChangesMonitorGet.GetValue(null);
            GetFieldValueHandle f       = FastFieldGetSet.FindGetValueHandle(o.GetType().GetField("_dirMonSubdirs", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.IgnoreCase));
            object              monitor = f(o);
            FastInvokeHandler   m       = FastValueGetSet.GetCustomerMethodInfo(monitor.GetType().GetMethod("StopMonitoring", BindingFlags.Instance | BindingFlags.NonPublic));

            m.Invoke(monitor, new object[] { });
        }
示例#6
0
        /// <summary>
        /// 查找实体的关联属性信息属性
        /// </summary>
        /// <param name="propertyName"></param>
        /// <returns></returns>
        public BQLEntityTableHandle FindChildEntity(string propertyName)
        {
            BQLEntityTableHandle table  = null;
            PropertyInfoHandle   handle = FastValueGetSet.GetPropertyInfoHandle(propertyName, this.GetType());

            if (!handle.HasGetHandle)
            {
                throw new MissingMemberException("不存在属性:" + propertyName);
            }
            table = handle.GetValue(this) as BQLEntityTableHandle;
            return(table);
        }
示例#7
0
        /// <summary>
        /// 根据排序方式列表获取对象的Get属性句柄和对应排序方式
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="lstSort"></param>
        /// <returns></returns>
        private static List <SortCompartItem> GetSortComparts(object obj, SortList lstSort)
        {
            Type type = obj.GetType();
            List <SortCompartItem> lstSCompare = new List <SortCompartItem>();

            foreach (Sort objSort in lstSort)
            {
                PropertyInfoHandle getHandle = FastValueGetSet.GetPropertyInfoHandle(objSort.PropertyName, type);
                SortCompartItem    item      = new SortCompartItem();
                item.CurSortType     = objSort.SortType;
                item.GetValueHandler = getHandle;
                lstSCompare.Add(item);
            }
            return(lstSCompare);
        }
示例#8
0
        /// <summary>
        /// 根据集合里边对应属性的值组合出Dictionary
        /// </summary>
        /// <param name="list">集合</param>
        /// <param name="propertyName">属性名</param>
        /// <returns></returns>
        public static Dictionary <T, K> CollectValues <T, K>(IEnumerable <K> list, string propertyName)
        {
            Dictionary <T, K> dic = new Dictionary <T, K>();


            Type objType = typeof(K);

            PropertyInfoHandle pInfo = FastValueGetSet.GetPropertyInfoHandle(propertyName, objType);

            if (pInfo == null)
            {
                throw new Exception("找不到该属性");
            }

            foreach (K obj in list)
            {
                dic[(T)pInfo.GetValue(obj)] = obj;
            }
            return(dic);
        }
示例#9
0
        /// <summary>
        /// 获取需要序列化的属性信息
        /// </summary>
        /// <param name="objType"></param>
        /// <returns></returns>
        private static Dictionary <string, PropertyInfoHandle> GetHandle(Type objType)
        {
            Dictionary <string, PropertyInfoHandle> dic = new Dictionary <string, PropertyInfoHandle>();

            PropertyInfo[] destproper = objType.GetProperties(FastValueGetSet.AllBindingFlags);
            foreach (PropertyInfo pinfo in destproper)
            {
                object[] arr = pinfo.GetCustomAttributes(AttType, true);
                if (arr != null && arr.Length > 0)
                {
                    NeedSerializer tag = arr[0] as NeedSerializer;
                    if (tag != null)
                    {
                        string name = tag.Name;
                        if (string.IsNullOrEmpty(name))
                        {
                            name = pinfo.Name;
                        }
                        dic[name] = FastValueGetSet.GetPropertyInfoHandle(pinfo.Name, objType);
                    }
                }
            }
            return(dic);
        }