/// <summary>
        /// 获取缓存项,如果没有,将自动创建一个
        /// </summary>
        /// <param name="entityType">实体类类型</param>
        /// <returns></returns>
        public static DMEDb_EntityFields Item(Type entityType)
        {
            if (dict.ContainsKey(entityType.FullName))
                return dict[entityType.FullName];

            DMEDb_EntityFields ef = new DMEDb_EntityFields();
            if (ef.Init(entityType))
                dict.Add(entityType.FullName, ef);
            return ef;
        }
Beispiel #2
0
        protected internal static void BinaryDeserializeCommon(BinaryReader br, DMEDb_EntityFields ef,DMEDb_EntityBase factEntity)
        {
            int flag = br.ReadInt32();
            if (flag != DMEDb_Serialize.ENTITY_ITEM_FLAG)
                throw new Exception("反序列化错误:不是有效的实体类数据格式!");

            for (int i = 0; i < factEntity.PropertyValues.Length; i++)
            {
                object obj = null;
                if (br.ReadByte() == 0)
                {
                    obj = DBNull.Value;
                }
                else
                {
                    Type propertyType = ef.GetPropertyType(factEntity.PropertyNames[i]);
                    if (propertyType == null)
                        throw new Exception("DME.DataBase实体类序列化错误:未知的实体属性类型,请检查实体类的属性和字段定义是否匹配。");

                    switch (propertyType.Name)
                    {
                        case "Int32": obj = br.ReadInt32(); break;
                        case "String":
                            obj = br.ReadString();//继续读一个字符串
                            break;
                        case "DateTime": obj = DateTime.FromBinary(br.ReadInt64()); break;
                        case "Int16": obj = br.ReadInt16(); break;
                        case "Int64": obj = br.ReadInt64(); break;
                        case "Single": obj = br.ReadSingle(); break;
                        case "Double": obj = br.ReadDouble(); break;
                        case "Decimal": obj = br.ReadDecimal(); break;
                        case "Boolean": obj = br.ReadBoolean(); break;
                        case "Byte": obj = br.ReadByte(); break;
                        case "Char": obj = br.ReadChar(); break;
                        case "Byte[]":
                            int length = br.ReadInt32();
                            if (length > 0)
                                obj = br.ReadBytes(length);
                            break;
                    }
                }

                factEntity.PropertyValues[i] = obj;
            }
        }