示例#1
0
        internal static void ReadEntityFields(EntityModel model, Entity obj, IntPtr valuePtr, int valueSize)
        {
            //TODO:暂使用KVTuple解析,待优化
            var fields = new KVTuple();

            fields.ReadFrom(valuePtr, valueSize);
            ushort fieldId;

            for (int i = 0; i < fields.fs.Count; i++)
            {
                fieldId = fields.fs[i].Id;
                var m = model.GetMember(fieldId, true);
                if (m.Type == EntityMemberType.DataField)
                {
                    var df = (DataFieldModel)m;
                    switch (df.DataType)
                    {
                    case EntityFieldType.String:
                        obj.SetString(fieldId, fields.GetString(fieldId)); break;

                    case EntityFieldType.Binary:
                        obj.SetBytes(fieldId, fields.GetBytes(fieldId)); break;

                    case EntityFieldType.Int32:
                        obj.SetInt32Nullable(fieldId, fields.GetInt32(fieldId)); break;

                    case EntityFieldType.UInt64:
                        obj.SetUInt64Nullable(fieldId, fields.GetUInt64(fieldId)); break;

                    case EntityFieldType.EntityId:
                        obj.SetEntityId(fieldId, fields.GetGuid(fieldId)); break;     //TODO:可能null处理

                    case EntityFieldType.Guid:
                        obj.SetGuidNullable(fieldId, fields.GetGuid(fieldId)); break;

                    case EntityFieldType.Byte:
                        obj.SetByteNullable(fieldId, fields.GetByte(fieldId)); break;

                    case EntityFieldType.Boolean:
                        obj.SetBooleanNullable(fieldId, fields.GetBool(fieldId)); break;

                    case EntityFieldType.DateTime:
                        obj.SetDateTimeNullable(fieldId, fields.GetDateTime(fieldId)); break;

                    case EntityFieldType.Float:
                        obj.SetFloatNullable(fieldId, fields.GetFloat(fieldId)); break;

                    default:
                        throw ExceptionHelper.NotImplemented($"{df.DataType}");
                    }
                }
                else
                {
                    throw new Exception("Only read DataField");
                }
            }

            //TODO:待修改上述赋值后不再需要,参考SqlQuery填充实体
            obj.ChangeToUnChanged();//obj.AcceptChanges();
        }
示例#2
0
        public unsafe void ReadFieldsTest()
        {
            byte[] data   = StringHelper.FromHexString("40000600004141414141418000060000424242424242");
            var    fields = new KVTuple();

            fixed(byte *ptr = data)
            {
                fields.ReadFrom(new IntPtr(ptr), data.Length);
                for (int i = 0; i < fields.fs.Count; i++)
                {
                    Console.WriteLine($"{fields.fs[i].Id} {fields.fs[i].DataPtr} {fields.fs[i].DataSize}");
                }
            }

            Assert.Equal("AAAAAA", fields.GetString(0x40));
            Assert.Equal("BBBBBB", fields.GetString(0x80));
        }