diff --git a/GBase/GBase.xml b/GBase/GBase.xml index 5d8fdaa..2945813 100644 --- a/GBase/GBase.xml +++ b/GBase/GBase.xml @@ -605,6 +605,29 @@ The given True if successful, false if not + + + Add an entry that implements to this + + The entry implementing + True if successful, false if not + + + + Remove an entry that implements from this + + The entry implementing + True if successful, false if not + + + + Modify the property of a given entry with the given value + + The entry + The name of the property + The new value to set + True if successful, false if not + A entry changed @@ -1011,6 +1034,20 @@ The given True if successful, false if not + + + Add an entry that implements to this + + The entry implementing + True if successful, false if not + + + + Remove an entry that implements from this + + The entry implementing + True if successful, false if not + Settings of a instance diff --git a/GBase/GBaseTable.cs b/GBase/GBaseTable.cs index 6e227fc..887f8d8 100644 --- a/GBase/GBaseTable.cs +++ b/GBase/GBaseTable.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Reflection; using System.Threading; using System.Threading.Tasks; @@ -35,8 +36,6 @@ namespace GBase Columns = new List(); Entries = new List(); - - INotifyGBaseEntryChanged.GBaseEntryChanged += OnGBaseEntryChanged; } @@ -119,30 +118,47 @@ namespace GBase return Columns.Remove(column); } - private bool AddEntry(object entry) //TODO: Write to file + /// + /// Add an entry that implements to this + /// + /// The entry implementing + /// True if successful, false if not + public bool AddEntry(INotifyGBaseEntryChanged entry) //TODO: Write to file { Entries.Add(entry); - return true; - } + entry.GBaseEntryChanged += OnGBaseEntryChanged; - private bool ModifyEntry(object entry, string propertyName, object value) //TODO: Write to file - { - PropertyInfo property = entry.GetType().GetProperty(propertyName); - if (property == null) - return false; - - property.SetValue(entry, value); return true; } - private bool RemoveEntry(object entry) //TODO: remove from file + /// + /// Remove an entry that implements from this + /// + /// The entry implementing + /// True if successful, false if not + public bool RemoveEntry(INotifyGBaseEntryChanged entry) //TODO: remove from file { if (!Entries.Contains(entry)) return false; + entry.GBaseEntryChanged -= OnGBaseEntryChanged; + return Entries.Remove(entry); } + /// + /// Modify the property of a given entry with the given value + /// + /// The entry + /// The name of the property + /// The new value to set + /// True if successful, false if not + private bool ModifyEntry(object entry, string propertyName, object value) //TODO: Write to file + { + //don't need to change value of property in `Entries` list, the instance is saved there, any property change is already changed there as well + return true; + } + /// /// A entry changed /// @@ -151,13 +167,7 @@ namespace GBase private void OnGBaseEntryChanged(object entry, GBaseEntryChangedEventArgs args) { //TODO: Might change, depending on #23 - bool success; - if (args == null) - success = RemoveEntry(entry); - else if (!Entries.Contains(entry)) - success = AddEntry(entry); - else - success = ModifyEntry(entry, args.ColumnName, args.Value); + bool success = ModifyEntry(entry, args.ColumnName, args.Value); if (!success) throw new Exception("Failed to handle EntryChanged"); //TODO: Decide what to do here @@ -177,6 +187,13 @@ namespace GBase } Columns.Clear(); + + foreach (var entry in Entries.OfType().ToList()) + { + RemoveEntry(entry); + } + + Entries.Clear(); } } } \ No newline at end of file diff --git a/GBase/Interfaces/IGBaseTable.cs b/GBase/Interfaces/IGBaseTable.cs index 4b6e697..613c0af 100644 --- a/GBase/Interfaces/IGBaseTable.cs +++ b/GBase/Interfaces/IGBaseTable.cs @@ -6,6 +6,7 @@ using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; +using GBase.Api; namespace GBase.Interfaces { @@ -58,5 +59,18 @@ namespace GBase.Interfaces /// 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