예제 #1
0
 void writer_OnMemberWriting(object sender, WriteMemberEventArgs e)
 {
     var writer = sender as IWriter;
     if (writer.CurrentObject == this && e.Member.Name == "_Value")
     {
         e.Type = Type; 
         writer.OnMemberWriting -= new EventHandler<WriteMemberEventArgs>(writer_OnMemberWriting);
     }
 }
예제 #2
0
        /// <summary>写入对象成员</summary>
        /// <param name="name">成员名字</param>
        /// <param name="value">要写入的对象</param>
        /// <param name="type">要写入的成员类型</param>
        /// <param name="index">成员索引</param>
        /// <param name="callback">处理成员的方法</param>
        /// <returns>是否写入成功</returns>
        public Boolean WriteMember(String name, Object value, Type type, Int32 index, WriteObjectCallback callback)
        {
            if (callback == null)
            {
                callback = WriteMember;
            }

            // 写入成员前
            WriteMemberEventArgs e = null;

            if (OnMemberWriting != null)
            {
                e = new WriteMemberEventArgs(name, value, type, index, callback);

                OnMemberWriting(this, e);

                // 事件处理器可能已经成功写入对象
                if (e.Success)
                {
                    return(true);
                }

                // 事件里面有可能改变了参数
                value    = e.Value;
                type     = e.Type;
                index    = e.Index;
                callback = e.Callback;
            }

            var rs = OnWriteMember(name, value, type, index, callback);

            // 写入成员后
            if (OnMemberWrited != null)
            {
                e         = new WriteMemberEventArgs(name, value, type, index, callback);
                e.Success = rs;

                OnMemberWrited(this, e);

                // 事件处理器可以影响结果
                rs = e.Success;
            }

            return(rs);
        }
예제 #3
0
파일: WriterBase.cs 프로젝트: xlfj5211/esb
        /// <summary>写入对象成员</summary>
        /// <param name="value">要写入的对象</param>
        /// <param name="type">要写入的成员类型</param>
        /// <param name="member">成员</param>
        /// <param name="index">成员索引</param>
        /// <param name="callback">处理成员的方法</param>
        /// <returns>是否写入成功</returns>
        public Boolean WriteMember(Object value, Type type, IObjectMemberInfo member, Int32 index, WriteObjectCallback callback)
        {
            if (callback == null)
            {
                callback = WriteMember;
            }

            IObjectMemberInfo old = CurrentMember;

            CurrentMember = member;

#if !DEBUG
            try
#endif
            {
                // 写入成员前
                WriteMemberEventArgs e = null;
                if (OnMemberWriting != null)
                {
                    e = new WriteMemberEventArgs(value, type, member, index, callback);

                    OnMemberWriting(this, e);

                    // 事件处理器可能已经成功写入对象
                    if (e.Success)
                    {
                        CurrentMember = old;
                        return(true);
                    }

                    // 事件里面有可能改变了参数
                    value    = e.Value;
                    type     = e.Type;
                    member   = e.Member;
                    index    = e.Index;
                    callback = e.Callback;
                }

                Boolean rs = OnWriteMember(value, type, member, index, callback);

                // 写入成员后
                if (OnMemberWrited != null)
                {
                    e         = new WriteMemberEventArgs(value, type, member, index, callback);
                    e.Success = rs;

                    OnMemberWrited(this, e);

                    // 事件处理器可以影响结果
                    rs = e.Success;
                }

                CurrentMember = old;

                return(rs);
            }
#if !DEBUG
            catch (Exception ex)
            {
                throw new XSerializationException(member, ex);
            }
#endif
        }
예제 #4
0
 void writer_OnMemberWriting(object sender, WriteMemberEventArgs e)
 {
     if (e.Member.Name == "_Value") e.Type = Type;
 }