public static void WriteConfigAsJson(Type type, string folder)
    {
        var exportFields = ClassFieldFilter.GetConfigFieldInfo(type);

        if (exportFields.Count == 0)
        {
            return;
        }

        foreach (var field in exportFields)
        {
            if (field.GetValue(null) == null)
            {
                UnityEngine.Debug.LogErrorFormat("Export {0} is null", field.Name);
                return;
            }
            var    file = Path.Combine(folder, field.Name + ".json");
            fsData data;
            _serializer.TrySerialize(field.FieldType, field.GetValue(null), out data).AssertSuccess();
            if (File.Exists(file))
            {
                File.Delete(file);
            }
            using (FileStream fs = File.Create(file))
            {
                byte[] content = new UTF8Encoding(true).GetBytes(fsJsonPrinter.PrettyJson(data));
                fs.Write(content, 0, content.Length);
            }
        }
    }
    public override string GenerateSerializerCode(Type type)
    {
        var fields = ClassFieldFilter.GetConfigFieldInfo(type);

        return(GenSerializerStaticClassCodeByTemplate(
                   type,
                   FieldReferencedTypes(fields),
                   GenFieldReadCode(type, fields),
                   GenFieldWriteCode(type, fields)));
    }
    public override string GenerateSerializerCode(Type type)
    {
        var fields = ClassFieldFilter.GetClassFieldInfo(type);

        return(GenSerializerClassCodeByTemplate(
                   type,
                   FieldReferencedTypes(fields).Union(TypeNameReferencedTypes(type)).ToArray(),
                   string.Format("new {0}()", type.Name),
                   GenFieldReadCode(fields),
                   GenFieldWriteCode(fields)));
    }
    public static void ReadConfigAsJson(Type type, string folder)
    {
        if (readTypes.Contains(type))
        {
            return;
        }
        else
        {
            readTypes.Add(type);
        }
        var exportFields = ClassFieldFilter.GetConfigFieldInfo(type);

        if (exportFields.Count == 0)
        {
            return;
        }
        foreach (var field in exportFields)
        {
            var file = Path.Combine(folder, field.Name + ".json");
            if (!File.Exists(file))
            {
                Debug.LogWarningFormat("Json file {0} not found", field.Name);
                continue;
            }
            FileStream    fs   = File.Open(file, FileMode.Open);
            StringBuilder sb   = new StringBuilder();
            byte[]        b    = new byte[1024];
            UTF8Encoding  temp = new UTF8Encoding(true);

            while (fs.Read(b, 0, b.Length) > 0)
            {
                sb.Append(temp.GetString(b));
            }
            fs.Close();

            fsData   data;
            fsResult res = fsJsonParser.Parse(sb.ToString(), out data);
            if (res.Failed)
            {
                Debug.LogWarningFormat("Json file {0} parsed error {1}", field.Name, res.FormattedMessages);
                continue;
            }

            var value = field.GetValue(null);
            _serializer.TryDeserialize(data, field.FieldType, ref value).AssertSuccess();
            field.SetValue(null, value);
        }
    }
    public override bool inspect(ref object data, Type type, string name, string path)
    {
        var fields = ClassFieldFilter.GetClassFieldInfo(type);
        //inspect the fields
        bool changed = false;

        foreach (var fieldinfo in fields)
        {
            object value     = fieldinfo.GetValue(data);
            Type   valueType = value != null?value.GetType() : fieldinfo.FieldType;

            if (DataInspectorUtility.inspect(ref value, valueType, fieldinfo.Name, path))
            {
                fieldinfo.SetValue(data, value);
                changed = true;
            }
        }
        return(changed);
    }
    public override Type[] DirectlyUsedTypesExcludeSelf(Type type)
    {
        var fields = ClassFieldFilter.GetClassFieldInfo(type);

        return(fields.Select(f => f.FieldType).ToArray());
    }