Exemplo n.º 1
0
        /// <summary>
        /// Override this method to get custom field values
        /// from the serialization stream.
        /// </summary>
        /// <param name="info">Serialization info.</param>
        protected virtual void OnSerializeState(ISerializationContext info)
        {
            //使用 bool 数组
            //bool[] values = { AllowEdit, AllowNew, AllowRemove, RaiseListChangedEvents };
            //info.AddValue("ListValues", values);

            //使用 byte
            //byte iValues = 0;
            //if (AllowEdit) iValues |= 8;
            //if (AllowNew) iValues |= 4;
            //if (AllowRemove) iValues |= 2;
            //if (RaiseListChangedEvents) iValues |= 1;
            //info.AddState("$ListValues", iValues);

            var bc = new BitContainer();

            bc.SetValue(Bit._1, AllowEdit);
            bc.SetValue(Bit._2, AllowNew);
            bc.SetValue(Bit._4, AllowRemove);
            bc.SetValue(Bit._8, RaiseListChangedEvents);
            info.AddState("$ListValues", bc.ToInt32());
        }
Exemplo n.º 2
0
        /// <summary>
        /// Override this method to set custom field values
        /// into the serialization stream.
        /// </summary>
        /// <param name="info">Serialization info.</param>
        protected virtual void OnDeserializeState(ISerializationContext info)
        {
            var bc = new BitContainer(info.GetState <int>("$ListValues"));

            AllowEdit              = bc.GetValue(Bit._1);
            AllowNew               = bc.GetValue(Bit._2);
            AllowRemove            = bc.GetValue(Bit._4);
            RaiseListChangedEvents = bc.GetValue(Bit._8);

            //使用 byte
            //var iValues = info.GetState<byte>("$ListValues");
            //AllowEdit = (iValues & 8) == 8;
            //AllowNew = (iValues & 4) == 4;
            //AllowRemove = (iValues & 2) == 2;
            //RaiseListChangedEvents = (iValues & 1) == 1;

            //使用 bool 数组
            //var values = info.GetValue<bool[]>("ListValues");
            //AllowEdit = values[0];
            //AllowNew = values[1];
            //AllowRemove = values[2];
            //RaiseListChangedEvents = values[3];
        }