Exemplo n.º 1
0
        /// <include file='doc\LOSFormatter.uex' path='docs/doc[@for="LosFormatter.Deserialize2"]/*' />
        /// <devdoc>
        ///    <para>Deserializes a LOS formatted object from a string.</para>
        /// </devdoc>
        public object Deserialize(string input)
        {
#if NO_BASE64
            char[] data = input.ToCharArray();
#else
            byte[] dataBytes = Convert.FromBase64String(input);

            int dataLength = -1;
            if (EnableViewStateMac)
            {
                try {
                    dataBytes = MachineKey.GetDecodedData(dataBytes, _macKey, 0, dataBytes.Length, ref dataLength);
                }
                catch {
                    throw new HttpException(HttpRuntime.FormatResourceString(SR.Invalid_Viewstate));
                }
            }

            if (dataLength == -1)
            {
                dataLength = dataBytes.Length;
            }

            char[] data = EncodingInstance.GetChars(dataBytes, 0, dataLength);
#endif


            // clear or allocate name and type tables.
            //
            if (_deserializedTypeTable == null)
            {
                _deserializedTypeTable      = new ArrayList();
                _deserializedConverterTable = new ListDictionary();
            }
            else
            {
                _deserializedTypeTable.Clear();
                _deserializedConverterTable.Clear();
            }

            _builder    = (char[])_charBufferAllocator.GetBuffer();
            _recyclable = true;

            // DeserializeValueInternal is recursive, so we just kick this off
            // starting at 0
            _current             = 0;
            _deserializationData = data;
            object ret = DeserializeValueInternal();

            if (_recyclable)
            {
                _charBufferAllocator.ReuseBuffer(_builder);
            }

            return(ret);
        }