I noticed when I reflect into an assembly, calls to property accessors sometimes look like methods
// "Reflected" example
class Class1 {
public bool Boolean { get; set;}
}
class Class2 {
public Class2() {
var class1 = new Class1();
var boolean = class1.get_Boolean();
}
}
Now I was curious, and I put a method with a similar signature in Class1 that looks like the standard convention for accessors.
// "Hacked" example
class Class1 {
public bool get_Boolean() { return true; }
}
Somehow, the C# compiler still treats get_Boolean as a method.
What’s the magic sauce to get a method to be a property?
If you look at the IL, you’ll find something like this:
So the ‘magic’ is a
.propertymember which glues two methods together.