Here is a new language feature that saves a lot of time and eliminates some mindless typing...
Tired of writing code like this?
public class SolutionDescriptor
{ private string _folder;
private string _solutionName;
private string _fileName;
private int _lineNo;
public String Folder
{ get { return _folder; } set { _folder = value; } }
public String SolutionName
{ get { return _solutionName; } set { _solutionName = value; } }
public String FileName
{ get { return _fileName; } set { _fileName = value; } }
public int LineNo
{ get { return _lineNo; } set { _lineNo = value; } }
}
Automatic properties to the rescue! Now you can write this instead...
public class SolutionDescriptor
{ public String Folder { get; set; } public String SolutionName { get; set; } public String FileName { get; set; } public int LineNo { get; set; }}
Note that this is NOT equivalent to making the members public... the compiler actually generates a private field - with a very funky name! If you use Lutz Roeder's Reflector you will see something like this:
The field is also flagged with a [CompilerGenerated] attribute, which can be used by tools:
This private field comes with the conventional setter/getter methods. This is a good thing, because if you further down the road decide that you want to actually implement a getter or setter, you can just add your member variable and flesh out the property interface, without breaking the contract with existing users of your code.
You can read more about this feature and other new language features on Scott Guthrie's blog.
Pretty neat, huh?