using System; using System.Collections.Generic; namespace Chernobyl.Threading { /// /// A DataAccessor for strings - used to access strings /// from a . /// public class StringAccessor : DataAccessor { /// /// Constructor. /// /// The to attach to. /// The rights granted to this accessor. public StringAccessor(DataSafe attachTo, AccessRights accessRights) : base(attachTo, accessRights) { _theString = String.Empty; } /// /// Returns the current value of the string. /// public string Read() { return _theString; } /// /// Changes the value of the string to the /// string passed in. Only call this method /// when you have to. Fewer calls to this /// method will help performance. /// /// The new value of the string. public void Write(string newValue) { _theString = newValue; MyDataSafe.RecordChange(this, (ref string oldString) => oldString = String.Copy(newValue)); } /// /// This method is called when the DataSafe is synchronized. /// The passed in changeRecords are to be run on the accessors /// data so that it can have it's data synchronized with the other /// accessors. /// /// The change records to run on the internal /// data. public override void Synchronize(Queue.ChangeRecord> changeRecords) { foreach(DataSafe.ChangeRecord cr in changeRecords) { cr(ref _theString); } } String _theString; } }