Skip to content

Instantly share code, notes, and snippets.

@yzorg
Last active August 29, 2015 13:56
Show Gist options
  • Save yzorg/8873971 to your computer and use it in GitHub Desktop.
Save yzorg/8873971 to your computer and use it in GitHub Desktop.
using System.Text;
namespace Yzorg.Gist {
class NoteBuilder : IDisposable {
StringBuilder _note;
Func<string> _get;
Action<string> _set;
public NoteBuilder(Func<string> get, Action<string> set) {
_get = get;
_set = set;
}
public StringBuilder Note {
get {
if (_note == null) {
_note = new StringBuilder(_get());
if (_note.Length > 0)
_note.AppendLine();
}
return _note;
}
}
public void Dispose() {
if (_note != null && _note.Length >= 2) {
if (_note[_note.Length-1] == '\n')
_note.Length -= 2; // remove trailing \r\n
_set(_note.ToString());
_note = null;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment