Skip to content

Instantly share code, notes, and snippets.

@jcouv
Created March 9, 2016 02:58
Show Gist options
  • Save jcouv/03517507739c74165336 to your computer and use it in GitHub Desktop.
Save jcouv/03517507739c74165336 to your computer and use it in GitHub Desktop.
public void DynamicLocalCapturedByLambda()
{
var mslib = @"
namespace System
{
public class Object { }
public struct Int32 { }
public class ValueType { }
public class Attribute { }
public struct Void { }
public struct IntPtr { }
public class Type {
public static Type GetTypeFromHandle(RuntimeTypeHandle handle ) { return null; }
}
public struct RuntimeTypeHandle { }
public class String { }
public delegate void Action();
public class MulticastDelegate : Delegate { }
public class Delegate { }
}";
var source = @"
class C
{
void M()
{
dynamic local = 42;
System.Action lambda = () => {
dynamic i = local;
};
}
}
";
// Build an mscorlib including String
var mslibComp = CreateCompilation(new string[] { mslib }).VerifyDiagnostics();
var mslibRef = mslibComp.EmitToImageReference();
var comp = CreateCompilation(source, references: new[] { mslibRef, CSharpRef});
comp.VerifyDiagnostics();
CompileAndVerify(comp);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment