Ejemplo n.º 1
0
        private void PrimitiveHandler(PrimitiveToken token)
        {
            Type type = typeIds[(int)token.TypeId];

            try {
                object value = ((IPrimitiveSerializer)serializerMapping[type]).Parse(token.SerialData);
                if (token.Id != null)
                {
                    id2obj[(int)token.Id] = value;
                }
                SetValue(token.Name, value);
            } catch (Exception e) {
                if (e is InvalidCastException || e is KeyNotFoundException)
                {
                    throw new PersistenceException(String.Format(
                                                       "Invalid primitive serializer configuration for type \"{0}\".",
                                                       type.AssemblyQualifiedName), e);
                }
                else
                {
                    throw new PersistenceException(String.Format(
                                                       "Unexpected exception while trying to parse object of type \"{0}\".",
                                                       type.AssemblyQualifiedName), e);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Formats the specified data token.
        /// </summary>
        /// <param name="dataToken">The data token.</param>
        /// <returns>The token in serialized form.</returns>
        protected override string Format(PrimitiveToken dataToken)
        {
            var dict = new Dictionary <string, string> {
                { "name", dataToken.Name },
                { "id", dataToken.Id.ToString() }
            };

            return(CreateNode(typeCache[dataToken.TypeId], dict,
                              ((XmlString)dataToken.SerialData).Data));
        }
Ejemplo n.º 3
0
        internal PrimitiveToken GetNextToken()
        {
            if (position >= primitives.Count)
            {
                return(null);
            }
            PrimitiveToken ret = primitives[position];

            position++;
            return(ret);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Formats the specified data token.
        /// </summary>
        /// <param name="dataToken">The data token.</param>
        /// <returns>The token in serialized form.</returns>
        protected override string Format(PrimitiveToken dataToken)
        {
            var dict = new Dictionary <string, string> {
                { "typeId", dataToken.TypeId.ToString() },
                { "name", dataToken.Name },
                { "id", dataToken.Id.ToString() }
            };

            AddTypeInfo(dataToken.TypeId, dict);
            return(CreateNode(XmlStringConstants.PRIMITIVE, dict,
                              ((XmlString)dataToken.SerialData).Data));
        }
        /// <summary>
        /// Formats the specified primitive token.
        /// </summary>
        /// <param name="primitiveToken">The primitive token.</param>
        /// <returns>The token in serialized form.</returns>
        protected override string Format(PrimitiveToken primitiveToken)
        {
            StringBuilder sb = new StringBuilder();

            if (isSepReq)
            {
                sb.Append(", ");
            }
            if (!string.IsNullOrEmpty(primitiveToken.Name))
            {
                sb.Append(primitiveToken.Name);
                if (primitiveToken.Id != null && showRefs)
                {
                    sb.Append('[');
                    sb.Append(primitiveToken.Id);
                    sb.Append(']');
                }
                sb.Append('=');
            }
            sb.Append(((DebugString)primitiveToken.SerialData).Data);
            isSepReq = true;
            return(sb.ToString());
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Formats the specified primitive token.
 /// </summary>
 /// <param name="primitiveToken">The primitive token.</param>
 /// <returns>The token in serialized form.</returns>
 protected abstract T Format(PrimitiveToken primitiveToken);
Ejemplo n.º 7
0
 internal UnknownLine(List <PrimitiveToken> primitives)
 {
     tokens = new PrimitiveToken[primitives.Count];
     primitives.CopyTo(tokens);
 }
Ejemplo n.º 8
0
        //internal bool StartOfStream
        //{
        //    get
        //    {
        //        return (position <= 0);
        //    }
        //}

        //internal void Unget()
        //{
        //    position--;
        //}

        internal void Add(PrimitiveToken token)
        {
            primitives.Add(token);
        }
Ejemplo n.º 9
0
 internal UnknownToken(PrimitiveToken token)
 {
     this.token = token;
 }