Chapter 3. Visual Studio Code Snippets
When you develop applications, you spend a huge amount of time typing source code. Even if there are many designers and wizards in Visual Studio generating code skeletons, resource information, and many code related files, at the end of the day, each developer writes code. Sometimes, typing is very tedious. For example, let's assume you have the Name
property defined with the following pattern in C#:
private string _Name; public string Name { get { return _Name; } set { _Name = value; PropertyChanged("Name", value); } }
It almost could be written with the automatic property syntax of C# (this syntax was introduced in C# 3.0), but, unfortunately, you have a PropertyChanged
call in the property setter requiring a backing field and manually created getter-setter definitions. If you have other properties such as Title, Description, Active
, and so on, following the same pattern as Name, you must type the previous pattern in addition to a lot of replacing for the occurrences of Name
and _Name
with the appropriate identifiers.
The work of Visual Basic programmers becomes even dustier, because they must type a bit more, as shown here:
Private _Name As String Public Property Name() As String Get Return _Name End Get
Set(ByVal value As String) _Name = value PropertyChanged("Name", value) End Set End Property
What if you could create a lot of properties with these semantics by only typing their names? Well, you can if you use code snippets!
Early versions of ...
Get Visual Studio® 2010 and .NET 4, Six-in-one now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.