progress
This commit is contained in:
parent
16e76d6b31
commit
484dbfc9d9
529 changed files with 113694 additions and 0 deletions
53
AspClassic.Scripting/ScopeVariable.cs
Normal file
53
AspClassic.Scripting/ScopeVariable.cs
Normal file
|
@ -0,0 +1,53 @@
|
|||
using System;
|
||||
using System.Threading;
|
||||
|
||||
namespace AspClassic.Scripting;
|
||||
|
||||
public sealed class ScopeVariable : IScopeVariable, IWeakReferencable
|
||||
{
|
||||
private object _value;
|
||||
|
||||
private WeakReference _weakref;
|
||||
|
||||
private static readonly object _novalue = new object();
|
||||
|
||||
public bool HasValue => _value != _novalue;
|
||||
|
||||
public WeakReference WeakReference
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_weakref == null)
|
||||
{
|
||||
_weakref = new WeakReference(this);
|
||||
}
|
||||
return _weakref;
|
||||
}
|
||||
}
|
||||
|
||||
internal ScopeVariable()
|
||||
{
|
||||
_value = _novalue;
|
||||
}
|
||||
|
||||
public bool TryGetValue(out dynamic value)
|
||||
{
|
||||
value = _value;
|
||||
if ((object)value != _novalue)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
value = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
public void SetValue(object value)
|
||||
{
|
||||
_value = value;
|
||||
}
|
||||
|
||||
public bool DeleteValue()
|
||||
{
|
||||
return Interlocked.Exchange(ref _value, _novalue) != _novalue;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue