diff --git a/GBase/GBase.cs b/GBase/GBase.cs index 0bf717e..e87c247 100644 --- a/GBase/GBase.cs +++ b/GBase/GBase.cs @@ -8,6 +8,7 @@ using System.Linq; using System.Reflection; using System.Threading; using System.Threading.Tasks; +using GBase.Api; using GBase.Attributes; using GBase.Factories; using GBase.Interfaces; @@ -100,6 +101,15 @@ namespace GBase return true; } + public IGBaseTable GetTable() where T : INotifyGBaseEntryChanged + { + if (Tables.OfType>().Any()) + return Tables.OfType>().First(); + + //TODO: This probably doesn't work, because even though t.Type : T, IGBaseTable !: IGBaseTable + return (IGBaseTable) Tables.FirstOrDefault(t => typeof(T).IsAssignableFrom(t.Type)); //TestMe + } + /// /// Removes a given from this /// @@ -113,6 +123,15 @@ namespace GBase return Tables.Remove(table); } + public bool AddEntry(T entry) where T : INotifyGBaseEntryChanged + { + IGBaseTable table = GetTable(); + if (table == null) + throw new Exception(); //TODO: Create exception + + return table.AddEntry(entry); + } + /// /// Dispose used resources asynchronously /// diff --git a/GBase/GBaseTable.cs b/GBase/GBaseTable.cs index 92fa996..5684bb1 100644 --- a/GBase/GBaseTable.cs +++ b/GBase/GBaseTable.cs @@ -21,7 +21,7 @@ namespace GBase /// /// A table /// - public class GBaseTable : IGBaseTable + public class GBaseTable : IGBaseTable where T : INotifyGBaseEntryChanged { private readonly IFileHandler _fileHandler; private readonly IGBaseColumnFactory _gBaseColumnFactory; @@ -35,7 +35,7 @@ namespace GBase _gBaseColumnFactory = gBaseColumnFactory; Columns = new List(); - Entries = new List(); + Entries = new List(); } @@ -57,7 +57,7 @@ namespace GBase /// /// The entries of this /// - public List Entries { get; } + public List Entries { get; } /// @@ -123,7 +123,7 @@ namespace GBase /// /// The entry implementing /// True if successful, false if not - public bool AddEntry(INotifyGBaseEntryChanged entry) //TODO: Write to file + public bool AddEntry(T entry) //TODO: Write to file { Entries.Add(entry); entry.GBaseEntryChanged += OnGBaseEntryChanged; @@ -136,7 +136,7 @@ namespace GBase /// /// The entry implementing /// True if successful, false if not - public bool RemoveEntry(INotifyGBaseEntryChanged entry) //TODO: remove from file + public bool RemoveEntry(T entry) //TODO: remove from file { if (!Entries.Contains(entry)) return false; @@ -188,7 +188,7 @@ namespace GBase Columns.Clear(); - foreach (var entry in Entries.OfType().ToList()) + foreach (var entry in Entries.ToList()) { RemoveEntry(entry); } diff --git a/GBase/Interfaces/IGBase.cs b/GBase/Interfaces/IGBase.cs index 614211a..955e242 100644 --- a/GBase/Interfaces/IGBase.cs +++ b/GBase/Interfaces/IGBase.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.Reflection; using System.Threading; using System.Threading.Tasks; +using GBase.Api; using GBase.Interfaces.Settings; namespace GBase.Interfaces @@ -48,11 +49,15 @@ namespace GBase.Interfaces /// True if successful, false if not bool AddTable(IGBaseTable table); + IGBaseTable GetTable() where T : INotifyGBaseEntryChanged; + /// /// Removes a given from this /// /// The given /// True if successful, false if not bool RemoveTable(IGBaseTable table); + + bool AddEntry(T entry) where T : INotifyGBaseEntryChanged; } } \ No newline at end of file diff --git a/GBase/Interfaces/IGBaseTable.cs b/GBase/Interfaces/IGBaseTable.cs index 613c0af..52673bc 100644 --- a/GBase/Interfaces/IGBaseTable.cs +++ b/GBase/Interfaces/IGBaseTable.cs @@ -10,6 +10,31 @@ using GBase.Api; namespace GBase.Interfaces { + public interface IGBaseTable : IGBaseTable where T : INotifyGBaseEntryChanged + { + /// + /// The entries of this + /// + List Entries { get; } + + /// + /// Add an entry that implements to this + /// + /// The entry implementing + /// True if successful, false if not + bool AddEntry(T entry); + + + //T GetEntry(T entry); //TODO: This doesn't make sense... (passing instance of T to get the same instance back...) + + /// + /// Remove an entry that implements from this + /// + /// The entry implementing + /// True if successful, false if not + bool RemoveEntry(T entry); + } + /// /// A table /// @@ -30,11 +55,6 @@ namespace GBase.Interfaces /// List Columns { get; } - /// - /// The entries of this - /// - List Entries { get; } - /// /// Initialize this /// @@ -58,19 +78,5 @@ namespace GBase.Interfaces /// The given /// True if successful, false if not bool RemoveColumn(IGBaseColumn column); - - /// - /// Add an entry that implements to this - /// - /// The entry implementing - /// True if successful, false if not - bool AddEntry(INotifyGBaseEntryChanged entry); - - /// - /// Remove an entry that implements from this - /// - /// The entry implementing - /// True if successful, false if not - bool RemoveEntry(INotifyGBaseEntryChanged entry); } } \ No newline at end of file