Exemplo n.º 1
0
        internal override Object GetSimpleValueInElement(L3TypeManager typeManager)
        {
            if (!GetNextXmlPart())
            {
                throw new Exception();
            }

            if (this.xmlReader.NodeType == XmlNodeType.EndElement)
            {
#if DEBUG
                if (typeManager.l2TypeManager.L1TypeManager.type != typeof(string))
                {
                    throw new Exception();
                }
#endif
                return(DeserializationFormatter.NoValue);
            }

#if DEBUG
            if (this.xmlReader.NodeType != XmlNodeType.Text)
            {
                throw new Exception();
            }
#endif
            var rawValue = this.xmlReader.Value;
            return(DeserializationFormatter.TranscodeStringToPrimitiveObject(rawValue, typeManager));
        }
Exemplo n.º 2
0
        // - - - -

        /// <summary>
        /// Prepare a serializer and deserializer following your parameters and modifiers.
        /// <para>Parameters.Stream must be defined.</para>
        /// </summary>
        /// <param name="parameters">Detailed parameters.</param>
        public UniversalSerializer(
            Parameters parameters)
        {
            lock (SharedLock)
            {
                if (parameters.Stream == null)
                {
                    throw new ArgumentNullException("parameters.Stream");
                }
                parameters.Init();
                this.parameters = parameters;

                this.CustomFormatter   = SerializationFormatter.ChooseDefaultFormatter(parameters);
                this.CustomDeFormatter = SerializationFormatter.ChooseDefaultDeFormatter(parameters);
            }
        }
Exemplo n.º 3
0
        // ------------------------------

        internal override Object GetSimpleValueInElement(L3TypeManager typeManager)
        {
            if (!GetNextJSONPart())
            {
                throw new Exception();
            }
            if (this._JSONReader.NodeType == XmlNodeType.EndElement)
            {             // empty 'e' element.
                this.WeAlreadyObtainedJSONPart = true;
                return(null);
            }
#if DEBUG
            if (this._JSONReader.NodeType != XmlNodeType.Element || this._JSONReader.Name != "a:item")
            {
                throw new Exception();
            }
#endif

            {
                if (!GetNextJSONPart())
                {
                    throw new Exception();
                }
#if DEBUG
                if (this._JSONReader.NodeType != XmlNodeType.Text || this._JSONReader.Name != string.Empty)
                {
                    throw new Exception();
                }
#endif
            }

            string rawValue;
            {
                // JsonReaderWriterFactory is very special: it splits string when it encounters a special character.
                // Therfore, we need to concatenate this parts.

                var Texts = new StringBuilder(this._JSONReader.Value);
                while (GetNextJSONPart())
                {
                    if (this._JSONReader.NodeType != XmlNodeType.Text)
                    {
                        this.WeAlreadyObtainedJSONPart = true;
                        break;
                    }
                    Texts.Append(this._JSONReader.Value);
                }
                rawValue = Texts.ToString();
            }

            {             // passes EndElement:
                if (!GetNextJSONPart())
                {
                    throw new Exception();
                }
#if DEBUG
                if (this._JSONReader.NodeType != XmlNodeType.EndElement || this._JSONReader.Name != "a:item")
                {
                    throw new Exception();
                }
#endif
            }

            return(DeserializationFormatter.TranscodeStringToPrimitiveObject(rawValue, typeManager));
        }