/// <summary>
        ///     从第三方客户数据转换为元数据
        /// </summary>
        /// <param name="proxy">内存片段代理器</param>
        /// <param name="attribute">字段属性</param>
        /// <param name="analyseResult">分析结果</param>
        /// <param name="target">目标对象实例</param>
        /// <param name="isArrayElement">当前写入的值是否为数组元素标示</param>
        /// <param name="isNullable">是否为可空字段标示</param>
        public override void Process(IMemorySegmentProxy proxy, IntellectPropertyAttribute attribute, ToBytesAnalyseResult analyseResult, object target, bool isArrayElement = false, bool isNullable = false)
        {
            bool value;

            if (!isNullable)
            {
                value = analyseResult.GetValue <bool>(target);
            }
            else
            {
                bool?nullableValue = analyseResult.GetValue <bool?>(target);
                if (nullableValue == null)
                {
                    if (!attribute.IsRequire)
                    {
                        return;
                    }
                    throw new PropertyNullValueException(string.Format(ExceptionMessage.EX_PROPERTY_VALUE, attribute.Id,
                                                                       analyseResult.Property.Name,
                                                                       analyseResult.Property.PropertyType));
                }
                value = (bool)nullableValue;
            }
            if (attribute.AllowDefaultNull && value.Equals(DefaultValue.Boolean) && !isArrayElement)
            {
                return;
            }
            proxy.WriteByte((byte)attribute.Id);
            proxy.WriteBoolean(value);
        }
예제 #2
0
 /// <summary>
 ///     �ӵ������ͻ�����ת��ΪԪ����
 /// </summary>
 /// <param name="proxy">�ڴ�Ƭ�δ�����</param>
 /// <param name="attribute">�ֶ�����</param>
 /// <param name="analyseResult">�������</param>
 /// <param name="target">Ŀ�����ʵ��</param>
 /// <param name="isArrayElement">��ǰд���ֵ�Ƿ�Ϊ����Ԫ�ر�ʾ</param>
 public override void Process(IMemorySegmentProxy proxy, ThriftPropertyAttribute attribute, ToBytesAnalyseResult analyseResult, object target, bool isArrayElement = false, bool isNullable = false)
 {
     bool value = analyseResult.GetValue<bool>(target);
     proxy.WriteSByte((sbyte)attribute.PropertyType);
     proxy.WriteInt16(((short)attribute.Id).ToBigEndian());
     proxy.WriteBoolean(value);
 }
예제 #3
0
        /// <summary>
        ///     从第三方客户数据转换为元数据
        /// </summary>
        /// <param name="proxy">内存片段代理器</param>
        /// <param name="attribute">字段属性</param>
        /// <param name="analyseResult">分析结果</param>
        /// <param name="target">目标对象实例</param>
        /// <param name="isArrayElement">当前写入的值是否为数组元素标示</param>
        public override void Process(IMemorySegmentProxy proxy, ThriftPropertyAttribute attribute, ToBytesAnalyseResult analyseResult, object target, bool isArrayElement = false, bool isNullable = false)
        {
            bool value = analyseResult.GetValue <bool>(target);

            proxy.WriteSByte((sbyte)attribute.PropertyType);
            proxy.WriteInt16(((short)attribute.Id).ToBigEndian());
            proxy.WriteBoolean(value);
        }
 /// <summary>
 ///     从第三方客户数据转换为元数据
 ///     <para>* 此方法将会被轻量级的DataHelper所使用,并且写入的数据将不会拥有编号(Id)</para>
 /// </summary>
 /// <param name="proxy">内存片段代理器</param>
 /// <param name="target">目标对象实例</param>
 /// <param name="isArrayElement">当前写入的值是否为数组元素标示</param>
 /// <param name="isNullable">是否为可空字段标示</param>
 public unsafe override void Process(IMemorySegmentProxy proxy, object target, bool isArrayElement = false, bool isNullable = false)
 {
     bool[] array = (bool[])target;
     if (array == null || array.Length == 0)
     {
         return;
     }
     if (array.Length > 10)
         fixed(bool *pByte = array) proxy.WriteMemory(pByte, (uint)array.Length * Size.Bool);
     else
     {
         for (int i = 0; i < array.Length; i++)
         {
             proxy.WriteBoolean(array[i]);
         }
     }
 }
        /// <summary>
        ///     从第三方客户数据转换为元数据
        ///     <para>* 此方法将会被轻量级的DataHelper所使用,并且写入的数据将不会拥有编号(Id)</para>
        /// </summary>
        /// <param name="proxy">内存片段代理器</param>
        /// <param name="target">目标对象实例</param>
        /// <param name="isArrayElement">当前写入的值是否为数组元素标示</param>
        /// <param name="isNullable">是否为可空字段标示</param>
        public override void Process(IMemorySegmentProxy proxy, object target, bool isArrayElement = false, bool isNullable = false)
        {
            bool value;

            if (!isNullable)
            {
                value = (bool)target;
            }
            else
            {
                if (target == null)
                {
                    return;
                }
                value = (bool)target;
            }
            proxy.WriteBoolean(value);
        }
        /// <summary>
        ///     从第三方客户数据转换为元数据
        /// </summary>
        /// <param name="proxy">内存片段代理器</param>
        /// <param name="attribute">字段属性</param>
        /// <param name="analyseResult">分析结果</param>
        /// <param name="target">目标对象实例</param>
        /// <param name="isArrayElement">当前写入的值是否为数组元素标示</param>
        /// <param name="isNullable">是否为可空字段标示</param>
        public override void Process(IMemorySegmentProxy proxy, IntellectPropertyAttribute attribute, ToBytesAnalyseResult analyseResult, object target, bool isArrayElement = false, bool isNullable = false)
        {
            bool[] value = analyseResult.GetValue <bool[]>(target);
            if (value == null)
            {
                if (!attribute.IsRequire)
                {
                    return;
                }
                throw new PropertyNullValueException(string.Format(ExceptionMessage.EX_PROPERTY_VALUE, attribute.Id, analyseResult.Property.Name, analyseResult.Property.PropertyType));
            }
            //id(1) + total length(4) + rank(4)
            proxy.WriteByte((byte)attribute.Id);
            MemoryPosition position = proxy.GetPosition();

            proxy.Skip(4U);
            proxy.WriteInt32(value.Length);
            if (value.Length == 0)
            {
                proxy.WriteBackInt32(position, 4);
                return;
            }
            if (value.Length > 10)
            {
                unsafe
                {
                    fixed(bool *pByte = value) proxy.WriteMemory(pByte, (uint)value.Length * Size.Bool);
                }
            }
            else
            {
                for (int i = 0; i < value.Length; i++)
                {
                    proxy.WriteBoolean(value[i]);
                }
            }
            proxy.WriteBackInt32(position, (int)(value.Length * Size.Bool + 4));
        }