public void CallSerialize(SubString value)
 {
     if (value.String == null)
     {
         CharStream.WriteJsonNull();
     }
     else
     {
         CharStream.WriteJson(ref value, Config.NullChar);
     }
 }
 public void CallSerialize(byte?value)
 {
     if (value.HasValue)
     {
         CallSerialize(value.Value);
     }
     else
     {
         CharStream.WriteJsonNull();
     }
 }
 public void CallSerialize(string value)
 {
     if (value != null)
     {
         primitiveSerialize(value);
     }
     else
     {
         CharStream.WriteJsonNull();
     }
 }
 public void CallSerialize(System.Guid?value)
 {
     if (value.HasValue)
     {
         CallSerialize((System.Guid)value);
     }
     else
     {
         CharStream.WriteJsonNull();
     }
 }
 public void CallSerialize(DateTime?value)
 {
     if (value.HasValue)
     {
         CallSerialize((DateTime)value);
     }
     else
     {
         CharStream.WriteJsonNull();
     }
 }
 public void CallSerialize(decimal?value)
 {
     if (value.HasValue)
     {
         CharStream.SimpleWrite(((decimal)value).ToString());
     }
     else
     {
         CharStream.WriteJsonNull();
     }
 }
 public void CallSerialize(Type type)
 {
     if (type == null)
     {
         CharStream.WriteJsonNull();
     }
     else
     {
         AutoCSer.Reflection.RemoteType remoteType = new AutoCSer.Reflection.RemoteType(type);
         TypeSerializer <AutoCSer.Reflection.RemoteType> .MemberSerialize(this, ref remoteType);
     }
 }
Esempio n. 8
0
 public void TypeSerialize <valueType>(valueType value)
 {
     if (value == null)
     {
         CharStream.WriteJsonNull();
     }
     else
     {
         TypeSerializer <valueType> .Serialize(this, ref value);
     }
 }
        /// <summary>
        /// 时间转换
        /// </summary>
        /// <param name="value">时间</param>
        internal void SerializeDateTime(DateTime value)
        {
            if (value == DateTime.MinValue && Config.IsDateTimeMinNull)
            {
                CharStream.WriteJsonNull();
                return;
            }
            switch (Config.DateTimeType)
            {
            case DateTimeType.Default: CharStream.WriteJsonString(value); return;

            case DateTimeType.Sql: CharStream.WriteJsonSqlString(value); return;

            case DateTimeType.Javascript:
                CharStream.WriteJsonNewDate();
                CallSerialize(((value.Kind == DateTimeKind.Utc ? value.Ticks + Date.LocalTimeTicks : value.Ticks) - AutoCSer.JsonDeSerializer.JavascriptLocalMinTimeTicks) / TimeSpan.TicksPerMillisecond);
                CharStream.Data.Write(')');
                return;

            case DateTimeType.ThirdParty:
                CharStream.WriteJsonOtherDate();
                CallSerialize(((value.Kind == DateTimeKind.Utc ? value.Ticks + Date.LocalTimeTicks : value.Ticks) - AutoCSer.JsonDeSerializer.JavascriptLocalMinTimeTicks) / TimeSpan.TicksPerMillisecond);
                CharStream.WriteJsonOtherDateEnd();
                return;

            case DateTimeType.CustomFormat:
                if (Config.DateTimeCustomFormat == null)
                {
                    primitiveSerialize(value.ToString());
                }
                else
                {
                    primitiveSerialize(value.ToString(Config.DateTimeCustomFormat));
                }
                return;
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="value"></param>
        private void serialize(ref Node value)
        {
            switch (value.Type)
            {
            case NodeType.Dictionary:
                CharStream.Write('{');
                if ((int)value.Int64 != 0)
                {
                    KeyValue <Node, Node>[] array = value.DictionaryArray;
                    for (int index = 0; index != (int)value.Int64; ++index)
                    {
                        if (index != 0)
                        {
                            CharStream.Write(',');
                        }
                        serialize(ref array[index].Key);
                        CharStream.Write(':');
                        serialize(ref array[index].Value);
                    }
                }
                CharStream.Write('}');
                return;

            case NodeType.Array:
                CharStream.Write('[');
                if ((int)value.Int64 != 0)
                {
                    Node[] array = value.ListArray;
                    for (int index = 0; index != (int)value.Int64; ++index)
                    {
                        if (index != 0)
                        {
                            CharStream.Write(',');
                        }
                        serialize(ref array[index]);
                        CharStream.Write(':');
                        serialize(ref array[index]);
                    }
                }
                CharStream.Write(']');
                return;

            case NodeType.String:
            {
                SubString subString = value.SubString;
                CharStream.WriteJson(ref subString, Config.NullChar);
            }
                return;

            case NodeType.QuoteString:
            case NodeType.ErrorQuoteString:
                CharStream.PrepCharSize(value.SubString.Length + 2);
                CharStream.Data.Write((char)value.Int64);
                CharStream.Write(ref value.SubString);
                CharStream.Data.Write((char)value.Int64);
                return;

            case NodeType.NumberString:
                if ((int)value.Int64 == 0)
                {
                    CharStream.Write(ref value.SubString);
                }
                else
                {
                    CharStream.PrepCharSize(value.SubString.Length + 2);
                    CharStream.Data.Write((char)value.Int64);
                    CharStream.Write(ref value.SubString);
                    CharStream.Data.Write((char)value.Int64);
                }
                return;

            case NodeType.Bool:
                CallSerialize((int)value.Int64 != 0);
                return;

            case NodeType.DateTimeTick:
                CallSerialize(new DateTime(value.Int64, DateTimeKind.Local));
                return;

            case NodeType.NaN:
                CharStream.WriteJsonNaN();
                return;

            case NodeType.PositiveInfinity:
                if (Config.IsInfinityToNaN)
                {
                    CharStream.WriteJsonNaN();
                }
                else
                {
                    CharStream.WritePositiveInfinity();
                }
                return;

            case NodeType.NegativeInfinity:
                if (Config.IsInfinityToNaN)
                {
                    CharStream.WriteJsonNaN();
                }
                else
                {
                    CharStream.WriteNegativeInfinity();
                }
                return;

            default:
                CharStream.WriteJsonNull();
                return;
            }
        }