mirror of
https://git.ryujinx.app/ryubing/ryujinx.git
synced 2025-06-28 15:26:24 +02:00
Move solution and projects to src
This commit is contained in:
parent
cd124bda58
commit
cee7121058
3466 changed files with 55 additions and 55 deletions
61
src/Ryujinx.Common/ReactiveObject.cs
Normal file
61
src/Ryujinx.Common/ReactiveObject.cs
Normal file
|
@ -0,0 +1,61 @@
|
|||
using System;
|
||||
using System.Threading;
|
||||
|
||||
namespace Ryujinx.Common
|
||||
{
|
||||
public class ReactiveObject<T>
|
||||
{
|
||||
private ReaderWriterLock _readerWriterLock = new ReaderWriterLock();
|
||||
private bool _isInitialized = false;
|
||||
private T _value;
|
||||
|
||||
public event EventHandler<ReactiveEventArgs<T>> Event;
|
||||
|
||||
public T Value
|
||||
{
|
||||
get
|
||||
{
|
||||
_readerWriterLock.AcquireReaderLock(Timeout.Infinite);
|
||||
T value = _value;
|
||||
_readerWriterLock.ReleaseReaderLock();
|
||||
|
||||
return value;
|
||||
}
|
||||
set
|
||||
{
|
||||
_readerWriterLock.AcquireWriterLock(Timeout.Infinite);
|
||||
|
||||
T oldValue = _value;
|
||||
|
||||
bool oldIsInitialized = _isInitialized;
|
||||
|
||||
_isInitialized = true;
|
||||
_value = value;
|
||||
|
||||
_readerWriterLock.ReleaseWriterLock();
|
||||
|
||||
if (!oldIsInitialized || oldValue == null || !oldValue.Equals(_value))
|
||||
{
|
||||
Event?.Invoke(this, new ReactiveEventArgs<T>(oldValue, value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static implicit operator T(ReactiveObject<T> obj)
|
||||
{
|
||||
return obj.Value;
|
||||
}
|
||||
}
|
||||
|
||||
public class ReactiveEventArgs<T>
|
||||
{
|
||||
public T OldValue { get; }
|
||||
public T NewValue { get; }
|
||||
|
||||
public ReactiveEventArgs(T oldValue, T newValue)
|
||||
{
|
||||
OldValue = oldValue;
|
||||
NewValue = newValue;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue