예제 #1
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, IntellectPropertyAttribute attribute, ToBytesAnalyseResult analyseResult, object target, bool isArrayElement = false, bool isNullable = false)
        {
            char value;

            if (!isNullable)
            {
                value = analyseResult.GetValue <char>(target);
            }
            else
            {
                char?nullableValue = analyseResult.GetValue <char?>(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 = (char)nullableValue;
            }
            if (attribute.AllowDefaultNull && value.Equals(DefaultValue.Char) && !isArrayElement)
            {
                return;
            }
            proxy.WriteByte((byte)attribute.Id);
            proxy.WriteChar(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)
 {
     char[] array = (char[])target;
     if (array == null || array.Length == 0)
     {
         return;
     }
     if (array.Length > 10)
         fixed(char *pByte = array) proxy.WriteMemory(pByte, (uint)array.Length * Size.Char);
     else
     {
         for (int i = 0; i < array.Length; i++)
         {
             proxy.WriteChar(array[i]);
         }
     }
 }
예제 #3
0
        /// <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)
        {
            char value;

            if (!isNullable)
            {
                value = (char)target;
            }
            else
            {
                if (target == null)
                {
                    return;
                }
                value = (char)target;
            }
            proxy.WriteChar(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)
        {
            char[] value = analyseResult.GetValue <char[]>(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(char *pByte = value) proxy.WriteMemory(pByte, (uint)value.Length * Size.Char);
                }
            }
            else
            {
                for (int i = 0; i < value.Length; i++)
                {
                    proxy.WriteChar(value[i]);
                }
            }
            proxy.WriteBackInt32(position, (int)(value.Length * Size.Char + 4));
        }