public void Pop(bool success)
        {
            Debug.Assert(_count > 0);

            if (!success)
            {
                // Check if we need to initialize the continuation.
                if (_continuationCount == 0)
                {
                    if (_count == 1)
                    {
                        // No need for a continuation since there is only one stack frame.
                        _continuationCount = 1;
                    }
                    else
                    {
                        AddCurrent();
                        _count--;
                        _continuationCount = _count;
                        _count--;
                        Current = _previous[_count - 1];
                    }

                    return;
                }

                if (_continuationCount == 1)
                {
                    // No need for a pop since there is only one stack frame.
                    Debug.Assert(_count == 1);
                    return;
                }

                // Update the list entry to the current value.
                _previous[_count - 1] = Current;

                Debug.Assert(_count > 0);
            }
            else
            {
                Debug.Assert(_continuationCount == 0);
            }

            if (_count > 1)
            {
                Current = _previous[--_count - 1];
            }

            SetConstructorArgumentState();
        }
        public void Push(BinaryTypeInfo typeInfo)
        {
            if (_continuationCount == 0)
            {
                if (_count == 0)
                {
                    // The first stack frame is held in Current.
                    Current.BinaryTypeInfo = typeInfo;
                    Current.TypeMap        = TypeMap;
                    _count = 1;
                }
                else
                {
                    BinaryClassInfo binaryClassInfo;
                    if (Current.BinaryClassInfo.ClassType == ClassType.Object)
                    {
                        if (Current.BinaryPropertyInfo != null)
                        {
                            binaryClassInfo = Current.PolymorphicBinaryClassInfo ?? Current.BinaryPropertyInfo.RuntimeClassInfo;
                        }
                        else
                        {
                            binaryClassInfo = Current.PolymorphicBinaryClassInfo ?? Current.CtorArgumentState !.BinaryParameterInfo !.RuntimeClassInfo;
                        }
                    }
                    else if (((ClassType.Value | ClassType.NewValue) & Current.BinaryClassInfo.ClassType) != 0)
                    {
                        // Although ClassType.Value doesn't push, a custom custom converter may re-enter serialization.
                        binaryClassInfo = Current.BinaryPropertyInfo !.RuntimeClassInfo;
                    }
                    else
                    {
                        Debug.Assert(((ClassType.Enumerable | ClassType.Dictionary) & Current.BinaryClassInfo.ClassType) != 0);
                        binaryClassInfo = Current.PolymorphicBinaryClassInfo ?? Current.BinaryClassInfo.ElementClassInfo !;
                    }

                    AddCurrent();
                    Current.Reset();

                    Current.BinaryClassInfo    = binaryClassInfo;
                    Current.BinaryPropertyInfo = binaryClassInfo.PropertyInfoForClassInfo;
                    Current.BinaryTypeInfo     = typeInfo;

                    Current.TypeMap = TypeMap;
                }
            }
            else if (_continuationCount == 1)
            {
                // No need for a push since there is only one stack frame.
                Debug.Assert(_count == 1);
                _continuationCount = 0;
            }
            else
            {
                // A continuation; adjust the index.
                Current = _previous[_count - 1];

                // Check if we are done.
                if (_count == _continuationCount)
                {
                    _continuationCount = 0;
                }
                else
                {
                    _count++;
                }
            }

            SetConstructorArgumentState();
        }