Exemple #1
0
        /// <summary>
        /// 尝试读取目标对象指定成员的值,处理基础类型、特殊类型、基础类型数组、特殊类型数组,通过委托方法处理成员
        /// </summary>
        /// <remarks>
        /// 简单类型在value中返回,复杂类型直接填充target;
        /// </remarks>
        /// <param name="reader">读取器</param>
        /// <param name="target">目标对象</param>
        /// <param name="member">成员</param>
        /// <param name="type">成员类型,以哪一种类型读取</param>
        /// <param name="encodeInt">是否编码整数</param>
        /// <param name="allowNull">是否允许空</param>
        /// <param name="isProperty">是否处理属性</param>
        /// <param name="value">成员值</param>
        /// <param name="callback">处理成员的方法</param>
        /// <returns>是否读取成功</returns>
        protected virtual Boolean ReadMember(BinaryReaderX reader, Object target, MemberInfoX member, Type type, Boolean encodeInt, Boolean allowNull, Boolean isProperty, out Object value, BinaryReaderX.ReadCallback callback)
        {
            if (type == null) type = member.Type;

            // 接口支持
            if (typeof(IBinaryAccessor).IsAssignableFrom(type))
            {
                // 读取对象
                value = member.GetValue(target);

                // 实例化对象
                if (value == null)
                {
                    //value = Activator.CreateInstance(member.Type);
                    value = CreateInstance(type);
                    //member.SetValue(target, value);
                }
                if (value == null) return false;

                // 调用接口
                IBinaryAccessor accessor = value as IBinaryAccessor;
                accessor.Read(reader);

                return true;
            }

            return reader.TryReadObject(target, member, type, encodeInt, true, isProperty, out value, callback);
        }
Exemple #2
0
 private static Boolean ReadMember(BinaryReaderX reader, Object target, MemberInfoX member, Type type, Boolean encodeInt, Boolean allowNull, Boolean isProperty, out Object value, ReadCallback callback)
 {
     // 使用自己作为处理成员的方法
     return reader.TryReadObject(target, member, type, encodeInt, allowNull, isProperty, out value, callback);
 }
Exemple #3
0
 /// <summary>
 /// 从读取器中读取数据到对象
 /// </summary>
 /// <param name="reader">读取器</param>
 public virtual void Read(BinaryReaderX reader)
 {
     //Read(this, reader, true, true, false);
     Object value = null;
     reader.TryReadObject(this, TypeX.Create(this.GetType()), null, true, false, false, out value, ReadMember);
 }