Add project files.
This commit is contained in:
70
Model/TableCollection.cs
Normal file
70
Model/TableCollection.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user