Files
DbTools/Model/TableCollection.cs

71 lines
1.8 KiB
C#

using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DbTools.Model {
internal class TableCollection {
internal Dictionary<string, Table> Items { get; private set; } = new Dictionary<string, Table>();
public TableCollection() {
Items = new Dictionary<string, Table>();
}
public Table this[string tableName] {
get {
if (Items.ContainsKey(tableName)) {
return Items[tableName];
}
return null;
}
set {
if (Items.ContainsKey(tableName)) {
Items[tableName] = value;
} else {
Items.Add(tableName, value);
}
}
}
public void Add(string tableName, string tableDefinition) {
Table table = new Table(tableDefinition) {
TableName = tableName
};
Add(table);
}
public void Add(Table table) {
if (!Items.ContainsKey(table.TableName)) {
Items.Add(table.TableName, table);
}
}
public bool Contains(string tableName) {
return Items.ContainsKey(tableName);
}
public string[] GetTableNames() {
return Items.Keys.ToArray();
}
public Table[] GetTables() {
return Items.Values.ToArray();
}
public int Count() {
return Items.Count;
}
public void Clear() {
Items.Clear();
}
public override string ToString() {
StringBuilder sb = new StringBuilder();
foreach (var kvp in Items) {
sb.AppendLine($"{kvp.Key}: {kvp.Value}");
}
return sb.ToString();
}
}
}