本文整理汇总了C#中JsonWriter.WriteEndObject方法的典型用法代码示例。如果您正苦于以下问题:C# JsonWriter.WriteEndObject方法的具体用法?C# JsonWriter.WriteEndObject怎么用?C# JsonWriter.WriteEndObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonWriter
的用法示例。
在下文中一共展示了JsonWriter.WriteEndObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExportDataSet
private static void ExportDataSet(ExportContext context, DataSet dataSet, JsonWriter writer)
{
Debug.Assert(context != null);
Debug.Assert(dataSet != null);
Debug.Assert(writer != null);
writer.WriteStartObject();
foreach (DataTable table in dataSet.Tables)
{
writer.WriteMember(table.TableName);
//
// If there is an exporter (perhaps an override) for the
// DataTable in effect then use it. Otherwise our
// DataTableExporter.
//
IExporter tableExporter = context.FindExporter(table.GetType());
if (tableExporter != null)
tableExporter.Export(context, table, writer);
else
DataTableExporter.ExportTable(context, table, writer);
}
writer.WriteEndObject();
}
示例2: ExportValue
protected override void ExportValue(ExportContext context, object value, JsonWriter writer)
{
Debug.Assert(context != null);
Debug.Assert(value != null);
Debug.Assert(writer != null);
if (_properties.Count == 0)
{
writer.WriteString(value.ToString());
}
else
{
writer.WriteStartObject();
foreach (PropertyDescriptor property in _properties)
{
object propertyValue = property.GetValue(value);
if (!JsonNull.LogicallyEquals(propertyValue))
{
writer.WriteMember(property.Name);
context.Export(propertyValue, writer);
}
}
writer.WriteEndObject();
}
}
示例3: FormatOther
protected override void FormatOther(object o, JsonWriter writer)
{
if (writer == null)
throw new ArgumentNullException("writer");
if (JNull.LogicallyEquals(o))
{
FormatNull(o, writer);
return;
}
writer.WriteStartObject();
if (_properties == null)
_properties = TypeDescriptor.GetProperties(o);
foreach (PropertyDescriptor property in _properties)
{
// TODO: Allow someone to indicate via an attribute (e.g. JsonIgnore) that a property should be excluded.
object value = property.GetValue(o);
if (!JNull.LogicallyEquals(value))
{
writer.WriteMember(property.Name);
writer.WriteValue(value);
}
}
writer.WriteEndObject();
}
示例4: 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)
{
IEntityKeyMember entityKeyMember = DynamicWrapper.CreateWrapper<IEntityKeyMember>(value);
Type keyType = (entityKeyMember.Value != null) ? entityKeyMember.Value.GetType() : null;
writer.WriteStartObject();
writer.WritePropertyName("Key");
writer.WriteValue(entityKeyMember.Key);
writer.WritePropertyName("Type");
writer.WriteValue((keyType != null) ? keyType.FullName : null);
writer.WritePropertyName("Value");
if (keyType != null)
{
string valueJson;
if (JsonSerializerInternalWriter.TryConvertToString(entityKeyMember.Value, keyType, out valueJson))
writer.WriteValue(valueJson);
else
writer.WriteValue(entityKeyMember.Value);
}
else
{
writer.WriteNull();
}
writer.WriteEndObject();
}
示例5: 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)
{
DataTable table = (DataTable)value;
DefaultContractResolver resolver = serializer.ContractResolver as DefaultContractResolver;
writer.WriteStartArray();
foreach (DataRow row in table.Rows)
{
writer.WriteStartObject();
foreach (DataColumn column in row.Table.Columns)
{
object columnValue = row[column];
if (serializer.NullValueHandling == NullValueHandling.Ignore && (columnValue == null || columnValue == DBNull.Value))
{
continue;
}
writer.WritePropertyName((resolver != null) ? resolver.GetResolvedPropertyName(column.ColumnName) : column.ColumnName);
serializer.Serialize(writer, columnValue);
}
writer.WriteEndObject();
}
writer.WriteEndArray();
}
示例6: 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)
{
DefaultContractResolver resolver = serializer.ContractResolver as DefaultContractResolver;
IEntityKeyMember entityKeyMember = DynamicWrapper.CreateWrapper<IEntityKeyMember>(value);
Type keyType = (entityKeyMember.Value != null) ? entityKeyMember.Value.GetType() : null;
writer.WriteStartObject();
writer.WritePropertyName((resolver != null) ? resolver.GetResolvedPropertyName(KeyPropertyName) : KeyPropertyName);
writer.WriteValue(entityKeyMember.Key);
writer.WritePropertyName((resolver != null) ? resolver.GetResolvedPropertyName(TypePropertyName) : TypePropertyName);
writer.WriteValue((keyType != null) ? keyType.FullName : null);
writer.WritePropertyName((resolver != null) ? resolver.GetResolvedPropertyName(ValuePropertyName) : ValuePropertyName);
if (keyType != null)
{
string valueJson;
if (JsonSerializerInternalWriter.TryConvertToString(entityKeyMember.Value, keyType, out valueJson))
writer.WriteValue(valueJson);
else
writer.WriteValue(entityKeyMember.Value);
}
else
{
writer.WriteNull();
}
writer.WriteEndObject();
}
示例7: 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)
{
EnsureReflectionObject(value.GetType());
DefaultContractResolver resolver = serializer.ContractResolver as DefaultContractResolver;
string keyName = (string)_reflectionObject.GetValue(value, KeyPropertyName);
object keyValue = _reflectionObject.GetValue(value, ValuePropertyName);
Type keyValueType = (keyValue != null) ? keyValue.GetType() : null;
writer.WriteStartObject();
writer.WritePropertyName((resolver != null) ? resolver.GetResolvedPropertyName(KeyPropertyName) : KeyPropertyName);
writer.WriteValue(keyName);
writer.WritePropertyName((resolver != null) ? resolver.GetResolvedPropertyName(TypePropertyName) : TypePropertyName);
writer.WriteValue((keyValueType != null) ? keyValueType.FullName : null);
writer.WritePropertyName((resolver != null) ? resolver.GetResolvedPropertyName(ValuePropertyName) : ValuePropertyName);
if (keyValueType != null)
{
string valueJson;
if (JsonSerializerInternalWriter.TryConvertToString(keyValue, keyValueType, out valueJson))
writer.WriteValue(valueJson);
else
writer.WriteValue(keyValue);
}
else
{
writer.WriteNull();
}
writer.WriteEndObject();
}
示例8: WriteJsonValue
private void WriteJsonValue(JsonWriter writer, IJsonValue value)
{
switch (value.ValueType)
{
case JsonValueType.Array:
{
JsonArray a = value.GetArray();
writer.WriteStartArray();
for (int i = 0; i < a.Count; i++)
{
WriteJsonValue(writer, a[i]);
}
writer.WriteEndArray();
}
break;
case JsonValueType.Boolean:
{
writer.WriteValue(value.GetBoolean());
}
break;
case JsonValueType.Null:
{
writer.WriteNull();
}
break;
case JsonValueType.Number:
{
// JsonValue doesn't support integers
// serialize whole numbers without a decimal point
double d = value.GetNumber();
bool isInteger = (d % 1 == 0);
if (isInteger && d <= long.MaxValue && d >= long.MinValue)
writer.WriteValue(Convert.ToInt64(d));
else
writer.WriteValue(d);
}
break;
case JsonValueType.Object:
{
JsonObject o = value.GetObject();
writer.WriteStartObject();
foreach (KeyValuePair<string, IJsonValue> v in o)
{
writer.WritePropertyName(v.Key);
WriteJsonValue(writer, v.Value);
}
writer.WriteEndObject();
}
break;
case JsonValueType.String:
{
writer.WriteValue(value.GetString());
}
break;
default:
throw new ArgumentOutOfRangeException("ValueType");
}
}
示例9: WriteJson
private void WriteJson(JsonWriter writer, Regex regex)
{
writer.WriteStartObject();
writer.WritePropertyName("Pattern");
writer.WriteValue(regex.ToString());
writer.WritePropertyName("Options");
writer.WriteValue(regex.Options);
writer.WriteEndObject();
}
示例10: ExportValue
protected override void ExportValue(ExportContext context, object value, JsonWriter writer)
{
if (context == null) throw new ArgumentNullException("context");
if (writer == null) throw new ArgumentNullException("writer");
writer.WriteStartObject();
ExportMembers(context, (ExpandoObject) value, writer);
writer.WriteEndObject();
}
示例11: 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>
public override void WriteJson(JsonWriter writer, object value)
{
XmlNode node = value as XmlNode;
if (node == null)
throw new ArgumentException("Value must be an XmlNode", "value");
writer.WriteStartObject();
SerializeNode(writer, node, true);
writer.WriteEndObject();
}
示例12: FormatTable
internal static void FormatTable(DataTable table, JsonWriter writer)
{
Debug.Assert(table != null);
Debug.Assert(writer != null);
writer.WriteStartObject();
writer.WriteMember("rows");
writer.WriteValue(table.Rows);
writer.WriteEndObject();
}
示例13: FormatDataSet
private static void FormatDataSet(DataSet dataSet, JsonWriter writer)
{
writer.WriteStartObject();
foreach (DataTable table in dataSet.Tables)
{
writer.WriteMember(table.TableName);
DataTableFormatter.FormatTable(table, writer);
}
writer.WriteEndObject();
}
示例14: FormatRowView
private static void FormatRowView(DataRowView rowView, JsonWriter writer)
{
writer.WriteStartObject();
foreach (DataColumn column in rowView.DataView.Table.Columns)
{
writer.WriteMember(column.ColumnName);
writer.WriteValue(rowView[column.Ordinal]);
}
writer.WriteEndObject();
}
示例15: 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)
{
Type t = value.GetType();
PropertyInfo keyProperty = t.GetProperty("Key");
PropertyInfo valueProperty = t.GetProperty("Value");
writer.WriteStartObject();
writer.WritePropertyName("Key");
serializer.Serialize(writer, ReflectionUtils.GetMemberValue(keyProperty, value));
writer.WritePropertyName("Value");
serializer.Serialize(writer, ReflectionUtils.GetMemberValue(valueProperty, value));
writer.WriteEndObject();
}