/// <summary> /// Generates the properties string of the script. /// </summary> /// <param name="rowInfos">The list of <see cref="DataTableRowInfo"/>.</param> /// <returns>The properties string of the script.</returns> private static string GenerateScriptPropertiesString(List <DataTableRowInfo> rowInfos) { string propertiesString = string.Empty; if (rowInfos != null && rowInfos.Count > 0) { for (int i = 0, length = rowInfos.Count; i < length; ++i) { DataTableRowInfo rowInfo = rowInfos[i]; propertiesString += string.Format("\t\t/// <summary>{0}\t\t/// {1}{2}\t\t/// </summary>{3}\t\tpublic {4} {5}{6}\t\t{{{7}\t\t\tget;{8}\t\t\tset;{9}\t\t}}", Environment.NewLine, rowInfo.Comments, Environment.NewLine, Environment.NewLine, rowInfo.Type, rowInfo.PropertyName, Environment.NewLine, Environment.NewLine, Environment.NewLine, Environment.NewLine); if (i < length - 1) { propertiesString += Environment.NewLine + Environment.NewLine; } } } return(propertiesString); }
/// <summary> /// Generates the data table row collection. /// </summary> /// <param name="table">The data table.</param> /// <param name="className">Name of the class.</param> /// <param name="rowInfos">The list of DataTableRow.</param> /// <returns>The data collection of data table row.</returns> private static List <DataTableRow> GenerateDataTableRowCollection(DataTable table, string namespaceString, string className, List <DataTableRowInfo> rowInfos) { List <DataTableRow> dataCollection = new List <DataTableRow>(); string classFullName = className; if (!string.IsNullOrEmpty(namespaceString)) { classFullName = string.Format("{0}.{1}", namespaceString, classFullName); } DataTablePreferences preferencesData = DataTablePreferencesWindow.LoadPreferencesData(); if (preferencesData) { int rowCount = table.Rows.Count; for (int i = preferencesData.DataRowsStartRow - 1; i < rowCount; ++i) { DataTableRow rowData = (DataTableRow)UnityReflectionUtil.CreateInstance(classFullName); for (int j = 0, propertiesCount = rowInfos.Count; j < propertiesCount; ++j) { string cellValue = table.Rows[i][j].ToString().Trim(); if (!string.IsNullOrEmpty(cellValue)) { DataTableRowInfo rowInfo = rowInfos[j]; ITypeParser typeParser = GetTypeParser(rowInfo.Type); if (typeParser != null) { object value = typeParser.Parse(cellValue); ReflectionUtil.SetObjectPropertyValue(rowData, rowInfo.PropertyName, value); } else { Debug.LogWarningFormat("Type '{0}' is not supported!", rowInfo.Type); } } } dataCollection.Add(rowData); } } return(dataCollection); }
/// <summary> /// Generates the list of DataTableRowInfo. /// </summary> /// <param name="dataTable">The data table.</param> /// <returns>The list of DataTableRowInfo.</returns> private static List <DataTableRowInfo> GenerateDataTableRowInfos(DataTable dataTable) { DataColumnCollection columns = dataTable.Columns; DataRowCollection rows = dataTable.Rows; int columnCount = columns.Count; List <DataTableRowInfo> infos = new List <DataTableRowInfo>(); for (int i = 0; i < columnCount; i++) { string propertyName = rows[0][i].ToString().Trim(); string type = rows[1][i].ToString().Trim(); string comments = rows[2][i].ToString().Trim(); if (!string.IsNullOrEmpty(propertyName) && !string.IsNullOrEmpty(type)) { DataTableRowInfo info = new DataTableRowInfo(propertyName, type, FormatCommentsString(comments)); infos.Add(info); } } return(infos); }