Ejemplo n.º 1
0
 private void EmitEndSerialization(BoundedStream stream, ValueNode child,
                                   LazyBinarySerializationContext lazyContext,
                                   EventShuttle eventShuttle)
 {
     if (eventShuttle != null && eventShuttle.HasSerializationSubscribers)
     {
         eventShuttle.OnMemberSerialized(this, child.Name, child.BoundValue, lazyContext,
                                         stream.GlobalPosition, stream.RelativePosition);
     }
 }
        protected virtual void ObjectSerializeOverride(BoundedStream stream, EventShuttle eventShuttle)
        {
            // check to see if we are actually supposed to be a custom serialization.  This is a side-effect of
            // treating all object members as object nodes.  In the case of sub-types we could later discover we
            // are actually a custom node because the specified subtype implements IBinarySerializable.
            var parent = (TypeNode)TypeNode.Parent;

            if (_valueType != null && (TypeNode.SubtypeBinding != null || parent.ItemSubtypeBinding != null))
            {
                var typeNode = (ObjectTypeNode)TypeNode;
                var subType  = typeNode.GetSubTypeNode(_valueType);

                if (subType is CustomTypeNode)
                {
                    var customValueNode = subType.CreateSerializer((ValueNode)Parent);

                    // this is a little bit of a cheat, but another side-effect of this weird corner case
                    customValueNode.Value = _cachedValue;
                    customValueNode.SerializeOverride(stream, eventShuttle);
                    return;
                }
            }

            var serializableChildren = GetSerializableChildren();

            var lazyContext = CreateLazySerializationContext();

            foreach (var child in serializableChildren)
            {
                // report on serialization start if subscribed
                if (eventShuttle != null && eventShuttle.HasSerializationSubscribers)
                {
                    eventShuttle.OnMemberSerializing(this, child.Name, lazyContext,
                                                     stream.GlobalPosition);
                }

                // serialize child
                child.Serialize(stream, eventShuttle);

                // report on serialization complete if subscribed
                if (eventShuttle != null && eventShuttle.HasSerializationSubscribers)
                {
                    eventShuttle.OnMemberSerialized(this, child.Name, child.BoundValue, lazyContext,
                                                    stream.GlobalPosition);
                }
            }
        }
Ejemplo n.º 3
0
        protected override void SerializeOverride(IBitStream stream, EventShuttle eventShuttle)
        {
            var serializableChildren = GetSerializableChildren();

            var serializationContext = CreateSerializationContext();

            foreach (var child in serializableChildren)
            {
                if (eventShuttle != null)
                {
                    eventShuttle.OnMemberSerializing(this, child.Name, serializationContext);
                }

                child.Serialize(stream, eventShuttle);

                if (eventShuttle != null)
                {
                    eventShuttle.OnMemberSerialized(this, child.Name, child.BoundValue, serializationContext);
                }
            }
        }