public static void GenViewModelCode(IEnumerable <TableSetting> tables, string outputPath) { var results = new Dictionary <string, StringBuilder>(); foreach (var table in tables) { results.Add(table.TableName, new StringBuilder()); } foreach (var line in System.IO.File.ReadLines(System.IO.Path.Combine(outputPath, ViewModelTemplateFileName))) { foreach (var table in tables) { var result = results[table.TableName]; var trimmedEnd = line.TrimEnd(); var trimmed = trimmedEnd.TrimStart(); var baseTab = trimmedEnd.Substring(0, trimmedEnd.Length - trimmed.Length); if (trimmed == "<DeclareHeaderFilters>") { result.Append(DeclareHeaderFilters(table.ColumnSettings, baseTab)); } else if (trimmed == "<DeclareNavigationDictionaries>") { result.Append(DeclareNavigationDictionaries(table.ColumnSettings, baseTab)); } else if (trimmed == "<InitHeaderFilters>") { result.Append(InitHeaderFilters(table.ColumnSettings, table.TableName, baseTab)); } else if (trimmed == "<AddHeaderFiltersToHeaderFilterCollection>") { result.Append(AddHeaderFiltersToHeaderFilterCollection(table.ColumnSettings, baseTab)); } else if (trimmed == "<AfterLoad>") { result.Append(AfterLoad(table.ColumnSettings, baseTab)); } else if (trimmed == "<LoadReferenceDatas>") { result.Append(LoadReferenceDatas(table.ColumnSettings, baseTab)); } else if (trimmed == "<SetDataModelsReferenceDataSource>") { result.Append(SetDataModelsReferenceDataSource(table.ColumnSettings, baseTab)); } else if (trimmed == "<SetDataModelsDefaultValue>") { result.Append(SetDataModelsDefaultValue(table.ColumnSettings, baseTab)); } else { result.AppendLineEx(line.Replace("<EntityName>", table.TableName)); } } } FileUtils.DeleteAllFileEndWith(outputPath, ViewModelFileNameSubFix); foreach (var result in results) { FileUtils.WriteAllTextInUTF8(System.IO.Path.Combine(outputPath, result.Key + ViewModelFileNameSubFix), result.Value.ToString()); } }