Created
May 2, 2014 17:11
-
-
Save pjmagee/9372c2017ac5e57b60ca to your computer and use it in GitHub Desktop.
M# Framework Object.Get Bug.
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
| void Main() | |
| { | |
| default(Container).Dump("default(Container)"); | |
| (default(Container?)).Dump("default of (Container?)"); | |
| var owner = new Owner() { NullContainer = null }; | |
| var nullContainer = owner.Get(o => { o = null; return o.NullContainer; }); | |
| typeof(Container?).Dump("typeof Container?"); | |
| nullContainer.Dump("default(container?) with Get()"); | |
| } | |
| public class Owner | |
| { | |
| public Container? NullContainer { get; set; } | |
| public Container NonNullContainer { get; set; } | |
| } | |
| public struct Container | |
| { | |
| public string Message | |
| { | |
| get | |
| { | |
| if(this.message == null) { return "default message"; } | |
| else { return this.message; } | |
| } | |
| set | |
| { | |
| this.message = value; | |
| } | |
| } | |
| private string message; | |
| public Container(string message = "custom default message") : this() | |
| { | |
| if(message == null) throw new ArgumentNullException("message"); | |
| this.Message = message; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment