Add `RealmContextFactory.Write` helper method

This commit is contained in:
Dean Herbert 2022-01-21 17:08:02 +09:00
parent a59105635e
commit da0a803e6c
1 changed files with 18 additions and 0 deletions

View File

@ -204,6 +204,24 @@ public void Run(Action<Realm> action)
}
}
/// <summary>
/// Write changes to realm.
/// </summary>
/// <remarks>
/// Handles correct context management and transaction committing automatically.
/// </remarks>
/// <param name="action">The work to run.</param>
public void Write(Action<Realm> action)
{
if (ThreadSafety.IsUpdateThread)
Context.Write(action);
else
{
using (var realm = createContext())
realm.Write(action);
}
}
private Realm createContext()
{
if (isDisposed)