mirror of
https://github.com/osukey/osukey.git
synced 2025-05-02 12:17:27 +09:00
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.
38 lines
887 B
C#
38 lines
887 B
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
|
|
{
|
|
public class EntityFrameworkLive<T> : ILive<T> where T : class
|
|
{
|
|
public EntityFrameworkLive(T item)
|
|
{
|
|
IsManaged = true; // no way to really know.
|
|
Value = item;
|
|
}
|
|
|
|
public Guid ID => throw new InvalidOperationException();
|
|
|
|
public void PerformRead(Action<T> perform)
|
|
{
|
|
perform(Value);
|
|
}
|
|
|
|
public TReturn PerformRead<TReturn>(Func<T, TReturn> perform)
|
|
{
|
|
return perform(Value);
|
|
}
|
|
|
|
public void PerformWrite(Action<T> perform)
|
|
{
|
|
perform(Value);
|
|
}
|
|
|
|
public bool IsManaged { get; }
|
|
|
|
public T Value { get; }
|
|
}
|
|
}
|