Last active
December 16, 2015 22:39
-
-
Save andreabalducci/5508218 to your computer and use it in GitHub Desktop.
strange behavior in vs2012 + r#
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
| [TestFixture] | |
| public class DynamicTest | |
| { | |
| public class Dto | |
| { | |
| public string Value { get; set; } | |
| } | |
| public Dto ToDto(dynamic d) | |
| { | |
| return new Dto(); | |
| } | |
| [Test] | |
| public void dto_is_typed() | |
| { | |
| // var is Dto | |
| var dto = ToDto(new { dummy = true }); | |
| dto.Value = "val"; | |
| Assert.Inconclusive("yust for intellisense test"); | |
| } | |
| [Test] | |
| public void dto_is_dynamic_inside_an_action_with_dynamic_type() | |
| { | |
| Action<dynamic> act = o => | |
| { | |
| // dto is dynamic | |
| var dto = ToDto(o); | |
| dto.ThisIsNotAProperty = 100; | |
| }; | |
| var ex = Assert.Throws<Microsoft.CSharp.RuntimeBinder.RuntimeBinderException>(() => | |
| { | |
| act(new {dummy = true}); | |
| }); | |
| Assert.IsTrue(ex.Message.EndsWith("does not contain a definition for 'ThisIsNotAProperty'")); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment