mirror of
https://github.com/ppy/osu
synced 2025-01-17 11:30:52 +00:00
40d1b97af1
For compatibility reasons, we quite often convert completely unmanaged instances to `ILive`s so they fit the required parameters of a property or method call. This ensures such cases will not cause any issues when trying to interact with the underlying data. Originally I had this allowing write operations, but that seems a bit unsafe (when performing a write one would assume that the underlying data is being persisted, whereas in this case it is not). We can change this if the requirements change in the future, but I think throwing is the safest bet for now.
48 lines
1.6 KiB
C#
48 lines
1.6 KiB
C#
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
using System;
|
|
|
|
namespace osu.Game.Database
|
|
{
|
|
/// <summary>
|
|
/// A wrapper to provide access to database backed classes in a thread-safe manner.
|
|
/// </summary>
|
|
/// <typeparam name="T">The databased type.</typeparam>
|
|
public interface ILive<out T> where T : class // TODO: Add IHasGuidPrimaryKey once we don't need EF support any more.
|
|
{
|
|
Guid ID { get; }
|
|
|
|
/// <summary>
|
|
/// Perform a read operation on this live object.
|
|
/// </summary>
|
|
/// <param name="perform">The action to perform.</param>
|
|
void PerformRead(Action<T> perform);
|
|
|
|
/// <summary>
|
|
/// Perform a read operation on this live object.
|
|
/// </summary>
|
|
/// <param name="perform">The action to perform.</param>
|
|
TReturn PerformRead<TReturn>(Func<T, TReturn> perform);
|
|
|
|
/// <summary>
|
|
/// Perform a write operation on this live object.
|
|
/// </summary>
|
|
/// <param name="perform">The action to perform.</param>
|
|
void PerformWrite(Action<T> perform);
|
|
|
|
/// <summary>
|
|
/// Whether this instance is tracking data which is managed by the database backing.
|
|
/// </summary>
|
|
bool IsManaged { get; }
|
|
|
|
/// <summary>
|
|
/// Resolve the value of this instance on the current thread's context.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// After resolving the data should not be passed between threads.
|
|
/// </remarks>
|
|
T Value { get; }
|
|
}
|
|
}
|