/// <summary>
        /// Initialize the state without delayed initialization of the BinaryClassInfo.
        /// </summary>
        public BinaryConverter Initialize(Type type, BinarySerializerOptions options, bool supportContinuation)
        {
            _typeSeqList = new List <ushort>();

            BinaryClassInfo binaryClassInfo = options.GetOrAddClass(type);

            TypeMap = options.TypeMap;
            AddTypeSeq(binaryClassInfo.TypeSeq);
            //PrimaryTypeSeq = binaryClassInfo.TypeSeq;

            Current.BinaryClassInfo            = binaryClassInfo;
            Current.BinaryTypeInfo             = TypeMap.GetTypeInfo(binaryClassInfo.TypeSeq);
            Current.DeclaredBinaryPropertyInfo = binaryClassInfo.PropertyInfoForClassInfo;

            if (options.ReferenceHandler != null)
            {
                ReferenceResolver = options.ReferenceHandler !.CreateResolver(writing: true);
            }
            else
            {
                ReferenceResolver = new ObjectReferenceResolver();
            }

            SupportContinuation = supportContinuation;

            return(binaryClassInfo.PropertyInfoForClassInfo.ConverterBase);
        }
        public BinaryConverter InitializeReEntry(Type type, BinarySerializerOptions options)
        {
            BinaryClassInfo classInfo = options.GetOrAddClass(type);


            // Set for exception handling calculation of BinaryPath.
            // BinaryPropertyNameAsString = propertyName;

            PolymorphicBinaryClassInfo = classInfo;
            PolymorphicBinaryTypeInfo  = TypeMap.GetTypeInfo(classInfo.TypeSeq);

            return(classInfo.PropertyInfoForClassInfo.ConverterBase);
        }
        public void Reset()
        {
            CollectionEnumerator      = null;
            EnumeratorIndex           = 0;
            IgnoreDictionaryKeyPolicy = false;
            BinaryClassInfo           = null !;
            EnumerableIndexBytes      = 8;
            //PolymorphicBinaryClassInfo = null;
            PolymorphicBinaryPropertyInfo = null;
            OriginalDepth            = 0;
            ProcessedStartToken      = false;
            ProcessedEndToken        = false;
            ProcessedEnumerableIndex = false;
            ObjectState = StackFrameWriteObjectState.None;
            //ProcessedArrayLength = false;

            EndProperty();
        }
        public void Push()
        {
            if (_continuationCount == 0)
            {
                if (_count == 0)
                {
                    // The first stack frame is held in Current.
                    _count = 1;
                }
                else
                {
                    BinaryClassInfo binaryClassInfo = Current.GetPolymorphicBinaryPropertyInfo().RuntimeClassInfo;

                    AddCurrent();
                    Current.Reset();

                    Current.BinaryClassInfo            = binaryClassInfo;
                    Current.BinaryTypeInfo             = TypeMap.GetTypeInfo(binaryClassInfo.TypeSeq);
                    Current.DeclaredBinaryPropertyInfo = binaryClassInfo.PropertyInfoForClassInfo;
                }
            }
            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++;
                }
            }
        }
 public void Reset()
 {
     CtorArgumentStateIndex       = 0;
     CtorArgumentState            = null;
     BinaryClassInfo              = null !;
     PolymorphicBinaryClassInfo   = null;
     PolymorphicBinaryTypeInfo    = null;
     BinaryTypeInfo               = null;
     PropertyPolymorphicConverter = null;
     ObjectState          = StackFrameObjectState.None;
     OriginalDepth        = 0;
     PropertyIndex        = 0;
     PropertyRefCache     = null;
     ReturnValue          = null;
     EnumerableIndexBytes = 0;
     EnumerableLength     = 0;
     EnumerableIndex      = 0;
     PropertyValueCache   = null;
     RefState             = RefState.None;
     EndProperty();
 }
        public void Initialize(Type type, BinarySerializerOptions options, bool supportContinuation)
        {
            BinaryClassInfo binaryClassInfo = options.GetOrAddClass(type);

            Current.BinaryClassInfo = binaryClassInfo;

            // The initial BinaryPropertyInfo will be used to obtain the converter.
            Current.BinaryPropertyInfo = binaryClassInfo.PropertyInfoForClassInfo;

            Current.BinaryTypeInfo = TypeMap.GetTypeInfo(type);
            Current.TypeMap        = TypeMap;

            if (options.ReferenceHandler != null)
            {
                ReferenceResolver = options.ReferenceHandler !.CreateResolver(writing: false);
            }
            else
            {
                ReferenceResolver = new ObjectReferenceResolver();
            }

            SupportContinuation = supportContinuation;
            UseFastPath         = !supportContinuation;
        }