NonCopyableAnalyzer
NonCopyableAnalyzer copied to clipboard
move semantics
interface INonCopyable { }
interface IMovable : INonCopyable
{
// void OnMoved(); ?
}
static class MoveExtensions
{
public static T Move<T>(ref this T x)
where T : struct, IMovable
{
// needs interlocked exchange?
var t = x;
// x.OnMoved(); ?
x = default;
return t;
}
}
- allow
var y = x.Move(); - disallow to use
xafterMove
This is not so hard for local variables and parameters but fields.