Created
February 3, 2017 15:41
-
-
Save controlflow/da02c598ccb965438129e7f81ed6b506 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
// ReSharper disable UnusedParameter.Local | |
// ReSharper disable UnusedVariable | |
// ReSharper disable FunctionRecursiveOnAllPaths | |
public class WriteTest | |
{ | |
public void RefArgument<T>(ref T t) { } | |
public void LocalVariable() | |
{ | |
var x = 42; | |
RefArgument(ref x); | |
x = 43; | |
x += 44; | |
x--; | |
++x; | |
var tr = __makeref(x); | |
ref var r = ref x; | |
} | |
public void RefLocalVariable() | |
{ | |
var t = 42; | |
ref var x = ref t; | |
RefArgument(ref x); | |
x = 43; | |
x += 44; | |
x--; | |
++x; | |
var tr = __makeref(x); | |
ref var r = ref x; | |
} | |
public void LocalConstant() | |
{ | |
const int local = 42; | |
RefArgument(ref local); | |
local = 43; | |
local += 44; | |
local--; | |
++local; | |
var tr = __makeref(local); | |
ref var r = ref local; | |
} | |
public void CatchVariable() | |
{ | |
try { } | |
catch (Bar local) | |
{ | |
RefArgument(ref local); | |
local = new Bar(); | |
local += 44; | |
local--; | |
++local; | |
var tr = __makeref(local); | |
ref var r = ref local; | |
} | |
} | |
public void ForeachVariable() | |
{ | |
foreach (var local in new int[0]) | |
{ | |
RefArgument(ref local); | |
local = 42; | |
local += 44; | |
local--; | |
++local; | |
var tr = __makeref(local); | |
ref var r = ref local; | |
} | |
} | |
public void UsingVariable() | |
{ | |
using (var local = new Bar()) | |
{ | |
RefArgument(ref local); | |
local = new Bar(); | |
local += 44; | |
local--; | |
++local; | |
var tr = __makeref(local); | |
ref var r = ref local; | |
} | |
} | |
public unsafe void FixedVariable(string s) | |
{ | |
fixed (char* local = s) | |
{ | |
RefArgument(ref local); | |
local = null; | |
local += 44; | |
local--; | |
++local; | |
var tr = __makeref(local); | |
ref var r = ref local; | |
} | |
} | |
public void PatternVariable(object o) | |
{ | |
var t = o is int local; | |
local = 43; | |
RefArgument(ref local); | |
local += 44; | |
local--; | |
++local; | |
var tr = __makeref(local); | |
ref var r = ref local; | |
} | |
public void DeclarationExpression(out int p) | |
{ | |
DeclarationExpression(out int local); | |
local = 43; | |
RefArgument(ref local); | |
local += 44; | |
local--; | |
++local; | |
var tr = __makeref(local); | |
ref var r = ref local; | |
p = 42; | |
} | |
public void Deconstruction() | |
{ | |
var (local, _) = (1, 2); | |
local = 43; | |
RefArgument(ref local); | |
local += 44; | |
local--; | |
++local; | |
var tr = __makeref(local); | |
ref var r = ref local; | |
} | |
public void DeconstructionInForeach() | |
{ | |
foreach (var (local, _) in new[] { (1, 2) }) | |
{ | |
local = 43; | |
RefArgument(ref local); | |
local += 44; | |
local--; | |
++local; | |
var tr = __makeref(local); | |
ref var r = ref local; | |
} | |
} | |
private class Bar : Exception, IDisposable | |
{ | |
public static Bar operator +(Bar me, int unused) => me; | |
public static Bar operator ++(Bar me) => me; | |
public static Bar operator --(Bar me) => me; | |
public void Dispose() { } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment