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


C# JsonWriter.WriteStartConstructor方法代碼示例

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


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


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