using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Text;
namespace CPF.Windows.Json
{
///
/// 提供了用于在序列化中的一些配置
/// Provides some configuration for serialization
///
public class JsonSerializerHandler
{
#region pregenerated metas
internal static readonly FieldInfo _Option = typeof(JsonSerializerHandler).GetField(nameof(Option));
internal static readonly FieldInfo _SerializeStacks = typeof(JsonSerializerHandler).GetField(nameof(SerializeStacks), BindingFlags.NonPublic | BindingFlags.Instance);
internal static readonly FieldInfo _CommaIndexLists = typeof(JsonSerializerHandler).GetField(nameof(CommaIndexLists), BindingFlags.NonPublic | BindingFlags.Instance);
internal static readonly MethodInfo _WriteStringInvoke = typeof(Action).GetMethod("Invoke");
internal static readonly FieldInfo _WriteString = typeof(JsonSerializerHandler).GetField(nameof(WriteString));
#endregion
internal JsonSerializerHandler(StringBuilder stringBuilder) {
this.stringBuilder = stringBuilder;
WriteString = str => this.stringBuilder.Append(str);
WriteChars = (chars, start, length) => this.stringBuilder.Append(chars, start, length);
WriteChar = @char => this.stringBuilder.Append(@char);
WriteLong = @long => this.stringBuilder.Append(@long);
}
internal JsonSerializerHandler(StreamWriter streamWriter)
{
this.streamWriter = streamWriter;
WriteString = str => this.streamWriter.Write(str);
WriteChars = (chars, start, length) => this.streamWriter.Write(chars, start, length);
WriteChar = @char => this.streamWriter.Write(@char);
WriteLong = @long => this.streamWriter.Write(@long);
}
internal StringBuilder stringBuilder;
internal StreamWriter streamWriter;
///
/// Write Long
///
public Action WriteLong;
///
/// Write Char
///
public Action WriteChar;
///
/// Write String
///
public Action WriteString;
///
/// Write Chars
///
public Action WriteChars;
///
/// Json Serializer Option
///
public JsonSerializerOption Option = null;
///
/// Used for infinite loop interreferences
///
internal Stack