示例#1
0
        /// <summary>
        /// 返回拷贝副本
        /// </summary>
        /// <param name="belong">新副本所属的实体</param>
        /// <returns></returns>
        public EntityPropertyInfo Copy(EntityInfoHandle belong)
        {
            EntityPropertyInfo info = new EntityPropertyInfo(belong, GetHandle,
                                                             SetHandle, _paramInfo, _fieldType, _fieldName, BelongFieldInfo, BelongPropertyInfo);

            return(info);
        }
示例#2
0
 /// <summary>
 /// 创建属性的信息类
 /// </summary>
 /// <param name="belong">所属的实体信息</param>
 /// <param name="getHandle">get委托</param>
 /// <param name="setHandle">set委托</param>
 /// <param name="ep">字段标识类</param>
 /// <param name="fieldType">字段类型</param>
 /// <param name="fieldName">字段名</param>
 /// <param name="sourceType">源字段类型</param>
 public EntityPropertyInfo(EntityInfoHandle belong, GetFieldValueHandle getHandle, SetFieldValueHandle setHandle,
                           EntityParam paramInfo, Type fieldType, string fieldName, FieldInfo belongFieldInfo, PropertyInfo belongPropertyInfo)
     : base(belong.EntityType, getHandle, setHandle, fieldType, fieldName, belongFieldInfo)
 {
     paramInfo.SqlType   = belong.DBInfo.CurrentDbAdapter.ToCurrentDbType(paramInfo.SqlType);//转换成本数据库支持的数据类型
     this._paramInfo     = paramInfo;
     _belong             = belong;
     _belongPropertyInfo = belongPropertyInfo;
 }
示例#3
0
        /// <summary>
        /// 创建代理类
        /// </summary>
        /// <returns></returns>
        public static object Create(Type objType)
        {
            EntityInfoHandle handle = EntityInfoManager.GetEntityHandle(objType);

            if (handle != null)
            {
                return(handle.CreateProxyInstance());
            }
            return(null);
        }
示例#4
0
文件: CH.cs 项目: radtek/buffalobro
        /// <summary>
        /// 获取代理类类型
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static Type GetProxyType(Type objType)
        {
            EntityInfoHandle handle = EntityInfoManager.GetEntityHandle(objType);

            if (handle != null)
            {
                return(handle.ProxyType);
            }
            return(null);
        }
示例#5
0
        /// <summary>
        /// 创建代理类
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static T Create <T>() where T : EntityBase
        {
            Type             objType = typeof(T);
            EntityInfoHandle handle  = EntityInfoManager.GetEntityHandle(objType);

            if (handle != null)
            {
                return(handle.CreateProxyInstance() as T);
            }
            return(null);
        }
示例#6
0
文件: CH.cs 项目: radtek/buffalobro
        /// <summary>
        /// 获取代理类类型
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static Type GetProxyType <T>() where T : EntityBase
        {
            Type             objType = typeof(T);
            EntityInfoHandle handle  = EntityInfoManager.GetEntityHandle(objType);

            if (handle != null)
            {
                return(handle.ProxyType);
            }
            return(null);
        }
示例#7
0
        private static Dictionary <string, EntityInfoHandle> _dicClass = new Dictionary <string, EntityInfoHandle>();//记录已经初始化过的类型

        /// <summary>
        /// 获取实体类里边得属性信息
        /// </summary>
        /// <param name="type">类型</param>
        /// <param name="isThrowException">是否抛出异常</param>
        /// <returns></returns>
        public static EntityInfoHandle GetEntityHandle(Type type, bool isThrowException)
        {
            string           fullName    = type.FullName;
            EntityInfoHandle classHandle = null;

            //if (!DataAccessLoader.HasInit)
            //{
            //    DataAccessLoader.InitConfig();
            //}
            if (isThrowException && (!_dicClass.TryGetValue(fullName, out classHandle)))
            {
                throw new Exception("找不到实体" + fullName + "请检查配置文件");
            }

            return(classHandle);
        }
示例#8
0
        /// <summary>
        /// 填充特殊信息指定标签
        /// </summary>
        /// <param name="type"></param>
        /// <param name="dicParamsInfo"></param>
        /// <param name="tableAtt"></param>
        private static void FillAttributeInfo(Type type, EntityInfoHandle classInfo)
        {
            object[] atts = type.GetCustomAttributes(true);
            foreach (object objAtt in atts)
            {
                SequenceAttributes satt = objAtt as SequenceAttributes;
                if (satt != null)
                {
                    EntityPropertyInfo info = classInfo.PropertyInfo[satt.PropertyName];
                    if (info == null)
                    {
                        throw new System.MissingMemberException("实体:" + classInfo.EntityType.FullName
                                                                + "  ,不包含属性找不到属性:" + satt.PropertyName);
                    }
                    info.ParamInfo.SequenceName = satt.SequenceName;
                    continue;
                }

                EntityParam ep = objAtt as EntityParam;
                if (ep != null)
                {
                    EntityPropertyInfo info = classInfo.PropertyInfo[ep.PropertyName];
                    if (info == null)
                    {
                        throw new System.MissingMemberException("实体:" + classInfo.EntityType.FullName
                                                                + "  ,不包含属性找不到属性:" + ep.PropertyName);
                    }
                    info.ParamInfo = ep;
                    continue;
                }

                TableRelationAttribute tra = objAtt as TableRelationAttribute;
                if (tra != null)
                {
                    EntityMappingInfo info = classInfo.MappingInfo[tra.PropertyName];
                    if (info == null)
                    {
                        throw new System.MissingMemberException("实体:" + classInfo.EntityType.FullName
                                                                + "  ,不包含属性找不到属性:" + tra.PropertyName);
                    }
                    info.MappingInfo = tra;
                    continue;
                }
            }
        }
示例#9
0
        /// <summary>
        /// 初始化所有实体
        /// </summary>
        /// <param name="dicConfigs"></param>
        internal static void InitAllEntity(Dictionary <string, EntityConfigInfo> dicConfigs)
        {
            Queue <EntityInfoHandle> queEntitys = new Queue <EntityInfoHandle>();

            foreach (KeyValuePair <string, EntityConfigInfo> item in dicConfigs)
            {
                EntityConfigInfo info = item.Value;
                if (info.Type != null)
                {
                    queEntitys.Enqueue(InitEntityPropertyInfos(info.Type, dicConfigs));
                }
            }
            EntityProxyBuilder proxyBuilder = new EntityProxyBuilder();

            while (queEntitys.Count > 0)
            {
                EntityInfoHandle handle = queEntitys.Dequeue();
                handle.InitProxyType(proxyBuilder);
                _dicClass[handle.ProxyType.FullName] = handle;
            }
        }
示例#10
0
        /// <summary>
        /// 初始化类型的属性信息
        /// </summary>
        /// <param name="type">类型</param>
        /// <returns>如果已经初始化过侧返回false</returns>
        private static EntityInfoHandle InitEntityPropertyInfos(Type type,
                                                                Dictionary <string, EntityConfigInfo> dicConfigs)
        {
            if (type == null)
            {
                return(null);
            }


            string                fullName      = type.FullName;
            TableAttribute        tableAtt      = new TableAttribute();
            CreateInstanceHandler createrHandle = null;

            //实例化本类型的句柄
            if (!type.IsGenericType)
            {
                createrHandle = FastValueGetSet.GetCreateInstanceHandlerWithOutCache(type);
            }
            Dictionary <string, EntityPropertyInfo> dicPropertys = new Dictionary <string, EntityPropertyInfo>();
            Dictionary <string, EntityMappingInfo>  dicMapping   = new Dictionary <string, EntityMappingInfo>();

            Dictionary <string, EntityParam>            dicParamsInfo   = new Dictionary <string, EntityParam>();
            Dictionary <string, TableRelationAttribute> dicRelationInfo = new Dictionary <string, TableRelationAttribute>();

            FillEntityInfos(dicParamsInfo, dicRelationInfo, type, tableAtt, dicConfigs);
            DBInfo           db        = DataAccessLoader.GetDBInfo(tableAtt.BelongDB);
            IDBAdapter       idb       = db.CurrentDbAdapter;
            EntityInfoHandle classInfo = new EntityInfoHandle(type, createrHandle, tableAtt, db);

            Dictionary <string, bool> dicNotFoundParam    = new Dictionary <string, bool>();
            Dictionary <string, bool> dicNotFoundRelation = new Dictionary <string, bool>();

            FillNotFoundField(dicParamsInfo, dicRelationInfo, dicNotFoundParam, dicNotFoundRelation);

            //属性信息句柄
            List <FieldInfoHandle> lstFields = FieldInfoHandle.GetFieldInfos(type, FastValueGetSet.AllBindingFlags, true);
            DataBaseOperate        oper      = db.DefaultOperate;

            ///读取属性别名
            foreach (FieldInfoHandle finf in lstFields)
            {
                ///通过属性来反射
                EntityParam ep = null;


                if (dicParamsInfo.TryGetValue(finf.FieldName, out ep))
                {
                    //if (tableAtt.IsParamNameUpper)
                    //{
                    //    ep.ParamName = ep.ParamName.ToUpper();
                    //}
                    string proName = ep.PropertyName;
                    //GetFieldValueHandle getHandle = FastFieldGetSet.GetGetValueHandle(finf);
                    //SetFieldValueHandle setHandle = FastFieldGetSet.GetSetValueHandle(finf);
                    if (finf.HasGetHandle || finf.HasSetHandle)
                    {
                        PropertyInfo       pinfo          = type.GetProperty(ep.PropertyName, FastValueGetSet.AllBindingFlags);
                        EntityPropertyInfo entityProperty = new EntityPropertyInfo(
                            classInfo, finf.GetHandle, finf.SetHandle, ep, finf.FieldType, finf.FieldName,
                            finf.BelongFieldInfo, pinfo);
                        dicPropertys.Add(proName, entityProperty);
                        dicNotFoundParam.Remove(finf.FieldName);
                    }
                }
                else
                {
                    TableRelationAttribute tableMappingAtt = null;

                    if (dicRelationInfo.TryGetValue(finf.FieldName, out tableMappingAtt))
                    {
                        Type targetType = DefaultType.GetRealValueType(finf.FieldType);
                        tableMappingAtt.SetEntity(type, targetType);
                        //GetFieldValueHandle getHandle = FastFieldGetSet.GetGetValueHandle(finf);
                        //SetFieldValueHandle setHandle = FastFieldGetSet.GetSetValueHandle(finf);
                        PropertyInfo      pinfo             = type.GetProperty(tableMappingAtt.PropertyName, FastValueGetSet.AllBindingFlags);
                        EntityMappingInfo entityMappingInfo = new EntityMappingInfo(
                            type, finf.GetHandle, finf.SetHandle, tableMappingAtt,
                            finf.FieldName, finf.FieldType, finf.BelongFieldInfo, pinfo);
                        dicMapping.Add(tableMappingAtt.PropertyName, entityMappingInfo);
                        dicNotFoundRelation.Remove(finf.FieldName);
                    }
                }
            }



            if (dicNotFoundParam.Count > 0 || dicNotFoundRelation.Count > 0)
            {
                StringBuilder message = new StringBuilder();

                foreach (KeyValuePair <string, bool> kvp in dicNotFoundParam)
                {
                    message.Append(kvp.Key + "、");
                }


                foreach (KeyValuePair <string, bool> kvp in dicNotFoundRelation)
                {
                    message.Append(kvp.Key + "、");
                }
                if (message.Length > 0)
                {
                    message.Remove(message.Length - 1, 1);
                }
                message.Insert(0, "类:" + type.FullName + " 找不到字段");
                throw new MissingFieldException(message.ToString());
            }
            classInfo.SetInfoHandles(dicPropertys, dicMapping);
            FillAttributeInfo(type, classInfo);
            _dicClass[fullName] = classInfo;
            return(classInfo);
        }