Language enhancements I'd like to see.
Awhile back I wrote about my Whidby hopes, dreams, and concerns. My friend Michael wrote me today with a wishlist of his own. I realize it's kind of late in the game for additional language features, but his ideas are good (in my opinion) so I'm going to post them anyway in the hope that maybe, just maybe someone at Microsoft might take note.
1. Different scope/access modifieres for the property getter and setter.
public int Property1
{
get
{
return m_iProperty1;
}
}
private int Property1
{
set
{
m_iProperty1 = value;
}
}
I've personally run into this one. I tend to run into this when I want to inherit from a class that has a readonly property, and I want to set the property in the base class without exposing the setter to the rest of the world. I end up having to write a SetPropertyName(value as object) procedure (sorry about the mixed C#/VB syntax) in the child class. FXCop doesn't like the SetPropertyName() method and recommends that I "use a property setter" instead. D'oh!
2. Add a new access modifier for data members that can only be accessed through property methods even from within the containing class.
Michael's C# example (given the above property sample):
secret int m_iProperty1;
private void AMethod()
{
m_iProperty1 = 2; // Compiler error
Property1 = 2; // Ok, no error
}
My VB .NET Example:
Public Property MyValue() As String
Private _Value as string = String.Empty 'Scope limited to getter and setter Get
return _Value End Get Set(ByVal Value As String)
me._Value = Value End Set End Property