private Type GetTypeFromCode(string typeCode)
        {
            RuntimeTypeHandle typeHandle;

            if (!this._typeHandleMap.TryGetValue(typeCode, out typeHandle))
            {
                SerializationExceptions.ThrowSerializationException(
                    String.Format(CultureInfo.CurrentCulture, "Unknown type {0}.", StringEscape.ForDisplay(typeCode))
                    );
            }

            return(Type.GetTypeFromHandle(typeHandle));
        }
        private static int GetSize(IList <string> value, StringEscape escape)
        {
            int size = 0;

            if (escape == StringEscape.Default)
            {
                for (int i = 0; i < value.Count; i++)
                {
                    if (value[i] != null)
                    {
                        size += value[i].Length;
                    }
                    else
                    {
                        size += 4;
                    }
                }
            }
            //else if(escape == StringEscape.EscapeHtml)
            //{
            //    for (int i = 0; i < value.Length; i++)
            //    {
            //        if (value[i] != null)
            //            size += value[i].Length;
            //        else
            //            size += 4;
            //    }
            //}
            else if (escape == StringEscape.EscapeNonAscii)
            {
                for (int i = 0; i < value.Count; i++)
                {
                    if (value[i] != null)
                    {
                        size += value[i].Length * 6;
                    }
                    else
                    {
                        size += 4;
                    }
                }
            }
            return(size + (value.Count * 3) + 2);
        }
Exemple #3
0
        protected internal override T UnpackFromCore(Unpacker unpacker)
        {
            return
                (TypeInfoEncoder.Decode(
                     unpacker,
                     u =>
            {
                var typeCode = u.LastReadData.AsString();

                RuntimeTypeHandle typeHandle;
                if (!this._typeHandleMap.TryGetValue(typeCode, out typeHandle))
                {
                    throw new SerializationException(
                        String.Format(CultureInfo.CurrentCulture, "Unknown type {0}.", StringEscape.ForDisplay(typeCode))
                        );
                }

                return Type.GetTypeFromHandle(typeHandle);
            },
                     (t, u) => ( T )this.GetActualTypeSerializer(t).UnpackFrom(u)
                     ));
        }