当前位置: 首页>>代码示例>>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;未经允许,请勿转载。