示例#1
0
    private static void MakeData(Type _dataType)
    {
        MakeFormat(_dataType);
        string filePath = SystemSetting.GetCSVFilePath() + StringExtensions.UpperCamelToSnake(_dataType.Name) + ".csv";

        using (Workaholism.IO.CsvWriter writer = new Workaholism.IO.CsvWriter(filePath, Encoding.GetEncoding("utf-8"))) {
            string[] values = memberList.ToArray();
            writer.WriteLine(values);
        }
    }
示例#2
0
    public static void MakeData(Type _type, List <MasterLoadSprite.Data> _dataObject)
    {
        string filePath = SystemSetting.GetCSVFilePath() + _type.Name + ".csv";
        List <MasterLoadSprite.Data> _MasterLoadSprite = _dataObject;

        FieldInfo[]   fieldInfoList  = CSMaker.GetFieldInfo(typeof(MakeDataNamespace.MasterLoadSprite));
        List <string> memberNameList = CSMaker.GetMemberList(typeof(MakeDataNamespace.MasterLoadSprite));
        Type          curType        = typeof(MasterLoadSprite.Data);

        using (Workaholism.IO.CsvWriter writer = new Workaholism.IO.CsvWriter(filePath, Encoding.GetEncoding("utf-8"))) {
            List <string> headData = new List <string>();

            foreach (string fieldName in memberNameList)
            {
                headData.Add("\"" + fieldName + "\"");
            }
            writer.WriteLine(headData);

            foreach (MasterLoadSprite.Data curData in _MasterLoadSprite)
            {
                List <string> lineData = new List <string>();

                int columnCount = 0;

                foreach (string fieldName in memberNameList)
                {
                    string getString = curType.InvokeMember(fieldName, BindingFlags.GetField, null, curData, null).ToString();

                    FieldInfo memberFieldInfo = fieldInfoList[columnCount];

                    string addString = "";

                    if (memberFieldInfo.FieldType.ToString() == "System.Int32")
                    {
                        addString = getString;
                    }
                    else if (memberFieldInfo.FieldType.ToString() == "System.Single")
                    {
                        addString = getString;
                    }
                    else if (memberFieldInfo.FieldType.ToString() == "System.String")
                    {
                        addString = "\"" + getString + "\"";
                    }
                    else if (memberFieldInfo.FieldType.ToString() == "System.Boolean")
                    {
                        if (getString == "true")
                        {
                            addString = "1";
                        }
                        else
                        {
                            addString = "0";
                        }
                    }
                    else
                    {
                        Debug.LogError("データ定義に異常があります!!!!!!!" + memberFieldInfo.FieldType);
                        //異常なデータは出力してはいけないので強制停止
                        break;
                    }

                    lineData.Add(addString);
                    columnCount++;
                }

                writer.WriteLine(lineData);
            }
        }
    }