Skip to content

Instantly share code, notes, and snippets.

@pjmagee
Created May 2, 2014 17:11
Show Gist options
  • Select an option

  • Save pjmagee/9372c2017ac5e57b60ca to your computer and use it in GitHub Desktop.

Select an option

Save pjmagee/9372c2017ac5e57b60ca to your computer and use it in GitHub Desktop.
M# Framework Object.Get Bug.
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