Created
March 9, 2016 14:23
-
-
Save NickCraver/99fe05107321d903890e to your computer and use it in GitHub Desktop.
Example of get-only overrides in C# 6 and fun side-effects.
This file contains 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() | |
{ | |
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