/// <summary> /// 把对象数据写入到写入器 /// </summary> /// <param name="writer">写入器</param> public virtual void Write(BinaryWriterX writer) { //Write(this, writer, true, true, false); writer.WriteObject(this, TypeX.Create(this.GetType()), true, false, false, WriteMember); }
private static Boolean WriteMember(BinaryWriterX writer, Object value, MemberInfoX member, Boolean encodeInt, Boolean allowNull, Boolean isProperty, WriteCallback callback) { // 使用自己作为处理成员的方法 return writer.WriteObject(value, member, encodeInt, allowNull, isProperty, callback); }
/// <summary> /// 把对象写入数据流,处理基础类型、特殊类型、基础类型数组、特殊类型数组,通过委托方法处理成员 /// </summary> /// <param name="writer">写入器</param> /// <param name="target">目标对象</param> /// <param name="member">成员</param> /// <param name="encodeInt">是否编码整数</param> /// <param name="allowNull">是否允许空</param> /// <param name="isProperty">是否处理属性</param> /// <param name="callback">处理成员的方法</param> /// <returns>是否写入成功</returns> protected virtual Boolean WriteMember(BinaryWriterX writer, Object target, MemberInfoX member, Boolean encodeInt, Boolean allowNull, Boolean isProperty, BinaryWriterX.WriteCallback callback) { Type type = member.Type; Object value = member.IsType ? target : member.GetValue(target); if (value != null) type = value.GetType(); // 接口支持 if (value != null && typeof(IBinaryAccessor).IsAssignableFrom(type)) { // 调用接口 IBinaryAccessor accessor = value as IBinaryAccessor; accessor.Write(writer); return true; } return writer.WriteObject(target, member, encodeInt, true, isProperty, callback); }