You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A simplified version of restricted state access with side effects (locking):
public delegate void ActionRef<T>(ref T r1);
public delegate RES FuncRef<T, RES>(ref T r1);
public class LockedState<T> {
T Value;
readonly object theLock = new object();
public void Ref(ActionRef<T> f) { lock(theLock) f(ref Value); }
public TRES Ref<TRES>(FuncRef<T, TRES> f) { lock(theLock) return f(ref Value); }
}
public static void Main() {
LockedState<SomeComplexType<DateTime, OtherComplexType<List<int>>>> State = new();
// this is what I have to do ATM:
State.Ref((ref SomeComplexType<DateTime, OtherComplexType<List<int>>> v) => { v = v.next(); });
// but I would like to do this:
State.Ref((ref var v) => { v = v.next(); }); // The contextual keyword 'var' may only appear within a local variable declaration or in script code
// or even better this:
State.Ref(ref var v => { v = v.next(); });
// or even better this:
State.Ref((ref v) => { v = v.next(); });
// or best this:
State.Ref(ref v => { v = v.next(); });
}
I propose for some of the shorter forms I show above to be allowed Thanks!
The text was updated successfully, but these errors were encountered:
A simplified version of restricted state access with side effects (locking):
I propose for some of the shorter forms I show above to be allowed Thanks!
The text was updated successfully, but these errors were encountered: