Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/standard/assembly/create-public-private-key-pair.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ms.date: "08/20/2019"
helpviewer_keywords:
- "key pairs for strong-named assemblies"
- "signing assemblies"
- "assemblies [.NET Framework], signing"
- "assemblies [.NET], signing"
- "cryptographic key pairs"
- "snk files (key pair files)"
- "public-private key pairs"
Expand Down
6 changes: 3 additions & 3 deletions docs/standard/assembly/create-use-strong-named.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ helpviewer_keywords:
- "strong-named assemblies, about strong-named assemblies"
- "strong-named assemblies"
- "signing assemblies"
- "assemblies [.NET Framework], signing"
- "assemblies [.NET], signing"
- "strong-named assemblies, scenarios"
- "assemblies [.NET Framework], strong-named"
- "assemblies [.NET], strong-named"
- "strong-named assemblies, loading into trusted application domains"
- "assembly binding, strong-named"
ms.assetid: ffbf6d9e-4a88-4a8a-9645-4ce0ee1ee5f9
Expand Down Expand Up @@ -40,7 +40,7 @@ The following scenario outlines the process of signing an assembly with a strong

3. Assembly B is a consumer of Assembly A. The reference section of Assembly B's manifest includes a token that represents Assembly A's public key. A token is a portion of the full public key and is used rather than the key itself to save space.

4. The common language runtime verifies the strong name signature when the assembly is placed in the global assembly cache. When binding by strong name at run time, the common language runtime compares the key stored in Assembly B's manifest with the key used to generate the strong name for Assembly A. If the .NET Framework security checks pass and the bind succeeds, Assembly B has a guarantee that Assembly A's bits have not been tampered with and that these bits actually come from the developers of Assembly A.
4. The common language runtime verifies the strong name signature when the assembly is placed in the global assembly cache. When binding by strong name at run time, the common language runtime compares the key stored in Assembly B's manifest with the key used to generate the strong name for Assembly A. If the .NET security checks pass and the bind succeeds, Assembly B has a guarantee that Assembly A's bits have not been tampered with and that these bits actually come from the developers of Assembly A.

> [!NOTE]
> This scenario doesn't address trust issues. Assemblies can carry full Microsoft Authenticode signatures in addition to a strong name. Authenticode signatures include a certificate that establishes trust. It's important to note that strong names don't require code to be signed in this way. Strong names only provide a unique identity.
Expand Down
4 changes: 2 additions & 2 deletions docs/standard/assembly/create.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ title: "Create assemblies"
description: Learn about creating single-file or multifile assemblies using an IDE, such as Visual Studio, or the compilers and tools provided by the Windows SDK.
ms.date: "08/19/2019"
helpviewer_keywords:
- "assemblies [.NET Framework], multifile"
- "assemblies [.NET], multifile"
- "single-file assemblies"
- "assemblies [.NET Framework], creating"
- "assemblies [.NET], creating"
- "multifile assemblies"
ms.assetid: 54832ee9-dca8-4c8b-913c-c0b9d265e9a4
---
Expand Down
4 changes: 2 additions & 2 deletions docs/standard/assembly/delay-sign.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ms.date: "08/19/2019"
helpviewer_keywords:
- "deferring assembly signing"
- "signing assemblies"
- "assemblies [.NET Framework], signing"
- "assemblies [.NET], signing"
- "strong-named assemblies, delaying assembly signing"
- "partial assembly signing"
ms.assetid: 9d300e17-5bf1-4360-97da-2aa55efd9070
Expand Down Expand Up @@ -57,7 +57,7 @@ To delay-sign an assembly:
sn –Vr myAssembly.dll
```

To turn off verification on platforms where you cant run the Strong Name tool, such as Advanced RISC Machine (ARM) microprocessors, use the **–Vk** option to create a registry file. Import the registry file into the registry on the computer where you want to turn off verification. The following example creates a registry file for `myAssembly.dll`.
To turn off verification on platforms where you can't run the Strong Name tool, such as Advanced RISC Machine (ARM) microprocessors, use the **–Vk** option to create a registry file. Import the registry file into the registry on the computer where you want to turn off verification. The following example creates a registry file for `myAssembly.dll`.

```console
sn –Vk myRegFile.reg myAssembly.dll
Expand Down
63 changes: 33 additions & 30 deletions docs/standard/attributes/applying-attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,51 @@
title: "Applying Attributes"
ms.date: "03/30/2017"
ms.technology: dotnet-standard
dev_langs:
dev_langs:
- "csharp"
- "vb"
- "cpp"
helpviewer_keywords:
helpviewer_keywords:
- "assemblies [.NET Framework], attributes"
- "attributes [.NET Framework], applying"
ms.assetid: dd7604eb-9fa3-4b60-b2dd-b47739fa3148
---
# Applying Attributes
Use the following process to apply an attribute to an element of your code.

1. Define a new attribute or use an existing attribute by importing its namespace from the .NET Framework.

2. Apply the attribute to the code element by placing it immediately before the element.

# Apply attributes

Use the following process to apply an attribute to an element of your code.

1. Define a new attribute or use an existing .NET attribute.

2. Apply the attribute to the code element by placing it immediately before the element.

Each language has its own attribute syntax. In C++ and C#, the attribute is surrounded by square brackets and separated from the element by white space, which can include a line break. In Visual Basic, the attribute is surrounded by angle brackets and must be on the same logical line; the line continuation character can be used if a line break is desired.

3. Specify positional parameters and named parameters for the attribute.

Positional parameters are required and must come before any named parameters; they correspond to the parameters of one of the attribute's constructors. Named parameters are optional and correspond to read/write properties of the attribute. In C++, and C#, specify `name`=`value` for each optional parameter, where `name` is the name of the property. In Visual Basic, specify `name`:=`value`.

The attribute is emitted into metadata when you compile your code and is available to the common language runtime and any custom tool or application through the runtime reflection services.

By convention, all attribute names end with Attribute. However, several languages that target the runtime, such as Visual Basic and C#, do not require you to specify the full name of an attribute. For example, if you want to initialize <xref:System.ObsoleteAttribute?displayProperty=nameWithType>, you only need to reference it as **Obsolete**.

## Applying an Attribute to a Method
The following code example shows how to declare **System.ObsoleteAttribute**, which marks code as obsolete. The string `"Will be removed in next version"` is passed to the attribute. This attribute causes a compiler warning that displays the passed string when code that the attribute describes is called.


3. Specify positional parameters and named parameters for the attribute.

*Positional* parameters are required and must come before any named parameters; they correspond to the parameters of one of the attribute's constructors. *Named* parameters are optional and correspond to read/write properties of the attribute. In C++, and C#, specify `name=value` for each optional parameter, where `name` is the name of the property. In Visual Basic, specify `name:=value`.

The attribute is emitted into metadata when you compile your code and is available to the common language runtime and any custom tool or application through the runtime reflection services.

By convention, all attribute names end with "Attribute". However, several languages that target the runtime, such as Visual Basic and C#, do not require you to specify the full name of an attribute. For example, if you want to initialize <xref:System.ObsoleteAttribute?displayProperty=nameWithType>, you only need to reference it as **Obsolete**.

## Apply an attribute to a method

The following code example shows how to use **System.ObsoleteAttribute**, which marks code as obsolete. The string `"Will be removed in next version"` is passed to the attribute. This attribute causes a compiler warning that displays the passed string when code that the attribute describes is called.

[!code-cpp[Conceptual.Attributes.Usage#3](../../../samples/snippets/cpp/VS_Snippets_CLR/conceptual.attributes.usage/cpp/source1.cpp#3)]
[!code-csharp[Conceptual.Attributes.Usage#3](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.attributes.usage/cs/source1.cs#3)]
[!code-vb[Conceptual.Attributes.Usage#3](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.attributes.usage/vb/source1.vb#3)]

## Applying Attributes at the Assembly Level
If you want to apply an attribute at the assembly level, use the **assembly** (`Assembly` in Visual Basic) keyword. The following code shows the **AssemblyTitleAttribute** applied at the assembly level.

[!code-vb[Conceptual.Attributes.Usage#3](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.attributes.usage/vb/source1.vb#3)]

## Apply attributes at the assembly level

If you want to apply an attribute at the assembly level, use the `assembly` (`Assembly` in Visual Basic) keyword. The following code shows the **AssemblyTitleAttribute** applied at the assembly level.

[!code-cpp[Conceptual.Attributes.Usage#2](../../../samples/snippets/cpp/VS_Snippets_CLR/conceptual.attributes.usage/cpp/source1.cpp#2)]
[!code-csharp[Conceptual.Attributes.Usage#2](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.attributes.usage/cs/source1.cs#2)]
[!code-vb[Conceptual.Attributes.Usage#2](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.attributes.usage/vb/source1.vb#2)]
When this attribute is applied, the string `"My Assembly"` is placed in the assembly manifest in the metadata portion of the file. You can view the attribute either by using the [MSIL Disassembler (Ildasm.exe)](../../framework/tools/ildasm-exe-il-disassembler.md) or by creating a custom program to retrieve the attribute.
[!code-vb[Conceptual.Attributes.Usage#2](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.attributes.usage/vb/source1.vb#2)]

When this attribute is applied, the string `"My Assembly"` is placed in the assembly manifest in the metadata portion of the file. You can view the attribute either by using the [MSIL Disassembler (Ildasm.exe)](../../framework/tools/ildasm-exe-il-disassembler.md) or by creating a custom program to retrieve the attribute.

## See also

- [Attributes](index.md)
Expand Down
44 changes: 23 additions & 21 deletions docs/standard/attributes/index.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
---
title: "Extending Metadata Using Attributes"
description: Learn how to extend metadata using attributes in .NET. Attributes are keyword-like descriptive declarations to annotate programming elements, like types and fields.
ms.date: "03/30/2017"
ms.date: 10/14/2020
ms.technology: dotnet-standard
helpviewer_keywords:
helpviewer_keywords:
- "metadata, extending"
- "attributes [.NET Framework], metadata"
- "elements [.NET Framework], attributes"
- "attributes [.NET], metadata"
- "elements [.NET], attributes"
- "common language runtime, attributes"
- "annotating programming elements"
- "keyword-like descriptive declarations"
- "runtime, attributes"
- "extending metadata"
ms.assetid: 30386922-1e00-4602-9ebf-526b271a8b87
---
# Extending Metadata Using Attributes
The common language runtime allows you to add keyword-like descriptive declarations, called attributes, to annotate programming elements such as types, fields, methods, and properties. When you compile your code for the runtime, it is converted into Microsoft intermediate language (MSIL) and placed inside a portable executable (PE) file along with metadata generated by the compiler. Attributes allow you to place extra descriptive information into metadata that can be extracted using runtime reflection services. The compiler creates attributes when you declare instances of special classes that derive from <xref:System.Attribute?displayProperty=nameWithType>.

The .NET Framework uses attributes for a variety of reasons and to address a number of issues. Attributes describe how to serialize data, specify characteristics that are used to enforce security, and limit optimizations by the just-in-time (JIT) compiler so the code remains easy to debug. Attributes can also record the name of a file or the author of code, or control the visibility of controls and members during forms development.

## Related Topics

|Title|Description|
|-----------|-----------------|
|[Applying Attributes](applying-attributes.md)|Describes how to apply an attribute to an element of your code.|
|[Writing Custom Attributes](writing-custom-attributes.md)|Describes how to design custom attribute classes.|
|[Retrieving Information Stored in Attributes](retrieving-information-stored-in-attributes.md)|Describes how to retrieve custom attributes for code that is loaded into the execution context.|
|[Metadata and Self-Describing Components](../metadata-and-self-describing-components.md)|Provides an overview of metadata and describes how it is implemented in a .NET Framework portable executable (PE) file.|
|[How to: Load Assemblies into the Reflection-Only Context](../../framework/reflection-and-codedom/how-to-load-assemblies-into-the-reflection-only-context.md)|Explains how to retrieve custom attribute information in the reflection-only context.|

## Reference
<xref:System.Attribute?displayProperty=nameWithType>
# Extend metadata using attributes

The common language runtime allows you to add keyword-like descriptive declarations, called attributes, to annotate programming elements such as types, fields, methods, and properties. When you compile your code for the runtime, it is converted into Microsoft intermediate language (MSIL) and placed inside a portable executable (PE) file along with metadata generated by the compiler. Attributes allow you to place extra descriptive information into metadata that can be extracted using runtime reflection services. The compiler creates attributes when you declare instances of special classes that derive from <xref:System.Attribute?displayProperty=nameWithType>.

.NET uses attributes for a variety of reasons and to address a number of issues. Attributes describe how to serialize data, specify characteristics that are used to enforce security, and limit optimizations by the just-in-time (JIT) compiler so the code remains easy to debug. Attributes can also record the name of a file or the author of code, or control the visibility of controls and members during forms development.

## Related articles

|Title|Description|
|-----------|-----------------|
|[Applying Attributes](applying-attributes.md)|Describes how to apply an attribute to an element of your code.|
|[Writing Custom Attributes](writing-custom-attributes.md)|Describes how to design custom attribute classes.|
|[Retrieving Information Stored in Attributes](retrieving-information-stored-in-attributes.md)|Describes how to retrieve custom attributes for code that is loaded into the execution context.|
|[Metadata and Self-Describing Components](../metadata-and-self-describing-components.md)|Provides an overview of metadata and describes how it is implemented in a .NET Framework portable executable (PE) file.|
|[How to: Load Assemblies into the Reflection-Only Context](../../framework/reflection-and-codedom/how-to-load-assemblies-into-the-reflection-only-context.md)|Explains how to retrieve custom attribute information in the reflection-only context.|

## Reference

- <xref:System.Attribute?displayProperty=nameWithType>
6 changes: 3 additions & 3 deletions docs/standard/base-types/best-practices.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ dev_langs:
- "csharp"
- "vb"
helpviewer_keywords:
- ".NET Framework regular expressions, best practices"
- ".NET regular expressions, best practices"
- "regular expressions, best practices"
ms.assetid: 618e5afb-3a97-440d-831a-70e4c526a51c
---
Expand Down Expand Up @@ -55,7 +55,7 @@ To solve this problem, you can do the following:

## Handle object instantiation appropriately

At the heart of .NETs regular expression object model is the <xref:System.Text.RegularExpressions.Regex?displayProperty=nameWithType> class, which represents the regular expression engine. Often, the single greatest factor that affects regular expression performance is the way in which the <xref:System.Text.RegularExpressions.Regex> engine is used. Defining a regular expression involves tightly coupling the regular expression engine with a regular expression pattern. That coupling process, whether it involves instantiating a <xref:System.Text.RegularExpressions.Regex> object by passing its constructor a regular expression pattern or calling a static method by passing it the regular expression pattern along with the string to be analyzed, is by necessity an expensive one.
At the heart of .NET's regular expression object model is the <xref:System.Text.RegularExpressions.Regex?displayProperty=nameWithType> class, which represents the regular expression engine. Often, the single greatest factor that affects regular expression performance is the way in which the <xref:System.Text.RegularExpressions.Regex> engine is used. Defining a regular expression involves tightly coupling the regular expression engine with a regular expression pattern. That coupling process, whether it involves instantiating a <xref:System.Text.RegularExpressions.Regex> object by passing its constructor a regular expression pattern or calling a static method by passing it the regular expression pattern along with the string to be analyzed, is by necessity an expensive one.

> [!NOTE]
> For a more detailed discussion of the performance implications of using interpreted and compiled regular expressions, see [Optimizing Regular Expression Performance, Part II: Taking Charge of Backtracking](/archive/blogs/bclteam/optimizing-regular-expression-performance-part-ii-taking-charge-of-backtracking-ron-petrusha) in the BCL Team blog.
Expand Down Expand Up @@ -130,7 +130,7 @@ The regular expression pattern used in the example, `\b(\w+((\r?\n)|,?\s))*\w+[.

### Regular expressions: Compiled to an assembly

.NET also enables you to create an assembly that contains compiled regular expressions. This moves the performance hit of regular expression compilation from run time to design time. However, it also involves some additional work: You must define the regular expressions in advance and compile them to an assembly. The compiler can then reference this assembly when compiling source code that uses the assemblys regular expressions. Each compiled regular expression in the assembly is represented by a class that derives from <xref:System.Text.RegularExpressions.Regex>.
.NET also enables you to create an assembly that contains compiled regular expressions. This moves the performance hit of regular expression compilation from run time to design time. However, it also involves some additional work: You must define the regular expressions in advance and compile them to an assembly. The compiler can then reference this assembly when compiling source code that uses the assembly's regular expressions. Each compiled regular expression in the assembly is represented by a class that derives from <xref:System.Text.RegularExpressions.Regex>.

To compile regular expressions to an assembly, you call the <xref:System.Text.RegularExpressions.Regex.CompileToAssembly%28System.Text.RegularExpressions.RegexCompilationInfo%5B%5D%2CSystem.Reflection.AssemblyName%29?displayProperty=nameWithType> method and pass it an array of <xref:System.Text.RegularExpressions.RegexCompilationInfo> objects that represent the regular expressions to be compiled, and an <xref:System.Reflection.AssemblyName> object that contains information about the assembly to be created.

Expand Down
Loading