Skip to content

Commit a3375e7

Browse files
sputierBillWagner
authored andcommitted
Added sample code to read attributes for C# tour (#6488)
* Added sample code to read attributes for C# tour * Replaced snippet reference from line numbers to name
1 parent 89208b3 commit a3375e7

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

docs/csharp/tour-of-csharp/attributes.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ All attribute classes derive from the <xref:System.Attribute> base class provide
1919

2020
This example attaches a `HelpAttribute` to the `Widget` class. It adds another `HelpAttribute` to the `Display` method in the class. The public constructors of an attribute class control the information that must be provided when the attribute is attached to a program entity. Additional information can be provided by referencing public read-write properties of the attribute class (such as the reference to the `Topic` property previously).
2121

22-
When a particular attribute is requested through reflection, the constructor for the attribute class is invoked with the information provided in the program source, and the resulting attribute instance is returned. If additional information was provided through properties, those properties are set to the given values before the attribute instance is returned.
22+
The metadata defined by attributes can be read and manipulated at runtime using reflection. When a particular attribute is requested using this technique, the constructor for the attribute class is invoked with the information provided in the program source, and the resulting attribute instance is returned. If additional information was provided through properties, those properties are set to the given values before the attribute instance is returned.
23+
24+
The following code sample demonstrates how to get the `HelpAttribute` instances associated to the `Widget` class and its `Display` method.
25+
26+
[!code-csharp[AttributeRead](../../../samples/snippets/csharp/tour/attributes/Program.cs#ReadAttributes)]
2327

2428
>[!div class="step-by-step"]
2529
[Previous](delegates.md)

0 commit comments

Comments
 (0)