当前位置: 首页>>代码示例>>C#>>正文


C# JsonTextWriter.WriteRawValue方法代码示例

本文整理汇总了C#中Raven.Imports.Newtonsoft.Json.JsonTextWriter.WriteRawValue方法的典型用法代码示例。如果您正苦于以下问题:C# JsonTextWriter.WriteRawValue方法的具体用法?C# JsonTextWriter.WriteRawValue怎么用?C# JsonTextWriter.WriteRawValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Raven.Imports.Newtonsoft.Json.JsonTextWriter的用法示例。


在下文中一共展示了JsonTextWriter.WriteRawValue方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GenerateOutput

		private static string GenerateOutput(Dictionary<string, object> result, int indent)
		{
			var stringWriter = new StringWriter();
			var writer = new JsonTextWriter(stringWriter)
			{
				Formatting = Formatting.Indented
			};

			writer.WriteStartObject();
			foreach (var o in result)
			{
				writer.WritePropertyName(o.Key);
				var ravenJToken = o.Value as RavenJToken;
				if (ravenJToken != null)
				{
					ravenJToken.WriteTo(writer);
					continue;
				}
				var conflicted = o.Value as Conflicted;
				if (conflicted != null)
				{
					writer.WriteComment(">>>> conflict start");
					writer.WriteStartArray();
					foreach (var token in conflicted.Values)
					{
						token.WriteTo(writer);
					}
					writer.WriteEndArray();
					writer.WriteComment("<<<< conflict end");
					continue;
				}

				var arrayWithWarning = o.Value as ArrayWithWarning;
				if(arrayWithWarning != null)
				{
					writer.WriteComment(">>>> auto merged array start");
					arrayWithWarning.MergedArray.WriteTo(writer);
					writer.WriteComment("<<<< auto merged array end");
					continue;
				}

				var resolver = o.Value as ConflictsResolver;
				if(resolver != null)
				{
					using(var stringReader = new StringReader(resolver.Resolve(indent + 1)))
					{
						var first = true;
						string line ;
						while((line = stringReader.ReadLine()) != null)
						{
							if(first == false)
							{
								writer.WriteRaw(Environment.NewLine);
								for (var i = 0; i < indent; i++)
								{
									writer.WriteRaw(new string(writer.IndentChar, writer.Indentation));
								}
							}
							if(first)
								writer.WriteRawValue(line);
							else
								writer.WriteRaw(line);


							first = false;

						}
					}
					continue;
				}
				throw new InvalidOperationException("Could not understand how to deal with: " + o.Value);
			}
			writer.WriteEndObject();
			return stringWriter.GetStringBuilder().ToString();
		}
开发者ID:925coder,项目名称:ravendb,代码行数:75,代码来源:ConflictsResolver.cs

示例2: WriteRawData

        private void WriteRawData(JsonTextWriter writer, String data, int indent)
        {
            var sb = new StringBuilder();
            using (var stringReader = new StringReader(data))
            {
                var first = true;
                string line;
                while ((line = stringReader.ReadLine()) != null)
                {
                    if (first == false)
                    {
                        sb.AppendLine();
                        for (var i = 0; i < indent; i++)
                        {
                            sb.Append(writer.IndentChar, writer.Indentation);
                        }
                    }

                    sb.Append(line);

                    first = false;
                }
            }
            writer.WriteRawValue(sb.ToString());
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:25,代码来源:ConflictsResolver.cs

示例3: WriteRawValue

    public void WriteRawValue()
    {
      StringBuilder sb = new StringBuilder();
      StringWriter sw = new StringWriter(sb);

      using (JsonWriter jsonWriter = new JsonTextWriter(sw))
      {
        int i = 0;
        string rawJson = "[1,2]";

        jsonWriter.WriteStartObject();

        while (i < 3)
        {
          jsonWriter.WritePropertyName("d" + i);
          jsonWriter.WriteRawValue(rawJson);

          i++;
        }

        jsonWriter.WriteEndObject();
      }

      Assert.AreEqual(@"{""d0"":[1,2],""d1"":[1,2],""d2"":[1,2]}", sb.ToString());
    }
开发者ID:925coder,项目名称:ravendb,代码行数:25,代码来源:JsonTextWriterTest.cs


注:本文中的Raven.Imports.Newtonsoft.Json.JsonTextWriter.WriteRawValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。