Skip to content

Instantly share code, notes, and snippets.

@NickCraver
Created March 9, 2016 14:23
Show Gist options
  • Save NickCraver/99fe05107321d903890e to your computer and use it in GitHub Desktop.
Save NickCraver/99fe05107321d903890e to your computer and use it in GitHub Desktop.
Example of get-only overrides in C# 6 and fun side-effects.
void Main()
{
var child = new Child();
child.Prop = false;
child.Prop.Dump();
var propertyInfo = typeof(Child).GetProperty(nameof(Child.Prop));
propertyInfo.GetGetMethod().Dump();
propertyInfo.GetSetMethod().Dump();
}
public class Base
{
public virtual bool Prop { get; set; }
}
public class Child : Base
{
public override bool Prop => true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment