The Property Builder
Applies to: Visual Studio .NET 2002, Visual Studio .NET 2003, Visual Studio 2005, Visual Studio 2008
The Property Builder can be used to insert new properties.
To create a new property in Visual Basic:
-
Open a Visual Basic code module and click inside the
class or module where you want the property to be inserted.
-
Click Add New Property on the Code Edit
Tools toolbar or select the same entry in the Code Builder Tools popup menu,
Simple Code Builders secondary popup, to display the Add New
Property dialog-box (quick toolbar
and menu references
are available).
-
Type the new property name in the corresponding text box.
-
Select an existing property type from the Return type combobox
or enter a new type name if appropriate.
-
If the property will have a well defined initial value this one should be entered in the Default value textbox.
-
Select the new property kind: Get
(read-only), Set (write-only) or both Get
& Set (read/write).
-
Set the property scope. If you want to use
the implicit public scope select Do not specify.
-
CodeSMART automatically suggests a local
variable name (built according to the current
naming
standard settings) to hold the property value.
-
Set the appropriate modifiers for the new property.
Invalid modifiers are automatically disabled.
-
Optional. Specify if this should be marked as the default property.
-
Generate XML comments: check this option if you want for XML descriptive comments to be generated.
-
You can keep the member variable together with the body and enclose everything between #Region and #End Region directives by checking the corresponding option.
- Press the Standards button in order to review the naming standards configuration (this will be considered when generating code).
- Click Insert/New if you want to generate and insert the new property and continue with another one. Use Insert to simply close the dialog after
the new property is generated and inserted in code.
In Visual C# you can create both regular properties and indexers. Indexers permit instances of a class
or structure to be indexed in the same way as arrays do. Indexers
are similar to properties except their accessor take
parameters. Here are the main differences between properties
and indexers in C#.
|
Property
|
Indexer
|
|
Identified by its name.
|
Identified by its signature.
|
|
Accessed through a simple name or a member access.
|
Accessed through an element access.
|
|
Can be a static or an instance member.
|
Must be an instance member.
|
|
A get accessor of a property has no parameters.
|
A get accessor of an indexer has the same
formal parameter list as the indexer.
|
|
A set accessor of a property contains the
implicit value parameter.
|
A set accessor of an indexer has the same
formal parameter list as the indexer, in addition
to the value parameter.
|
To create a (regular) new property in C#:
-
Open the C# code module and click inside the class
where you want the property to be inserted.
-
Click Add New Property on the Code Edit
Tools toolbar or select the same entry in the Code Builder Tools popup menu,
Simple Code Builders secondary popup, to display the Add New
Property dialog-box (quick toolbar
and menu references
are available).
-
Select Property in the Type combobox.
-
Type the new property name in the corresponding text box.
-
Select an existing type from the Return type combo box
or enter a new type name if appropriate.
- If the property will have a well defined initial value this one should be entered in the Default value textbox.
-
Select the new property kind: get
(read-only), set (write-only) or both get
& set (read/write).
-
Set the property scope. If you want to use
the implicit public scope select Do not specify.
-
Set the appropriate modifiers for the new property.
Invalid modifiers are automatically disabled.
-
CodeSMART automatically suggests a local
variable name (built according to the current
naming
standard settings) to hold the property value.
-
Generate XML comments: check this option if you want for XML descriptive comments to be generated.
-
You can keep the member variable together with the body and enclose everything between #region and #endregion directives by checking the corresponding option.
-
Format property accessors each on a single line: check this option if you want to keep property accessors on single lines.
-
Click Insert and New if you want to generate and insert the new property and continue with another one. Use Insert to simply close the dialog after
the property is generated and inserted in code.
To create an indexer in C#:
-
Open the C# code module and click inside the class
where you want to insert the indexer.
-
Click Add New Property on the Code Edit
Tools toolbar or select the same entry in the
Simple Code Builders menu to display the New
Property dialog-box (quick toolbar
and menu references
are available).
-
Select Indexer in the Type combobox.
-
Select an existing type from the Return type combo box
or enter a new type name if none of the already saved ones is appropriate.
-
Select the new indexer kind: Get
(read-only), Set (write-only) or both Get
& Set (read/write).
-
Set the indexer scope. If you want to use
the implicit public scope select Do not specify.
-
Set the appropriate modifier for the new indexer.
Invalid modifiers are automatically disabled.
-
CodeSMART automatically suggests a local
variable name (built according to the current
naming
standard settings) to hold the property value.
-
Argument list: you can specify here a list of arguments for the indexer.
-
Generate XML comments: check this option if you want for XML descriptive comments to be generated.
-
You can keep the member variable together with the body and enclose everything between #region and #endregion directives by checking the corresponding option.
-
Format property accessors each on a single line: check this option if you want to keep the property accessors on single lines.
-
Click Insert and New if you want to generate
and insert the indexer template and continue with
another item (a regular property). Use Insert to close the dialog after
the indexer template is created.
Note
-
New properties can also be created by using the Add
New Property entry from the CodeSMART Code Explorer
context menu. This entry is available for module
(Visual Basic) and class type nodes only.
See Also
Back to top
|