當前位置: 首頁>>代碼示例>>C#>>正文


C# JsonWriter.WriteEndConstructor方法代碼示例

本文整理匯總了C#中Newtonsoft.Json.JsonWriter.WriteEndConstructor方法的典型用法代碼示例。如果您正苦於以下問題:C# JsonWriter.WriteEndConstructor方法的具體用法?C# JsonWriter.WriteEndConstructor怎麽用?C# JsonWriter.WriteEndConstructor使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Newtonsoft.Json.JsonWriter的用法示例。


在下文中一共展示了JsonWriter.WriteEndConstructor方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: WriteJson

        /// <summary>
        /// Writes the JSON representation of the object.
        /// </summary>
        /// <param name="writer">The <see cref="JsonWriter"/> to write to.</param>
        /// <param name="value">The value.</param>
        /// <param name="serializer">The calling serializer.</param>
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            long ticks;

            if (value is DateTime)
            {
                DateTime dateTime = (DateTime)value;
                DateTime utcDateTime = dateTime.ToUniversalTime();
                ticks = DateTimeUtils.ConvertDateTimeToJavaScriptTicks(utcDateTime);
            }
#if !NET20
            else if (value is DateTimeOffset)
            {
                DateTimeOffset dateTimeOffset = (DateTimeOffset)value;
                DateTimeOffset utcDateTimeOffset = dateTimeOffset.ToUniversalTime();
                ticks = DateTimeUtils.ConvertDateTimeToJavaScriptTicks(utcDateTimeOffset.UtcDateTime);
            }
#endif
            else
            {
                throw new JsonSerializationException("Expected date object value.");
            }

            writer.WriteStartConstructor("Date");
            writer.WriteValue(ticks);
            writer.WriteEndConstructor();
        }
開發者ID:HaKDMoDz,項目名稱:eStd,代碼行數:33,代碼來源:JavaScriptDateTimeConverter.cs

示例2: WriteJson

        /// <summary>
        /// Writes the JSON representation of the object.
        /// </summary>
        /// <param name="writer">The <see cref="JsonWriter"/> to write to.</param>
        /// <param name="value">The value.</param>
        /// <param name="serializer">The calling serializer.</param>
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            String isoDateTimeString;

            if (value is DateTime)
            {
                DateTime dateTime = (DateTime)value;

                if ((DateTimeStyles & DateTimeStyles.AdjustToUniversal) == DateTimeStyles.AdjustToUniversal 
                    || (DateTimeStyles & DateTimeStyles.AssumeUniversal) == DateTimeStyles.AssumeUniversal)
                    dateTime = dateTime.ToUniversalTime();

                isoDateTimeString = dateTime.ToString(DefaultDateTimeFormat);
            }
#if !PocketPC && !NET20
            else if (value is DateTimeOffset)
            {
                DateTimeOffset dateTimeOffset = (DateTimeOffset)value;

                if ((DateTimeStyles & DateTimeStyles.AdjustToUniversal) == DateTimeStyles.AdjustToUniversal
                    || (DateTimeStyles & DateTimeStyles.AssumeUniversal) == DateTimeStyles.AssumeUniversal)
                    dateTimeOffset = dateTimeOffset.ToUniversalTime();

                isoDateTimeString = dateTimeOffset.ToString(DefaultDateTimeFormat);
            }
#endif
            else
            {
                throw new Exception("Expected date object value.");
            }

            writer.WriteStartConstructor("Date");
            writer.WriteValue(isoDateTimeString);
            writer.WriteEndConstructor();
        }
開發者ID:borisdj,項目名稱:dextop,代碼行數:41,代碼來源:DextopUtil.DextopDateTimeConverter.cs

示例3: WriteJson

 public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
 {
   if (!(value is DateTime))
     throw new JsonSerializationException("Expected date object value.");
   long num = JsonConvert.ConvertDateTimeToJavaScriptTicks(((DateTime) value).ToUniversalTime());
   writer.WriteStartConstructor("Date");
   writer.WriteValue(num);
   writer.WriteEndConstructor();
 }
開發者ID:tanis2000,項目名稱:FEZ,代碼行數:9,代碼來源:JavaScriptDateTimeConverter.cs

示例4: WriteJson

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (value is DateTime)
            {
                DateTime date = (DateTime)value;

                if (date.Equals(DateTime.MinValue))
                {
                    writer.WriteRawValue("null");
                }
                else
                {
                    string template = (date.TimeOfDay == new TimeSpan(0, 0, 0)) ? "{0},{1},{2}" : "{0},{1},{2},{3},{4},{5}";

                    writer.WriteStartConstructor("Date");
                    writer.WriteRawValue(
                        string.Format(template, date.Year, date.Month - 1, date.Day,
                                      date.Hour, date.Minute, date.Second));
                    writer.WriteEndConstructor();
                }
            }
        }
開發者ID:pgodwin,項目名稱:Ext.net,代碼行數:22,代碼來源:CtorDateTimeJsonConverter.cs

示例5: WriteJson

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            string v;
            if (value != null && !string.IsNullOrEmpty((v = value.ToString( ))))
            {

                if (System.Text.RegularExpressions.Regex.IsMatch(v, @"\[*\]"))
                {
                    writer.WriteRawValue(v);
                }
                else if (System.Text.RegularExpressions.Regex.IsMatch(v, @"\{*\}"))
                {
                    writer.WriteRawValue(v);
                }
                else
                {
                    writer.WriteStartConstructor(value.ToString( ));
                    writer.WriteEndConstructor( );
                }
            }
            else
                writer.WriteNull( );
        }
開發者ID:eleooo,項目名稱:App,代碼行數:23,代碼來源:JavaScriptObjectConverter.cs

示例6: WriteTo

 public override void WriteTo(JsonWriter writer, params JsonConverter[] converters)
 {
   writer.WriteStartConstructor(this._name);
   foreach (JToken jtoken in this.Children())
     jtoken.WriteTo(writer, converters);
   writer.WriteEndConstructor();
 }
開發者ID:tanis2000,項目名稱:FEZ,代碼行數:7,代碼來源:JConstructor.cs

示例7: JsonReaderToJsonWriter

 public void JsonReaderToJsonWriter(JsonReader reader, JsonWriter writer)
 {
     do
     {
         switch (reader.TokenType)
         {
             case JsonToken.None:
                 break;
             case JsonToken.StartObject:
                 writer.WriteStartObject();
                 break;
             case JsonToken.StartArray:
                 writer.WriteStartArray();
                 break;
             case JsonToken.PropertyName:
                 string propertyName = reader.Value.ToString();
                 writer.WritePropertyName(ConvertPropertyName(propertyName));
                 break;
             case JsonToken.Comment:
                 writer.WriteComment((reader.Value != null) ? reader.Value.ToString() : null);
                 break;
             case JsonToken.Integer:
                 writer.WriteValue(Convert.ToInt64(reader.Value, CultureInfo.InvariantCulture));
                 break;
             case JsonToken.Float:
                 object value = reader.Value;
                 if (value is decimal)
                 {
                     writer.WriteValue((decimal)value);
                 }
                 else if (value is double)
                 {
                     writer.WriteValue((double)value);
                 }
                 else if (value is float)
                 {
                     writer.WriteValue((float)value);
                 }
                 else
                 {
                     writer.WriteValue(Convert.ToDouble(value, CultureInfo.InvariantCulture));
                 }
                 break;
             case JsonToken.String:
                 writer.WriteValue(reader.Value.ToString());
                 break;
             case JsonToken.Boolean:
                 writer.WriteValue(Convert.ToBoolean(reader.Value, CultureInfo.InvariantCulture));
                 break;
             case JsonToken.Null:
                 if (this.PropertyNullValueReplaceValue != null)
                 {
                     writer.WriteValue(this.PropertyNullValueReplaceValue);
                 }
                 else
                 {
                     writer.WriteNull();
                 }
                 break;
             case JsonToken.Undefined:
                 writer.WriteUndefined();
                 break;
             case JsonToken.EndObject:
                 writer.WriteEndObject();
                 break;
             case JsonToken.EndArray:
                 writer.WriteEndArray();
                 break;
             case JsonToken.EndConstructor:
                 writer.WriteEndConstructor();
                 break;
             case JsonToken.Date:
                 if (reader.Value is DateTimeOffset)
                 {
                     writer.WriteValue((DateTimeOffset)reader.Value);
                 }
                 else
                 {
                     writer.WriteValue(Convert.ToDateTime(reader.Value, CultureInfo.InvariantCulture));
                 }
                 break;
             case JsonToken.Raw:
                 writer.WriteRawValue((reader.Value != null) ? reader.Value.ToString() : null);
                 break;
             case JsonToken.Bytes:
                 if (reader.Value is Guid)
                 {
                     writer.WriteValue((Guid)reader.Value);
                 }
                 else
                 {
                     writer.WriteValue((byte[])reader.Value);
                 }
                 break;
         }
     } while (reader.Read());
 }
開發者ID:269378737,項目名稱:go81,代碼行數:97,代碼來源:CustomJsonConverter.cs


注:本文中的Newtonsoft.Json.JsonWriter.WriteEndConstructor方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。