本文整理汇总了C#中Raven.Imports.Newtonsoft.Json.JsonTextWriter.WriteComment方法的典型用法代码示例。如果您正苦于以下问题:C# JsonTextWriter.WriteComment方法的具体用法?C# JsonTextWriter.WriteComment怎么用?C# JsonTextWriter.WriteComment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Raven.Imports.Newtonsoft.Json.JsonTextWriter
的用法示例。
在下文中一共展示了JsonTextWriter.WriteComment方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteToken
private void WriteToken(JsonTextWriter writer, string propertyName, Object propertyValue)
{
if (isMetadataResolver && (
propertyName.StartsWith("Raven-Replication-") ||
propertyName.StartsWith("@") ||
propertyName == "Last-Modified" ||
propertyName == "Raven-Last-Modified"
) )
{
return;
}
writer.WritePropertyName(propertyName);
var ravenJToken = propertyValue as RavenJToken;
if (ravenJToken != null)
{
ravenJToken.WriteTo(writer);
return;
}
var conflicted = propertyValue 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");
return;
}
var arrayWithWarning = propertyValue as ArrayWithWarning;
if (arrayWithWarning != null)
{
writer.WriteComment(">>>> auto merged array start");
arrayWithWarning.MergedArray.WriteTo(writer);
writer.WriteComment("<<<< auto merged array end");
return;
}
throw new InvalidOperationException("Could not understand how to deal with: " + propertyValue);
}
示例2: Indenting
public void Indenting()
{
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
using (JsonWriter jsonWriter = new JsonTextWriter(sw))
{
jsonWriter.Formatting = Formatting.Indented;
jsonWriter.WriteStartObject();
jsonWriter.WritePropertyName("CPU");
jsonWriter.WriteValue("Intel");
jsonWriter.WritePropertyName("PSU");
jsonWriter.WriteValue("500W");
jsonWriter.WritePropertyName("Drives");
jsonWriter.WriteStartArray();
jsonWriter.WriteValue("DVD read/writer");
jsonWriter.WriteComment("(broken)");
jsonWriter.WriteValue("500 gigabyte hard drive");
jsonWriter.WriteValue("200 gigabype hard drive");
jsonWriter.WriteEnd();
jsonWriter.WriteEndObject();
Assert.AreEqual(WriteState.Start, jsonWriter.WriteState);
}
// {
// "CPU": "Intel",
// "PSU": "500W",
// "Drives": [
// "DVD read/writer"
// /*(broken)*/,
// "500 gigabyte hard drive",
// "200 gigabype hard drive"
// ]
// }
string expected = @"{
""CPU"": ""Intel"",
""PSU"": ""500W"",
""Drives"": [
""DVD read/writer""
/*(broken)*/,
""500 gigabyte hard drive"",
""200 gigabype hard drive""
]
}";
string result = sb.ToString();
Assert.AreEqual(expected, result);
}
示例3: 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();
}
示例4: CloseWithRemainingContent
public void CloseWithRemainingContent()
{
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
using (JsonWriter jsonWriter = new JsonTextWriter(sw))
{
jsonWriter.Formatting = Formatting.Indented;
jsonWriter.WriteStartObject();
jsonWriter.WritePropertyName("CPU");
jsonWriter.WriteValue("Intel");
jsonWriter.WritePropertyName("PSU");
jsonWriter.WriteValue("500W");
jsonWriter.WritePropertyName("Drives");
jsonWriter.WriteStartArray();
jsonWriter.WriteValue("DVD read/writer");
jsonWriter.WriteComment("(broken)");
jsonWriter.WriteValue("500 gigabyte hard drive");
jsonWriter.WriteValue("200 gigabype hard drive");
jsonWriter.Close();
}
string expected = @"{
""CPU"": ""Intel"",
""PSU"": ""500W"",
""Drives"": [
""DVD read/writer""
/*(broken)*/,
""500 gigabyte hard drive"",
""200 gigabype hard drive""
]
}";
string result = sb.ToString();
Assert.AreEqual(expected, result);
}