Change BanManager.Bans to a readonly dictionary

Entries to this dictionary should be added through `InsertBan` rather than directly to the dictionary
This commit is contained in:
Chris 2020-12-03 14:25:38 +10:30
parent 3b1502c28f
commit ae8ab04e8a

View file

@ -21,6 +21,7 @@ using System.Linq;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data; using System.Data;
using MySql.Data.MySqlClient; using MySql.Data.MySqlClient;
using System.Collections.ObjectModel;
namespace TShockAPI.DB namespace TShockAPI.DB
{ {
@ -34,9 +35,9 @@ namespace TShockAPI.DB
private Dictionary<int, Ban> _bans; private Dictionary<int, Ban> _bans;
/// <summary> /// <summary>
/// Dictionary of Bans, keyed on ban ticket number /// Readonly dictionary of Bans, keyed on ban ticket number.
/// </summary> /// </summary>
public Dictionary<int, Ban> Bans public ReadOnlyDictionary<int, Ban> Bans
{ {
get get
{ {
@ -45,7 +46,7 @@ namespace TShockAPI.DB
_bans = RetrieveAllBans().ToDictionary(b => b.TicketNumber); _bans = RetrieveAllBans().ToDictionary(b => b.TicketNumber);
} }
return _bans; return new ReadOnlyDictionary<int, Ban>(_bans);
} }
} }