views:

76

answers:

1

If you look at the DataGridViewTextBoxCell property, ValueType, in reflector, you can see it overrides a property from DataGridViewCell.

The strange thing is, is that the overriden property is readonly, but the property in the parent class is read and write.

I can only presume that the property has been shadowed and reflector doesn't ...erm .. reflect this.

Is this right?

eta: I'm looking at the source, in reflector, as vb.net.

+1  A: 

The CLR implements properties internally as methods. There will be one method for each acessor. So if your property is read/write, you will have two methods. If your method is read-only or write-only, then you will have only one method.

You can see that for yourself using Reflector if you choose IL instead of Visual Basic.


.method public hidebysig specialname virtual instance class [mscorlib]System.Type get_ValueType() cil managed

If you comapre with the ToString method...


.method public hidebysig virtual instance string ToString() cil managed

... you will note that both start with ".method".

Since you have two methods, you can override them independently one from another.

Alfred Myers
I never realized it was possible to override only one of the accessors... that's good to know ! However, I find it rather confusing, because the overridden property seems to be read-only even though it's not...
Thomas Levesque
I'm still a bit confused. I understand that a property declaration is translated into 2 methods but, in vb.net at least, it's not possible to override a read and write property and just override the get - at least not without the shadows keyword.
Jules
Yeah.. You're right. Yesterday I tested it with C# and since it worked I assumed it would work on VB.NET too. Now I tried it on VB.NET but haven't found a way to make it work. The workaround would be to put a setter that accesses the base setter.
Alfred Myers