From 0b9776fae127bec71135b94615079f7204f94790 Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Wed, 19 Jan 2022 14:19:38 +0200 Subject: [PATCH 01/18] Add to toc --- docs/fundamentals/toc.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/docs/fundamentals/toc.yml b/docs/fundamentals/toc.yml index dff2ed171a20c..1ad83751315ef 100644 --- a/docs/fundamentals/toc.yml +++ b/docs/fundamentals/toc.yml @@ -893,6 +893,8 @@ items: href: code-analysis/quality-rules/ca1417.md - name: CA1418 href: code-analysis/quality-rules/ca1418.md + - name: CA1419 + href: code-analysis/quality-rules/ca1419.md - name: Maintainability rules items: - name: Overview @@ -947,6 +949,8 @@ items: href: code-analysis/quality-rules/ca1724.md - name: CA1725 href: code-analysis/quality-rules/ca1725.md + - name: CA1727 + href: code-analysis/quality-rules/ca1727.md - name: Performance rules items: - name: Overview @@ -1014,6 +1018,10 @@ items: href: code-analysis/quality-rules/ca1840.md - name: CA1841 href: code-analysis/quality-rules/ca1841.md + - name: CA1842 + href: code-analysis/quality-rules/ca1842.md + - name: CA1843 + href: code-analysis/quality-rules/ca1843.md - name: CA1844 href: code-analysis/quality-rules/ca1844.md - name: CA1845 @@ -1022,6 +1030,8 @@ items: href: code-analysis/quality-rules/ca1846.md - name: CA1847 href: code-analysis/quality-rules/ca1847.md + - name: CA1848 + href: code-analysis/quality-rules/ca1848.md - name: CA1849 href: code-analysis/quality-rules/ca1849.md - name: CA1850 @@ -1066,6 +1076,8 @@ items: href: code-analysis/quality-rules/ca2015.md - name: CA2016 href: code-analysis/quality-rules/ca2016.md + - name: CA2017 + href: code-analysis/quality-rules/ca2017.md - name: CA2018 href: code-analysis/quality-rules/ca2018.md - name: Security rules @@ -1338,8 +1350,18 @@ items: href: code-analysis/quality-rules/ca2251.md - name: CA2252 href: code-analysis/quality-rules/ca2252.md + - name: CA2253 + href: code-analysis/quality-rules/ca2253.md + - name: CA2254 + href: code-analysis/quality-rules/ca2254.md - name: CA2255 href: code-analysis/quality-rules/ca2255.md + - name: CA2256 + href: code-analysis/quality-rules/ca2256.md + - name: CA2257 + href: code-analysis/quality-rules/ca2257.md + - name: CA2258 + href: code-analysis/quality-rules/ca2258.md - name: Code style rules items: - name: Overview From b3b06428e3d1a59a9930f5ac54ef829142dea3f1 Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Wed, 19 Jan 2022 14:28:45 +0200 Subject: [PATCH 02/18] Add to index --- .../fundamentals/code-analysis/quality-rules/index.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/fundamentals/code-analysis/quality-rules/index.md b/docs/fundamentals/code-analysis/quality-rules/index.md index 487e28d208241..0730432afb805 100644 --- a/docs/fundamentals/code-analysis/quality-rules/index.md +++ b/docs/fundamentals/code-analysis/quality-rules/index.md @@ -78,6 +78,7 @@ The following table lists code quality analysis rules. > | [CA1416: Validate platform compatibility](ca1416.md) | Using platform-dependent APIs on a component makes the code no longer work across all platforms. | > | [CA1417: Do not use `OutAttribute` on string parameters for P/Invokes](ca1417.md) | String parameters passed by value with the `OutAttribute` can destabilize the runtime if the string is an interned string. | > | [CA1418: Use valid platform string](ca1418.md) | Platform compatibility analyzer requires a valid platform name and version. | +> | [CA1419: Provide a parameterless constructor that is as visible as the containing type for concrete types derived from 'System.Runtime.InteropServices.SafeHandle'](ca1419.md) | Providing a parameterless constructor that is as visible as the containing type for a type derived from 'System.Runtime.InteropServices.SafeHandle' enables better performance and usage with source-generated interop solutions. | > | [CA1501: Avoid excessive inheritance](ca1501.md) | A type is more than four levels deep in its inheritance hierarchy. Deeply nested type hierarchies can be difficult to follow, understand, and maintain. | > | [CA1502: Avoid excessive complexity](ca1502.md) | This rule measures the number of linearly independent paths through the method, which is determined by the number and complexity of conditional branches. | > | [CA1505: Avoid unmaintainable code](ca1505.md) | A type or method has a low maintainability index value. A low maintainability index indicates that a type or method is probably difficult to maintain and would be a good candidate for redesign. | @@ -100,6 +101,7 @@ The following table lists code quality analysis rules. > | [CA1721: Property names should not match get methods](ca1721.md) |The name of a public or protected member starts with "Get" and otherwise matches the name of a public or protected property. "Get" methods and properties should have names that clearly distinguish their function. | > | [CA1724: Type Names Should Not Match Namespaces](ca1724.md) | Type names should not match the names of .NET namespaces. Violating this rule can reduce the usability of the library. | > | [CA1725: Parameter names should match base declaration](ca1725.md) | Consistent naming of parameters in an override hierarchy increases the usability of the method overrides. A parameter name in a derived method that differs from the name in the base declaration can cause confusion about whether the method is an override of the base method or a new overload of the method. | +> | [CA1727: Use PascalCase for named placeholders](ca1727.md) | Use PascalCase for named placeholders in the logging message template. | > | [CA1801: Review unused parameters](ca1801.md) | A method signature includes a parameter that is not used in the method body. | > |[CA1802: Use Literals Where Appropriate](ca1802.md) |A field is declared static and read-only (Shared and ReadOnly in Visual Basic), and is initialized by using a value that is computable at compile time. Because the value that is assigned to the targeted field is computable at compile time, change the declaration to a const (Const in Visual Basic) field so that the value is computed at compile time instead of at run time. | > | [CA1805: Do not initialize unnecessarily](ca1805.md) | The .NET runtime initializes all fields of reference types to their default values before running the constructor. In most cases, explicitly initializing a field to its default value is redundant, which adds to maintenance costs and may degrade performance (such as with increased assembly size). | @@ -133,10 +135,13 @@ The following table lists code quality analysis rules. > | [CA1839: Use Environment.ProcessPath instead of Process.GetCurrentProcess().MainModule.FileName](ca1837.md) | `Environment.ProcessPath` is simpler and faster than `Process.GetCurrentProcess().MainModule.FileName`. | > | [CA1840: Use Environment.CurrentManagedThreadId instead of Thread.CurrentThread.ManagedThreadId](ca1837.md) | `Environment.CurrentManagedThreadId` is more compact and efficient than `Thread.CurrentThread.ManagedThreadId`. | > | [CA1841: Prefer Dictionary Contains methods](ca1841.md) | Calling `Contains` on the `Keys` or `Values` collection may often be more expensive than calling `ContainsKey` or `ContainsValue` on the dictionary itself. | +> | [CA1842: Do not use 'WhenAll' with a single task](ca1842.md) | Using 'WhenAll' with a single task may result in performance loss, await or return the task instead. | +> | [CA1843: Do not use 'WaitAll' with a single task](ca1843.md) | Using 'WaitAll' with a single task may result in performance loss, await or return the task instead. | > | [CA1844: Provide memory-based overrides of async methods when subclassing 'Stream'](ca1844.md) | To improve performance, override the memory-based async methods when subclassing 'Stream'. Then implement the array-based methods in terms of the memory-based methods. | > | [CA1845: Use span-based 'string.Concat'](ca1845.md) | It is more efficient to use `AsSpan` and `string.Concat`, instead of `Substring` and a concatenation operator. | > | [CA1846: Prefer `AsSpan` over `Substring`](ca1846.md) | `AsSpan` is more efficient than `Substring`. `Substring` performs an O(n) string copy, while `AsSpan` does not and has a constant cost. `AsSpan` also does not perform any heap allocations. | > | [CA1847: Use char literal for a single character lookup](ca1847.md) | Use `string.Contains(char)` instead of `string.Contains(string)` when searching for a single character. | +> | [CA1848: Use the LoggerMessage delegates](ca1848.md) | For improved performance, use the LoggerMessage delegates. | > | [CA1849: Call async methods when in an async method](ca1849.md) | In a method which is already asynchronous, calls to other methods should be to their async versions, where they exist. | > | [CA1850: Prefer static `HashData` method over `ComputeHash`](ca1850.md) | It's more efficient to use the static `HashData` method over creating and managing a `HashAlgorithm` instance to call `ComputeHash`. | > | [CA2000: Dispose objects before losing scope](ca2000.md) | Because an exceptional event might occur that will prevent the finalizer of an object from running, the object should be explicitly disposed before all references to it are out of scope. | @@ -150,6 +155,7 @@ The following table lists code quality analysis rules. > | [CA2014: Do not use stackalloc in loops.](ca2014.md) | Stack space allocated by a stackalloc is only released at the end of the current method's invocation. Using it in a loop can result in unbounded stack growth and eventual stack overflow conditions. | > | [CA2015: Do not define finalizers for types derived from MemoryManager<T>](ca2015.md) | Adding a finalizer to a type derived from may permit memory to be freed while it is still in use by a . | > | [CA2016: Forward the CancellationToken parameter to methods that take one](ca2016.md) | Forward the `CancellationToken` parameter to methods that take one to ensure the operation cancellation notifications gets properly propagated, or pass in `CancellationToken.None` explicitly to indicate intentionally not propagating the token. | +> | [CA2017: Parameter count mismatch](ca2017.md) | Number of parameters supplied in the logging message template do not match the number of named placeholders. | > | [CA2018: The `count` argument to `Buffer.BlockCopy` should specify the number of bytes to copy](ca2018.md) | When using `Buffer.BlockCopy`, the `count` argument specifies the number of bytes to copy. You should only use `Array.Length` for the `count` argument on arrays whose elements are exactly one byte in size. `byte`, `sbyte`, and `bool` arrays have elements that are one byte in size. | > | [CA2100: Review SQL queries for security vulnerabilities](ca2100.md) | A method sets the System.Data.IDbCommand.CommandText property by using a string that is built from a string argument to the method. This rule assumes that the string argument contains user input. A SQL command string that is built from user input is vulnerable to SQL injection attacks. | > |[CA2101: Specify marshaling for P/Invoke string arguments](ca2101.md) | A platform invoke member allows partially trusted callers, has a string parameter, and does not explicitly marshal the string. This can cause a potential security vulnerability. | @@ -189,7 +195,12 @@ The following table lists code quality analysis rules. > | [CA2250: Use `ThrowIfCancellationRequested`](ca2250.md) | `ThrowIfCancellationRequested` automatically checks whether the token has been canceled, and throws an `OperationCanceledException` if it has. | > | [CA2251: Use `String.Equals` over `String.Compare`](ca2251.md) | It is both clearer and likely faster to use `String.Equals` instead of comparing the result of `String.Compare` to zero. | > | [CA2252: Opt in to preview features](ca2252.md) | Opt in to preview features before using preview APIs. | +> | [CA2253: Named placeholders should not be numeric values](ca2253.md) | Named placeholders in the logging message template should not be comprised of only numeric characters. | +> | [CA2254: Template should be a static expression](ca2254.md) | The logging message template should not vary between calls. | > | [CA2255: The `ModuleInitializer` attribute should not be used in libraries](ca2255.md) | Module initializers are intended to be used by application code to ensure an application's components are initialized before the application code begins executing. | +> | [CA2256: All members declared in parent interfaces must have an implementation in a DynamicInterfaceCastableImplementation-attributed interface](ca2256.md) | Types attributed with 'DynamicInterfaceCastableImplementationAttribute' act as an interface implementation for a type that implements the 'IDynamicInterfaceCastable' type. As a result, it must provide an implementation of all of the members defined in the inherited interfaces, because the type that implements 'IDynamicInterfaceCastable' will not provide them otherwise. | +> | [CA2257: Members defined on an interface with the 'DynamicInterfaceCastableImplementationAttribute' should be 'static'](ca2257.md) | Since a type that implements 'IDynamicInterfaceCastable' may not implement a dynamic interface in metadata, calls to an instance interface member that is not an explicit implementation defined on this type are likely to fail at runtime. Mark new interface members 'static' to avoid runtime errors. | +> | [CA2258: Providing a 'DynamicInterfaceCastableImplementation' interface in Visual Basic is unsupported](ca2258.md) | Providing a functional 'DynamicInterfaceCastableImplementationAttribute'-attributed interface requires the Default Interface Members feature, which is unsupported in Visual Basic. | > | [CA2300: Do not use insecure deserializer BinaryFormatter](ca2300.md) | Insecure deserializers are vulnerable when deserializing untrusted data. An attacker could modify the serialized data to include unexpected types to inject objects with malicious side effects. | > | [CA2301: Do not call BinaryFormatter.Deserialize without first setting BinaryFormatter.Binder](ca2301.md) | Insecure deserializers are vulnerable when deserializing untrusted data. An attacker could modify the serialized data to include unexpected types to inject objects with malicious side effects. | > | [CA2302: Ensure BinaryFormatter.Binder is set before calling BinaryFormatter.Deserialize](ca2302.md) | Insecure deserializers are vulnerable when deserializing untrusted data. An attacker could modify the serialized data to include unexpected types to inject objects with malicious side effects. | From ecd08bd4e2c81485058ce3124a1bbc7d376b977e Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Wed, 19 Jan 2022 14:34:33 +0200 Subject: [PATCH 03/18] Add to category-based index --- .../code-analysis/quality-rules/interoperability-warnings.md | 1 + .../code-analysis/quality-rules/naming-warnings.md | 1 + .../code-analysis/quality-rules/performance-warnings.md | 3 +++ .../code-analysis/quality-rules/reliability-warnings.md | 1 + .../code-analysis/quality-rules/usage-warnings.md | 5 +++++ 5 files changed, 11 insertions(+) diff --git a/docs/fundamentals/code-analysis/quality-rules/interoperability-warnings.md b/docs/fundamentals/code-analysis/quality-rules/interoperability-warnings.md index 5a4681a16c53a..95d4edb5046e9 100644 --- a/docs/fundamentals/code-analysis/quality-rules/interoperability-warnings.md +++ b/docs/fundamentals/code-analysis/quality-rules/interoperability-warnings.md @@ -27,3 +27,4 @@ Portability rules support portability across different platforms. Interoperabili | [CA1416: Validate platform compatibility](ca1416.md) | Using platform-dependent APIs on a component makes the code no longer work across all platforms. | | [CA1417: Do not use `OutAttribute` on string parameters for P/Invokes](ca1417.md) | String parameters passed by value with the `OutAttribute` can destabilize the runtime if the string is an interned string. | | [CA1418: Use valid platform string](ca1418.md) | Platform compatibility analyzer requires a valid platform name and version. | +| [CA1419: Provide a parameterless constructor that is as visible as the containing type for concrete types derived from 'System.Runtime.InteropServices.SafeHandle'](ca1419.md) | Providing a parameterless constructor that is as visible as the containing type for a type derived from 'System.Runtime.InteropServices.SafeHandle' enables better performance and usage with source-generated interop solutions. | diff --git a/docs/fundamentals/code-analysis/quality-rules/naming-warnings.md b/docs/fundamentals/code-analysis/quality-rules/naming-warnings.md index a629b3db41206..6489127f71ace 100644 --- a/docs/fundamentals/code-analysis/quality-rules/naming-warnings.md +++ b/docs/fundamentals/code-analysis/quality-rules/naming-warnings.md @@ -35,3 +35,4 @@ Naming rules support adherence to the [naming conventions of the .NET design gui |[CA1721: Property names should not match get methods](ca1721.md)|The name of a public or protected member starts with "Get" and otherwise matches the name of a public or protected property. "Get" methods and properties should have names that clearly distinguish their function.| |[CA1724: Type Names Should Not Match Namespaces](ca1724.md)|Type names should not match the names of .NET namespaces. Violation of this rule can reduce the usability of the library.| |[CA1725: Parameter names should match base declaration](ca1725.md)|Consistent naming of parameters in an override hierarchy increases the usability of the method overrides. A parameter name in a derived method that differs from the name in the base declaration can cause confusion about whether the method is an override of the base method or a new overload of the method.| +|[CA1727: Use PascalCase for named placeholders](ca1727.md)|Use PascalCase for named placeholders in the logging message template.| diff --git a/docs/fundamentals/code-analysis/quality-rules/performance-warnings.md b/docs/fundamentals/code-analysis/quality-rules/performance-warnings.md index e4d9291ac6ae3..ba0df0cc1849c 100644 --- a/docs/fundamentals/code-analysis/quality-rules/performance-warnings.md +++ b/docs/fundamentals/code-analysis/quality-rules/performance-warnings.md @@ -52,9 +52,12 @@ Performance rules support high-performance libraries and applications. | [CA1839: Use Environment.ProcessPath instead of Process.GetCurrentProcess().MainModule.FileName](ca1837.md) | `Environment.ProcessPath` is simpler and faster than `Process.GetCurrentProcess().MainModule.FileName`. | | [CA1840: Use Environment.CurrentManagedThreadId instead of Thread.CurrentThread.ManagedThreadId](ca1837.md) | `Environment.CurrentManagedThreadId` is more compact and efficient than `Thread.CurrentThread.ManagedThreadId`. | | [CA1841: Prefer Dictionary Contains methods](ca1841.md) | Calling `Contains` on the `Keys` or `Values` collection may often be more expensive than calling `ContainsKey` or `ContainsValue` on the dictionary itself. | +| [CA1842: Do not use 'WhenAll' with a single task](ca1842.md) | Using 'WhenAll' with a single task may result in performance loss, await or return the task instead. | +| [CA1843: Do not use 'WaitAll' with a single task](ca1843.md) | Using 'WaitAll' with a single task may result in performance loss, await or return the task instead. | | [CA1844: Provide memory-based overrides of async methods when subclassing 'Stream'](ca1844.md) | To improve performance, override the memory-based async methods when subclassing 'Stream'. Then implement the array-based methods in terms of the memory-based methods. | | [CA1845: Use span-based 'string.Concat'](ca1845.md) | It is more efficient to use `AsSpan` and `string.Concat`, instead of `Substring` and a concatenation operator. | | [CA1846: Prefer `AsSpan` over `Substring`](ca1846.md) | `AsSpan` is more efficient than `Substring`. `Substring` performs an O(n) string copy, while `AsSpan` does not and has a constant cost. `AsSpan` also does not perform any heap allocations. | | [CA1847: Use char literal for a single character lookup](ca1847.md) | Use `string.Contains(char)` instead of `string.Contains(string)` when searching for a single character. | +| [CA1848: Use the LoggerMessage delegates](ca1848.md) | For improved performance, use the LoggerMessage delegates. | | [CA1849: Call async methods when in an async method](ca1849.md) | In a method which is already asynchronous, calls to other methods should be to their async versions, where they exist. | | [CA1850: Prefer static `HashData` method over `ComputeHash`](ca1850.md) | It's more efficient to use the static `HashData` method over creating and managing a `HashAlgorithm` instance to call `ComputeHash`. | diff --git a/docs/fundamentals/code-analysis/quality-rules/reliability-warnings.md b/docs/fundamentals/code-analysis/quality-rules/reliability-warnings.md index 88e4ab73ddaad..dba23563fa47a 100644 --- a/docs/fundamentals/code-analysis/quality-rules/reliability-warnings.md +++ b/docs/fundamentals/code-analysis/quality-rules/reliability-warnings.md @@ -29,4 +29,5 @@ Reliability rules support library and application reliability, such as correct m |[CA2014: Do not use stackalloc in loops.](ca2014.md) | Stack space allocated by a stackalloc is only released at the end of the current method's invocation. Using it in a loop can result in unbounded stack growth and eventual stack overflow conditions. | |[CA2015: Do not define finalizers for types derived from MemoryManager<T>](ca2015.md) | Adding a finalizer to a type derived from may permit memory to be freed while it is still in use by a . | |[CA2016: Forward the CancellationToken parameter to methods that take one](ca2016.md) | Forward the `CancellationToken` parameter to methods that take one to ensure the operation cancellation notifications gets properly propagated, or pass in `CancellationToken.None` explicitly to indicate intentionally not propagating the token. | +|[CA2017: Parameter count mismatch](ca2017.md) | Number of parameters supplied in the logging message template do not match the number of named placeholders. | |[CA2018: The `count` argument to `Buffer.BlockCopy` should specify the number of bytes to copy](ca2018.md) | When using `Buffer.BlockCopy`, the `count` argument specifies the number of bytes to copy. You should only use `Array.Length` for the `count` argument on arrays whose elements are exactly one byte in size. `byte`, `sbyte`, and `bool` arrays have elements that are one byte in size. | diff --git a/docs/fundamentals/code-analysis/quality-rules/usage-warnings.md b/docs/fundamentals/code-analysis/quality-rules/usage-warnings.md index 2fe754465c34a..d11527faeda52 100644 --- a/docs/fundamentals/code-analysis/quality-rules/usage-warnings.md +++ b/docs/fundamentals/code-analysis/quality-rules/usage-warnings.md @@ -55,4 +55,9 @@ Usage rules support proper usage of .NET. |[CA2250: Use `ThrowIfCancellationRequested`](ca2250.md) | `ThrowIfCancellationRequested` automatically checks whether the token has been canceled, and throws an `OperationCanceledException` if it has.| |[CA2251: Use `String.Equals` over `String.Compare`](ca2251.md)|It is both clearer and likely faster to use `String.Equals` instead of comparing the result of `String.Compare` to zero.| |[CA2252: Opt in to preview features](ca2252.md)|Opt in to preview features before using preview APIs.| +|[CA2253: Named placeholders should not be numeric values](ca2253.md)|Named placeholders in the logging message template should not be comprised of only numeric characters.| +|[CA2254: Template should be a static expression](ca2254.md)|The logging message template should not vary between calls.| |[CA2255: The `ModuleInitializer` attribute should not be used in libraries](ca2255.md) | Module initializers are intended to be used by application code to ensure an application's components are initialized before the application code begins executing. | +|[CA2256: All members declared in parent interfaces must have an implementation in a DynamicInterfaceCastableImplementation-attributed interface](ca2256.md) | Types attributed with 'DynamicInterfaceCastableImplementationAttribute' act as an interface implementation for a type that implements the 'IDynamicInterfaceCastable' type. As a result, it must provide an implementation of all of the members defined in the inherited interfaces, because the type that implements 'IDynamicInterfaceCastable' will not provide them otherwise. | +|[CA2257: Members defined on an interface with the 'DynamicInterfaceCastableImplementationAttribute' should be 'static'](ca2257.md) | Since a type that implements 'IDynamicInterfaceCastable' may not implement a dynamic interface in metadata, calls to an instance interface member that is not an explicit implementation defined on this type are likely to fail at runtime. Mark new interface members 'static' to avoid runtime errors. | +|[CA2258: Providing a 'DynamicInterfaceCastableImplementation' interface in Visual Basic is unsupported](ca2258.md) | Providing a functional 'DynamicInterfaceCastableImplementationAttribute'-attributed interface requires the Default Interface Members feature, which is unsupported in Visual Basic. | From 7e5df200927da9394127890bbc14e469508e8c1e Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Wed, 19 Jan 2022 14:51:47 +0200 Subject: [PATCH 04/18] Add rule doc files --- .../code-analysis/quality-rules/ca1419.md | 41 +++++++++++++++++++ .../code-analysis/quality-rules/ca1727.md | 36 ++++++++++++++++ .../code-analysis/quality-rules/ca1842.md | 41 +++++++++++++++++++ .../code-analysis/quality-rules/ca1843.md | 41 +++++++++++++++++++ .../code-analysis/quality-rules/ca1848.md | 40 ++++++++++++++++++ .../code-analysis/quality-rules/ca2017.md | 40 ++++++++++++++++++ .../code-analysis/quality-rules/ca2253.md | 40 ++++++++++++++++++ .../code-analysis/quality-rules/ca2254.md | 40 ++++++++++++++++++ .../code-analysis/quality-rules/ca2256.md | 40 ++++++++++++++++++ .../code-analysis/quality-rules/ca2257.md | 40 ++++++++++++++++++ .../code-analysis/quality-rules/ca2258.md | 40 ++++++++++++++++++ 11 files changed, 439 insertions(+) create mode 100644 docs/fundamentals/code-analysis/quality-rules/ca1419.md create mode 100644 docs/fundamentals/code-analysis/quality-rules/ca1727.md create mode 100644 docs/fundamentals/code-analysis/quality-rules/ca1842.md create mode 100644 docs/fundamentals/code-analysis/quality-rules/ca1843.md create mode 100644 docs/fundamentals/code-analysis/quality-rules/ca1848.md create mode 100644 docs/fundamentals/code-analysis/quality-rules/ca2017.md create mode 100644 docs/fundamentals/code-analysis/quality-rules/ca2253.md create mode 100644 docs/fundamentals/code-analysis/quality-rules/ca2254.md create mode 100644 docs/fundamentals/code-analysis/quality-rules/ca2256.md create mode 100644 docs/fundamentals/code-analysis/quality-rules/ca2257.md create mode 100644 docs/fundamentals/code-analysis/quality-rules/ca2258.md diff --git a/docs/fundamentals/code-analysis/quality-rules/ca1419.md b/docs/fundamentals/code-analysis/quality-rules/ca1419.md new file mode 100644 index 0000000000000..161c48254b99a --- /dev/null +++ b/docs/fundamentals/code-analysis/quality-rules/ca1419.md @@ -0,0 +1,41 @@ +--- +title: "CA1419: Provide a parameterless constructor that is as visible as the containing type for concrete types derived from 'System.Runtime.InteropServices.SafeHandle' (code analysis)" +description: "Learn about code analysis rule CA1419: Provide a parameterless constructor that is as visible as the containing type for concrete types derived from 'System.Runtime.InteropServices.SafeHandle'" +ms.date: 01/19/2022 +ms.topic: reference +f1_keywords: + - "ProvidePublicParameterlessSafeHandleConstructorAnalyzer" + - "CA1419" +helpviewer_keywords: + - "ProvidePublicParameterlessSafeHandleConstructorAnalyzer" + - "CA1419" +author: Youssef1313 +--- +# CA1419: Provide a parameterless constructor that is as visible as the containing type for concrete types derived from 'System.Runtime.InteropServices.SafeHandle' + +| | Value | +|-|-| +| **Rule ID** |CA1419| +| **Category** |[Interoperability](interoperability-warnings.md)| +| **Fix is breaking or non-breaking** |Non-breaking| + +## Cause + +A concrete type requires a parameterless constructor that is at least as visible as the containing type. + +## Rule description + +Providing a public parameterless constructor for a type derived from enables better performance and usage with source-generated interop solutions. + +## How to fix violations + +Add a parameterless constructor to your type. + +## When to suppress warnings + +Do not suppress a warning from this rule. + +## See also + +- [Interoperability rules](interoperability-warnings.md) +- [Native interoperability best practices](../../../standard/native-interop/best-practices.md) diff --git a/docs/fundamentals/code-analysis/quality-rules/ca1727.md b/docs/fundamentals/code-analysis/quality-rules/ca1727.md new file mode 100644 index 0000000000000..cd85cdad6af52 --- /dev/null +++ b/docs/fundamentals/code-analysis/quality-rules/ca1727.md @@ -0,0 +1,36 @@ +--- +title: "CA1727: Use PascalCase for named placeholders (code analysis)" +description: "Learn about code analysis rule CA1727: Use PascalCase for named placeholders" +ms.date: 01/19/2022 +ms.topic: reference +f1_keywords: +- LoggerMessageDefineAnalyzer +- CA1727 +helpviewer_keywords: +- CA1727 +- LoggerMessageDefineAnalyzer +author: Youssef1313 +--- +# CA1727: Use PascalCase for named placeholders + +| | Value | +|-|-| +| **Rule ID** |CA1727| +| **Category** |[Naming](naming-warnings.md)| +| **Fix is breaking or non-breaking** |Non-breaking| + +## Cause + +A named placeholder used with is not PascalCase. + +## Rule description + +A named placeholder used with should be PascalCase + +## How to fix violations + +Use PascalCase for named placeholders. + +## When to suppress warnings + +Do not suppress a warning from this rule. diff --git a/docs/fundamentals/code-analysis/quality-rules/ca1842.md b/docs/fundamentals/code-analysis/quality-rules/ca1842.md new file mode 100644 index 0000000000000..c898f6eb1da91 --- /dev/null +++ b/docs/fundamentals/code-analysis/quality-rules/ca1842.md @@ -0,0 +1,41 @@ +--- +title: "CA1842: Do not use 'WhenAll' with a single task (code analysis)" +description: "Learn about code analysis rule CA1842: Do not use 'WhenAll' with a single task" +ms.date: 01/19/2022 +ms.topic: reference +f1_keywords: + - "DoNotUseWhenAllOrWaitAllWithSingleArgument" + - "CA1842" +helpviewer_keywords: + - "DoNotUseWhenAllOrWaitAllWithSingleArgument" + - "CA1842" +author: Youssef1313 +--- +# CA1842: Do not use 'WhenAll' with a single task + +| | Value | +|-|-| +| **Rule ID** |CA1842| +| **Category** |[Performance](performance-warnings.md)| +| **Fix is breaking or non-breaking** |Non-breaking| + +## Cause + + is called with a single task. + +## Rule description + +Using 'WhenAll' with a single task may result in performance loss. + +## How to fix violations + +You should await or return the task instead. + +## When to suppress warnings + +Do not suppress a warning from this rule. + +## See also + +- [CA1843: Do not use 'WaitAll' with a single task](ca1843.md) +- [Performance rules](performance-warnings.md) diff --git a/docs/fundamentals/code-analysis/quality-rules/ca1843.md b/docs/fundamentals/code-analysis/quality-rules/ca1843.md new file mode 100644 index 0000000000000..66113b0e3c014 --- /dev/null +++ b/docs/fundamentals/code-analysis/quality-rules/ca1843.md @@ -0,0 +1,41 @@ +--- +title: "CA1843: Do not use 'WaitAll' with a single task (code analysis)" +description: "Learn about code analysis rule CA1843: Do not use 'WaitAll' with a single task" +ms.date: 01/19/2022 +ms.topic: reference +f1_keywords: + - "DoNotUseWhenAllOrWaitAllWithSingleArgument" + - "CA1843" +helpviewer_keywords: + - "DoNotUseWhenAllOrWaitAllWithSingleArgument" + - "CA1843" +author: Youssef1313 +--- +# CA1843: Do not use 'WaitAll' with a single task + +| | Value | +|-|-| +| **Rule ID** |CA1843| +| **Category** |[Performance](performance-warnings.md)| +| **Fix is breaking or non-breaking** |Non-breaking| + +## Cause + + is called with a single task. + +## Rule description + +Using 'WaitAll' with a single task may result in performance loss. + +## How to fix violations + +You should await or return the task instead. + +## When to suppress warnings + +Do not suppress a warning from this rule. + +## See also + +- [CA1842: Do not use 'WhenAll' with a single task](ca1842.md) +- [Performance rules](performance-warnings.md) diff --git a/docs/fundamentals/code-analysis/quality-rules/ca1848.md b/docs/fundamentals/code-analysis/quality-rules/ca1848.md new file mode 100644 index 0000000000000..689fba789fbb4 --- /dev/null +++ b/docs/fundamentals/code-analysis/quality-rules/ca1848.md @@ -0,0 +1,40 @@ +--- +title: "CA1848: Use the LoggerMessage delegates (code analysis)" +description: "Learn about code analysis rule CA1848: Use the LoggerMessage delegates" +ms.date: 01/19/2022 +ms.topic: reference +f1_keywords: + - "LoggerMessageDefineAnalyzer" + - "CA1848" +helpviewer_keywords: + - "LoggerMessageDefineAnalyzer" + - "CA1848" +author: Youssef1313 +--- +# CA1848: Use the LoggerMessage delegates + +| | Value | +|-|-| +| **Rule ID** |CA1848| +| **Category** |[Performance](performance-warnings.md)| +| **Fix is breaking or non-breaking** |Non-breaking| + +## Cause + +TODO + +## Rule description + +TODO + +## How to fix violations + +TODO + +## When to suppress warnings + +TODO + +## See also + +- [Performance rules](performance-warnings.md) diff --git a/docs/fundamentals/code-analysis/quality-rules/ca2017.md b/docs/fundamentals/code-analysis/quality-rules/ca2017.md new file mode 100644 index 0000000000000..513587ec2d4d4 --- /dev/null +++ b/docs/fundamentals/code-analysis/quality-rules/ca2017.md @@ -0,0 +1,40 @@ +--- +title: "CA2017: Parameter count mismatch (code analysis)" +description: "Learn about code analysis rule CA2017: Parameter count mismatch" +ms.date: 01/19/2022 +ms.topic: reference +f1_keywords: + - "LoggerMessageDefineAnalyzer" + - "CA2017" +helpviewer_keywords: + - "LoggerMessageDefineAnalyzer" + - "CA2017" +author: Youssef1313 +--- +# CA2017: Parameter count mismatch + +| | Value | +|-|-| +| **Rule ID** |CA2017| +| **Category** |[Reliability](reliability-warnings.md)| +| **Fix is breaking or non-breaking** |Non-breaking| + +## Cause + +TODO + +## Rule description + +TODO + +## How to fix violations + +TODO + +## When to suppress warnings + +TODO + +## See also + +- [Reliability rules](reliability-warnings.md) diff --git a/docs/fundamentals/code-analysis/quality-rules/ca2253.md b/docs/fundamentals/code-analysis/quality-rules/ca2253.md new file mode 100644 index 0000000000000..4d94544faf9eb --- /dev/null +++ b/docs/fundamentals/code-analysis/quality-rules/ca2253.md @@ -0,0 +1,40 @@ +--- +title: "CA2253: Named placeholders should not be numeric values" +description: "Learn about code analysis rule CA2253: Named placeholders should not be numeric values" +ms.date: 01/19/2022 +ms.topic: reference +f1_keywords: +- CA2253 +- LoggerMessageDefineAnalyzer +helpviewer_keywords: +- LoggerMessageDefineAnalyzer +- CA2253 +author: Youssef1313 +--- +# CA2253: Named placeholders should not be numeric values + +| | Value | +| ----------------------------------- | ------------------------------------ | +| **Rule ID** | CA2253 | +| **Category** | [Usage](usage-warnings.md) | +| **Fix is breaking or non-breaking** | Non-breaking | + +## Cause + +TODO + +## Rule description + +TODO + +## How to fix violations + +TODO + +## When to suppress errors + +TODO + +## See also + +- [Usage warnings](usage-warnings.md) diff --git a/docs/fundamentals/code-analysis/quality-rules/ca2254.md b/docs/fundamentals/code-analysis/quality-rules/ca2254.md new file mode 100644 index 0000000000000..ea5c1079a708b --- /dev/null +++ b/docs/fundamentals/code-analysis/quality-rules/ca2254.md @@ -0,0 +1,40 @@ +--- +title: "CA2254: Template should be a static expression" +description: "Learn about code analysis rule CA2254: Template should be a static expression" +ms.date: 01/19/2022 +ms.topic: reference +f1_keywords: +- CA2254 +- LoggerMessageDefineAnalyzer +helpviewer_keywords: +- LoggerMessageDefineAnalyzer +- CA2254 +author: Youssef1313 +--- +# CA2254: Template should be a static expression + +| | Value | +| ----------------------------------- | ------------------------------------ | +| **Rule ID** | CA2254 | +| **Category** | [Usage](usage-warnings.md) | +| **Fix is breaking or non-breaking** | Non-breaking | + +## Cause + +TODO + +## Rule description + +TODO + +## How to fix violations + +TODO + +## When to suppress errors + +TODO + +## See also + +- [Usage warnings](usage-warnings.md) diff --git a/docs/fundamentals/code-analysis/quality-rules/ca2256.md b/docs/fundamentals/code-analysis/quality-rules/ca2256.md new file mode 100644 index 0000000000000..17418a75a4c34 --- /dev/null +++ b/docs/fundamentals/code-analysis/quality-rules/ca2256.md @@ -0,0 +1,40 @@ +--- +title: "CA2256: All members declared in parent interfaces must have an implementation in a DynamicInterfaceCastableImplementation-attributed interface" +description: "Learn about code analysis rule CA2256: All members declared in parent interfaces must have an implementation in a DynamicInterfaceCastableImplementation-attributed interface" +ms.date: 01/19/2022 +ms.topic: reference +f1_keywords: +- CA2256 +- DynamicInterfaceCastableImplementationAnalyzer +helpviewer_keywords: +- DynamicInterfaceCastableImplementationAnalyzer +- CA2256 +author: Youssef1313 +--- +# CA2256: All members declared in parent interfaces must have an implementation in a DynamicInterfaceCastableImplementation-attributed interface + +| | Value | +| ----------------------------------- | ------------------------------------ | +| **Rule ID** | CA2256 | +| **Category** | [Usage](usage-warnings.md) | +| **Fix is breaking or non-breaking** | Non-breaking | + +## Cause + +TODO + +## Rule description + +TODO + +## How to fix violations + +TODO + +## When to suppress errors + +TODO + +## See also + +- [Usage warnings](usage-warnings.md) diff --git a/docs/fundamentals/code-analysis/quality-rules/ca2257.md b/docs/fundamentals/code-analysis/quality-rules/ca2257.md new file mode 100644 index 0000000000000..ba62f67fc45f9 --- /dev/null +++ b/docs/fundamentals/code-analysis/quality-rules/ca2257.md @@ -0,0 +1,40 @@ +--- +title: "CA2257: Members defined on an interface with the 'DynamicInterfaceCastableImplementationAttribute' should be 'static'" +description: "Learn about code analysis rule CA2257: Members defined on an interface with the 'DynamicInterfaceCastableImplementationAttribute' should be 'static'" +ms.date: 01/19/2022 +ms.topic: reference +f1_keywords: +- CA2257 +- DynamicInterfaceCastableImplementationAnalyzer +helpviewer_keywords: +- DynamicInterfaceCastableImplementationAnalyzer +- CA2257 +author: Youssef1313 +--- +# CA2257: Members defined on an interface with the 'DynamicInterfaceCastableImplementationAttribute' should be 'static' + +| | Value | +| ----------------------------------- | ------------------------------------ | +| **Rule ID** | CA2257 | +| **Category** | [Usage](usage-warnings.md) | +| **Fix is breaking or non-breaking** | Non-breaking | + +## Cause + +TODO + +## Rule description + +TODO + +## How to fix violations + +TODO + +## When to suppress errors + +TODO + +## See also + +- [Usage warnings](usage-warnings.md) diff --git a/docs/fundamentals/code-analysis/quality-rules/ca2258.md b/docs/fundamentals/code-analysis/quality-rules/ca2258.md new file mode 100644 index 0000000000000..3186f22b7faf3 --- /dev/null +++ b/docs/fundamentals/code-analysis/quality-rules/ca2258.md @@ -0,0 +1,40 @@ +--- +title: "CA2258: Providing a 'DynamicInterfaceCastableImplementation' interface in Visual Basic is unsupported" +description: "Learn about code analysis rule CA2258: Providing a 'DynamicInterfaceCastableImplementation' interface in Visual Basic is unsupported" +ms.date: 01/19/2022 +ms.topic: reference +f1_keywords: +- CA2258 +- DynamicInterfaceCastableImplementationAnalyzer +helpviewer_keywords: +- DynamicInterfaceCastableImplementationAnalyzer +- CA2258 +author: Youssef1313 +--- +# CA2258: Providing a 'DynamicInterfaceCastableImplementation' interface in Visual Basic is unsupported + +| | Value | +| ----------------------------------- | ------------------------------------ | +| **Rule ID** | CA2258 | +| **Category** | [Usage](usage-warnings.md) | +| **Fix is breaking or non-breaking** | Non-breaking | + +## Cause + +TODO + +## Rule description + +TODO + +## How to fix violations + +TODO + +## When to suppress errors + +TODO + +## See also + +- [Usage warnings](usage-warnings.md) From 819af6e68d7b842e5ac93c2aec9c183fce7aff25 Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Wed, 19 Jan 2022 15:39:45 +0200 Subject: [PATCH 05/18] Document CA1848 --- .../code-analysis/quality-rules/ca1848.md | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/docs/fundamentals/code-analysis/quality-rules/ca1848.md b/docs/fundamentals/code-analysis/quality-rules/ca1848.md index 689fba789fbb4..03ebcff50b9f5 100644 --- a/docs/fundamentals/code-analysis/quality-rules/ca1848.md +++ b/docs/fundamentals/code-analysis/quality-rules/ca1848.md @@ -21,20 +21,26 @@ author: Youssef1313 ## Cause -TODO +[logger extension methods](xref:Microsoft.Extensions.Logging.LoggerExtensions), such as and . ## Rule description -TODO +For high-performance logging scenarios, use the pattern. ## How to fix violations -TODO +Use `LoggerMessage` to fix violations of this rule. + + provides the following performance advantages over Logger extension methods: + +- Logger extension methods require "boxing" (converting) value types, such as `int`, into `object`. The pattern avoids boxing by using static fields and extension methods with strongly-typed parameters. +- Logger extension methods must parse the message template (named format string) every time a log message is written. only requires parsing a template once when the message is defined. ## When to suppress warnings -TODO +Do not suppress a warning from this rule. ## See also +- [High-performance logging with LoggerMessage in ASP.NET Core](/aspnet/core/fundamentals/logging/loggermessage) - [Performance rules](performance-warnings.md) From 20664a8498ba34a6bb338cd5fffe841ef79980db Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Wed, 19 Jan 2022 15:40:21 +0200 Subject: [PATCH 06/18] Fix xref --- docs/fundamentals/code-analysis/quality-rules/ca1842.md | 2 +- docs/fundamentals/code-analysis/quality-rules/ca1843.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/fundamentals/code-analysis/quality-rules/ca1842.md b/docs/fundamentals/code-analysis/quality-rules/ca1842.md index c898f6eb1da91..405d745391bf2 100644 --- a/docs/fundamentals/code-analysis/quality-rules/ca1842.md +++ b/docs/fundamentals/code-analysis/quality-rules/ca1842.md @@ -21,7 +21,7 @@ author: Youssef1313 ## Cause - is called with a single task. + is called with a single task. ## Rule description diff --git a/docs/fundamentals/code-analysis/quality-rules/ca1843.md b/docs/fundamentals/code-analysis/quality-rules/ca1843.md index 66113b0e3c014..f12f3b00c98f2 100644 --- a/docs/fundamentals/code-analysis/quality-rules/ca1843.md +++ b/docs/fundamentals/code-analysis/quality-rules/ca1843.md @@ -21,7 +21,7 @@ author: Youssef1313 ## Cause - is called with a single task. + is called with a single task. ## Rule description From 21725254eadd1e6d305e1fff27891d4659c3034c Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Wed, 19 Jan 2022 16:02:41 +0200 Subject: [PATCH 07/18] Document CA2017 --- docs/fundamentals/code-analysis/quality-rules/ca2017.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/fundamentals/code-analysis/quality-rules/ca2017.md b/docs/fundamentals/code-analysis/quality-rules/ca2017.md index 513587ec2d4d4..866be098ce394 100644 --- a/docs/fundamentals/code-analysis/quality-rules/ca2017.md +++ b/docs/fundamentals/code-analysis/quality-rules/ca2017.md @@ -21,19 +21,19 @@ author: Youssef1313 ## Cause -TODO +Number of parameters supplied in the logging message template do not match the number of named placeholders. ## Rule description -TODO +This rule flags logger calls that has incorrect number of message arguments. ## How to fix violations -TODO +Match the number of arguments in the template format with the number of passed arguments. ## When to suppress warnings -TODO +Do not suppress a warning from this rule. ## See also From 032b7c769229c45d55422edc43ba1f57e7b698a2 Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Wed, 19 Jan 2022 16:04:18 +0200 Subject: [PATCH 08/18] Update ca2017.md --- docs/fundamentals/code-analysis/quality-rules/ca2017.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/fundamentals/code-analysis/quality-rules/ca2017.md b/docs/fundamentals/code-analysis/quality-rules/ca2017.md index 866be098ce394..508f3dd15b2e9 100644 --- a/docs/fundamentals/code-analysis/quality-rules/ca2017.md +++ b/docs/fundamentals/code-analysis/quality-rules/ca2017.md @@ -29,7 +29,7 @@ This rule flags logger calls that has incorrect number of message arguments. ## How to fix violations -Match the number of arguments in the template format with the number of passed arguments. +Match the number of placeholders in the template format with the number of passed arguments. ## When to suppress warnings From 894e50fcb1a07360f053acb2c2a96e7ae7bd58a5 Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Wed, 19 Jan 2022 16:05:30 +0200 Subject: [PATCH 09/18] Document CA2253 --- docs/fundamentals/code-analysis/quality-rules/ca2253.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/fundamentals/code-analysis/quality-rules/ca2253.md b/docs/fundamentals/code-analysis/quality-rules/ca2253.md index 4d94544faf9eb..1fecd8ca7f666 100644 --- a/docs/fundamentals/code-analysis/quality-rules/ca2253.md +++ b/docs/fundamentals/code-analysis/quality-rules/ca2253.md @@ -21,19 +21,19 @@ author: Youssef1313 ## Cause -TODO +A message placeholder consists of numeric characters only. ## Rule description -TODO +Named placeholders in the logging message template should not be comprised of only numeric characters. ## How to fix violations -TODO +Rename the numeric placeholder. ## When to suppress errors -TODO +Do not suppress a warning from this rule. ## See also From 7e5428b1017428d29dcf4d978de5ef04304b3d53 Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Wed, 19 Jan 2022 16:09:31 +0200 Subject: [PATCH 10/18] Document CA2254 --- docs/fundamentals/code-analysis/quality-rules/ca2254.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/fundamentals/code-analysis/quality-rules/ca2254.md b/docs/fundamentals/code-analysis/quality-rules/ca2254.md index ea5c1079a708b..4967e2eccab62 100644 --- a/docs/fundamentals/code-analysis/quality-rules/ca2254.md +++ b/docs/fundamentals/code-analysis/quality-rules/ca2254.md @@ -21,19 +21,19 @@ author: Youssef1313 ## Cause -TODO +A message template passed to logger API is not constant. ## Rule description -TODO +The logging message template should not vary between calls. ## How to fix violations -TODO +Update the message template to be a constant expression. ## When to suppress errors -TODO +Do not suppress a warning from this rule. ## See also From ddf627b1996c50f94a5ce8758a0fee23fb55ea78 Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Wed, 19 Jan 2022 16:16:45 +0200 Subject: [PATCH 11/18] Document CA2256 --- docs/fundamentals/code-analysis/quality-rules/ca2256.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/fundamentals/code-analysis/quality-rules/ca2256.md b/docs/fundamentals/code-analysis/quality-rules/ca2256.md index 17418a75a4c34..2bbb8217c33c5 100644 --- a/docs/fundamentals/code-analysis/quality-rules/ca2256.md +++ b/docs/fundamentals/code-analysis/quality-rules/ca2256.md @@ -21,19 +21,19 @@ author: Youssef1313 ## Cause -TODO +An interface with has a non-implemented member. ## Rule description -TODO +Types attributed with act as an interface implementation for a type that implements the 'IDynamicInterfaceCastable' type. As a result, it must provide an implementation of all of the members defined in the inherited interfaces, because the type that implements 'IDynamicInterfaceCastable' will not provide them otherwise. ## How to fix violations -TODO +Implement the missing interface members. ## When to suppress errors -TODO +Do not suppress a warning from this rule. ## See also From 2243e47ec3296170ac6c2f68696a556e52e56d0a Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Wed, 19 Jan 2022 16:19:36 +0200 Subject: [PATCH 12/18] Document CA2257 --- docs/fundamentals/code-analysis/quality-rules/ca2257.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/fundamentals/code-analysis/quality-rules/ca2257.md b/docs/fundamentals/code-analysis/quality-rules/ca2257.md index ba62f67fc45f9..84cfa95404d61 100644 --- a/docs/fundamentals/code-analysis/quality-rules/ca2257.md +++ b/docs/fundamentals/code-analysis/quality-rules/ca2257.md @@ -21,19 +21,19 @@ author: Youssef1313 ## Cause -TODO +An interface member isn't explicitly implemented nor static. ## Rule description -TODO +Since a type that implements 'IDynamicInterfaceCastable' may not implement a dynamic interface in metadata, calls to an instance interface member that is not an explicit implementation defined on this type are likely to fail at runtime. Mark new interface members 'static' to avoid runtime errors. ## How to fix violations -TODO +Make the interface member static. ## When to suppress errors -TODO +Do not suppress a warning from this rule. ## See also From 62ca213bcb1e289c6280339daf1e87573c08197b Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Wed, 19 Jan 2022 16:21:28 +0200 Subject: [PATCH 13/18] Document CA2258 --- .../fundamentals/code-analysis/quality-rules/ca2258.md | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/docs/fundamentals/code-analysis/quality-rules/ca2258.md b/docs/fundamentals/code-analysis/quality-rules/ca2258.md index 3186f22b7faf3..16bb8af7feb3e 100644 --- a/docs/fundamentals/code-analysis/quality-rules/ca2258.md +++ b/docs/fundamentals/code-analysis/quality-rules/ca2258.md @@ -21,19 +21,15 @@ author: Youssef1313 ## Cause -TODO +Use of in Visual Basic. ## Rule description -TODO - -## How to fix violations - -TODO +Providing a functional 'DynamicInterfaceCastableImplementationAttribute'-attributed interface requires the Default Interface Members feature, which is unsupported in Visual Basic. ## When to suppress errors -TODO +Do not suppress a warning from this rule. ## See also From f995a954deca8354dc45f64b7c9486551e91d4ff Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Thu, 20 Jan 2022 07:53:15 +0200 Subject: [PATCH 14/18] Apply suggestions from code review Co-authored-by: Genevieve Warren <24882762+gewarren@users.noreply.github.com> --- .../fundamentals/code-analysis/quality-rules/ca1727.md | 2 +- .../fundamentals/code-analysis/quality-rules/ca1842.md | 2 +- .../fundamentals/code-analysis/quality-rules/ca1843.md | 2 +- .../fundamentals/code-analysis/quality-rules/ca1848.md | 4 ++-- .../fundamentals/code-analysis/quality-rules/ca2017.md | 4 ++-- .../fundamentals/code-analysis/quality-rules/ca2254.md | 2 +- .../fundamentals/code-analysis/quality-rules/ca2257.md | 10 +++++----- .../fundamentals/code-analysis/quality-rules/ca2258.md | 2 +- docs/fundamentals/code-analysis/quality-rules/index.md | 6 +++--- .../code-analysis/quality-rules/usage-warnings.md | 2 +- 10 files changed, 18 insertions(+), 18 deletions(-) diff --git a/docs/fundamentals/code-analysis/quality-rules/ca1727.md b/docs/fundamentals/code-analysis/quality-rules/ca1727.md index cd85cdad6af52..5ed3993e2562a 100644 --- a/docs/fundamentals/code-analysis/quality-rules/ca1727.md +++ b/docs/fundamentals/code-analysis/quality-rules/ca1727.md @@ -25,7 +25,7 @@ A named placeholder used with is not ## Rule description -A named placeholder used with should be PascalCase +A named placeholder used with should be PascalCase, a naming convention where the first letter of each compound word in a name is capitalized. ## How to fix violations diff --git a/docs/fundamentals/code-analysis/quality-rules/ca1842.md b/docs/fundamentals/code-analysis/quality-rules/ca1842.md index 405d745391bf2..72022a5b8eb91 100644 --- a/docs/fundamentals/code-analysis/quality-rules/ca1842.md +++ b/docs/fundamentals/code-analysis/quality-rules/ca1842.md @@ -25,7 +25,7 @@ author: Youssef1313 ## Rule description -Using 'WhenAll' with a single task may result in performance loss. +Using `WhenAll` with a single task may result in performance loss. ## How to fix violations diff --git a/docs/fundamentals/code-analysis/quality-rules/ca1843.md b/docs/fundamentals/code-analysis/quality-rules/ca1843.md index f12f3b00c98f2..5e1400b1111f5 100644 --- a/docs/fundamentals/code-analysis/quality-rules/ca1843.md +++ b/docs/fundamentals/code-analysis/quality-rules/ca1843.md @@ -25,7 +25,7 @@ author: Youssef1313 ## Rule description -Using 'WaitAll' with a single task may result in performance loss. +Using `WaitAll` with a single task may result in performance loss. ## How to fix violations diff --git a/docs/fundamentals/code-analysis/quality-rules/ca1848.md b/docs/fundamentals/code-analysis/quality-rules/ca1848.md index 03ebcff50b9f5..2747d46b70835 100644 --- a/docs/fundamentals/code-analysis/quality-rules/ca1848.md +++ b/docs/fundamentals/code-analysis/quality-rules/ca1848.md @@ -21,7 +21,7 @@ author: Youssef1313 ## Cause -[logger extension methods](xref:Microsoft.Extensions.Logging.LoggerExtensions), such as and . +Use of [logger extension methods](xref:Microsoft.Extensions.Logging.LoggerExtensions), such as and . ## Rule description @@ -33,7 +33,7 @@ Use `LoggerMessage` to fix violations of this rule. provides the following performance advantages over Logger extension methods: -- Logger extension methods require "boxing" (converting) value types, such as `int`, into `object`. The pattern avoids boxing by using static fields and extension methods with strongly-typed parameters. +- Logger extension methods require "boxing" (converting) value types, such as `int`, into `object`. The pattern avoids boxing by using static fields and extension methods with strongly typed parameters. - Logger extension methods must parse the message template (named format string) every time a log message is written. only requires parsing a template once when the message is defined. ## When to suppress warnings diff --git a/docs/fundamentals/code-analysis/quality-rules/ca2017.md b/docs/fundamentals/code-analysis/quality-rules/ca2017.md index 508f3dd15b2e9..923750e12d979 100644 --- a/docs/fundamentals/code-analysis/quality-rules/ca2017.md +++ b/docs/fundamentals/code-analysis/quality-rules/ca2017.md @@ -21,11 +21,11 @@ author: Youssef1313 ## Cause -Number of parameters supplied in the logging message template do not match the number of named placeholders. +The number of parameters supplied in the logging message template does not match the number of named placeholders. ## Rule description -This rule flags logger calls that has incorrect number of message arguments. +This rule flags logger calls that have an incorrect number of message arguments. ## How to fix violations diff --git a/docs/fundamentals/code-analysis/quality-rules/ca2254.md b/docs/fundamentals/code-analysis/quality-rules/ca2254.md index 4967e2eccab62..e93a3cfe47fc3 100644 --- a/docs/fundamentals/code-analysis/quality-rules/ca2254.md +++ b/docs/fundamentals/code-analysis/quality-rules/ca2254.md @@ -21,7 +21,7 @@ author: Youssef1313 ## Cause -A message template passed to logger API is not constant. +A message template passed to a logger API is not constant. ## Rule description diff --git a/docs/fundamentals/code-analysis/quality-rules/ca2257.md b/docs/fundamentals/code-analysis/quality-rules/ca2257.md index 84cfa95404d61..55e111fef47ae 100644 --- a/docs/fundamentals/code-analysis/quality-rules/ca2257.md +++ b/docs/fundamentals/code-analysis/quality-rules/ca2257.md @@ -1,6 +1,6 @@ --- -title: "CA2257: Members defined on an interface with the 'DynamicInterfaceCastableImplementationAttribute' should be 'static'" -description: "Learn about code analysis rule CA2257: Members defined on an interface with the 'DynamicInterfaceCastableImplementationAttribute' should be 'static'" +title: "CA2257: Members defined on an interface with 'DynamicInterfaceCastableImplementationAttribute' should be 'static'" +description: "Learn about code analysis rule CA2257: Members defined on an interface with 'DynamicInterfaceCastableImplementationAttribute' should be 'static'" ms.date: 01/19/2022 ms.topic: reference f1_keywords: @@ -21,15 +21,15 @@ author: Youssef1313 ## Cause -An interface member isn't explicitly implemented nor static. +An interface member isn't explicitly implemented or marked `static`. ## Rule description -Since a type that implements 'IDynamicInterfaceCastable' may not implement a dynamic interface in metadata, calls to an instance interface member that is not an explicit implementation defined on this type are likely to fail at runtime. Mark new interface members 'static' to avoid runtime errors. +Since a type that implements `IDynamicInterfaceCastable` may not implement a dynamic interface in metadata, calls to an instance interface member that is not an explicit implementation defined on this type are likely to fail at run time. To avoid run-time errors, mark new interface members `static`. ## How to fix violations -Make the interface member static. +Mark the interface member `static`. ## When to suppress errors diff --git a/docs/fundamentals/code-analysis/quality-rules/ca2258.md b/docs/fundamentals/code-analysis/quality-rules/ca2258.md index 16bb8af7feb3e..1c02d5ec582b1 100644 --- a/docs/fundamentals/code-analysis/quality-rules/ca2258.md +++ b/docs/fundamentals/code-analysis/quality-rules/ca2258.md @@ -25,7 +25,7 @@ Use of | [CA1839: Use Environment.ProcessPath instead of Process.GetCurrentProcess().MainModule.FileName](ca1837.md) | `Environment.ProcessPath` is simpler and faster than `Process.GetCurrentProcess().MainModule.FileName`. | > | [CA1840: Use Environment.CurrentManagedThreadId instead of Thread.CurrentThread.ManagedThreadId](ca1837.md) | `Environment.CurrentManagedThreadId` is more compact and efficient than `Thread.CurrentThread.ManagedThreadId`. | > | [CA1841: Prefer Dictionary Contains methods](ca1841.md) | Calling `Contains` on the `Keys` or `Values` collection may often be more expensive than calling `ContainsKey` or `ContainsValue` on the dictionary itself. | -> | [CA1842: Do not use 'WhenAll' with a single task](ca1842.md) | Using 'WhenAll' with a single task may result in performance loss, await or return the task instead. | -> | [CA1843: Do not use 'WaitAll' with a single task](ca1843.md) | Using 'WaitAll' with a single task may result in performance loss, await or return the task instead. | +> | [CA1842: Do not use 'WhenAll' with a single task](ca1842.md) | Using `WhenAll` with a single task may result in performance loss. Await or return the task instead. | +> | [CA1843: Do not use 'WaitAll' with a single task](ca1843.md) | Using `WaitAll` with a single task may result in performance loss. Await or return the task instead. | > | [CA1844: Provide memory-based overrides of async methods when subclassing 'Stream'](ca1844.md) | To improve performance, override the memory-based async methods when subclassing 'Stream'. Then implement the array-based methods in terms of the memory-based methods. | > | [CA1845: Use span-based 'string.Concat'](ca1845.md) | It is more efficient to use `AsSpan` and `string.Concat`, instead of `Substring` and a concatenation operator. | > | [CA1846: Prefer `AsSpan` over `Substring`](ca1846.md) | `AsSpan` is more efficient than `Substring`. `Substring` performs an O(n) string copy, while `AsSpan` does not and has a constant cost. `AsSpan` also does not perform any heap allocations. | @@ -199,7 +199,7 @@ The following table lists code quality analysis rules. > | [CA2254: Template should be a static expression](ca2254.md) | The logging message template should not vary between calls. | > | [CA2255: The `ModuleInitializer` attribute should not be used in libraries](ca2255.md) | Module initializers are intended to be used by application code to ensure an application's components are initialized before the application code begins executing. | > | [CA2256: All members declared in parent interfaces must have an implementation in a DynamicInterfaceCastableImplementation-attributed interface](ca2256.md) | Types attributed with 'DynamicInterfaceCastableImplementationAttribute' act as an interface implementation for a type that implements the 'IDynamicInterfaceCastable' type. As a result, it must provide an implementation of all of the members defined in the inherited interfaces, because the type that implements 'IDynamicInterfaceCastable' will not provide them otherwise. | -> | [CA2257: Members defined on an interface with the 'DynamicInterfaceCastableImplementationAttribute' should be 'static'](ca2257.md) | Since a type that implements 'IDynamicInterfaceCastable' may not implement a dynamic interface in metadata, calls to an instance interface member that is not an explicit implementation defined on this type are likely to fail at runtime. Mark new interface members 'static' to avoid runtime errors. | +> | [CA2257: Members defined on an interface with 'DynamicInterfaceCastableImplementationAttribute' should be 'static'](ca2257.md) | Since a type that implements `IDynamicInterfaceCastable` may not implement a dynamic interface in metadata, calls to an instance interface member that is not an explicit implementation defined on this type are likely to fail at run time. Mark new interface members `static` to avoid run-time errors. | > | [CA2258: Providing a 'DynamicInterfaceCastableImplementation' interface in Visual Basic is unsupported](ca2258.md) | Providing a functional 'DynamicInterfaceCastableImplementationAttribute'-attributed interface requires the Default Interface Members feature, which is unsupported in Visual Basic. | > | [CA2300: Do not use insecure deserializer BinaryFormatter](ca2300.md) | Insecure deserializers are vulnerable when deserializing untrusted data. An attacker could modify the serialized data to include unexpected types to inject objects with malicious side effects. | > | [CA2301: Do not call BinaryFormatter.Deserialize without first setting BinaryFormatter.Binder](ca2301.md) | Insecure deserializers are vulnerable when deserializing untrusted data. An attacker could modify the serialized data to include unexpected types to inject objects with malicious side effects. | diff --git a/docs/fundamentals/code-analysis/quality-rules/usage-warnings.md b/docs/fundamentals/code-analysis/quality-rules/usage-warnings.md index d11527faeda52..e12411a223120 100644 --- a/docs/fundamentals/code-analysis/quality-rules/usage-warnings.md +++ b/docs/fundamentals/code-analysis/quality-rules/usage-warnings.md @@ -59,5 +59,5 @@ Usage rules support proper usage of .NET. |[CA2254: Template should be a static expression](ca2254.md)|The logging message template should not vary between calls.| |[CA2255: The `ModuleInitializer` attribute should not be used in libraries](ca2255.md) | Module initializers are intended to be used by application code to ensure an application's components are initialized before the application code begins executing. | |[CA2256: All members declared in parent interfaces must have an implementation in a DynamicInterfaceCastableImplementation-attributed interface](ca2256.md) | Types attributed with 'DynamicInterfaceCastableImplementationAttribute' act as an interface implementation for a type that implements the 'IDynamicInterfaceCastable' type. As a result, it must provide an implementation of all of the members defined in the inherited interfaces, because the type that implements 'IDynamicInterfaceCastable' will not provide them otherwise. | -|[CA2257: Members defined on an interface with the 'DynamicInterfaceCastableImplementationAttribute' should be 'static'](ca2257.md) | Since a type that implements 'IDynamicInterfaceCastable' may not implement a dynamic interface in metadata, calls to an instance interface member that is not an explicit implementation defined on this type are likely to fail at runtime. Mark new interface members 'static' to avoid runtime errors. | +|[CA2257: Members defined on an interface with 'DynamicInterfaceCastableImplementationAttribute' should be 'static'](ca2257.md) | Since a type that implements 'IDynamicInterfaceCastable' may not implement a dynamic interface in metadata, calls to an instance interface member that is not an explicit implementation defined on this type are likely to fail at runtime. Mark new interface members 'static' to avoid runtime errors. | |[CA2258: Providing a 'DynamicInterfaceCastableImplementation' interface in Visual Basic is unsupported](ca2258.md) | Providing a functional 'DynamicInterfaceCastableImplementationAttribute'-attributed interface requires the Default Interface Members feature, which is unsupported in Visual Basic. | From 6ab0ef01a63b44f0986dd20b1e2ed33024709a6a Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Thu, 20 Jan 2022 11:40:42 +0200 Subject: [PATCH 15/18] Apply suggestions from code review --- docs/fundamentals/code-analysis/quality-rules/ca2256.md | 2 +- docs/fundamentals/code-analysis/quality-rules/index.md | 6 +++--- .../quality-rules/interoperability-warnings.md | 2 +- .../code-analysis/quality-rules/performance-warnings.md | 6 +++--- .../code-analysis/quality-rules/usage-warnings.md | 6 +++--- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/docs/fundamentals/code-analysis/quality-rules/ca2256.md b/docs/fundamentals/code-analysis/quality-rules/ca2256.md index 2bbb8217c33c5..0f3ed97c472d8 100644 --- a/docs/fundamentals/code-analysis/quality-rules/ca2256.md +++ b/docs/fundamentals/code-analysis/quality-rules/ca2256.md @@ -25,7 +25,7 @@ An interface with act as an interface implementation for a type that implements the 'IDynamicInterfaceCastable' type. As a result, it must provide an implementation of all of the members defined in the inherited interfaces, because the type that implements 'IDynamicInterfaceCastable' will not provide them otherwise. +Types attributed with act as an interface implementation for a type that implements the `IDynamicInterfaceCastable` type. As a result, it must provide an implementation of all of the members defined in the inherited interfaces, because the type that implements `IDynamicInterfaceCastable` will not provide them otherwise. ## How to fix violations diff --git a/docs/fundamentals/code-analysis/quality-rules/index.md b/docs/fundamentals/code-analysis/quality-rules/index.md index fdcc9b079dbcf..b03501cb2d306 100644 --- a/docs/fundamentals/code-analysis/quality-rules/index.md +++ b/docs/fundamentals/code-analysis/quality-rules/index.md @@ -78,7 +78,7 @@ The following table lists code quality analysis rules. > | [CA1416: Validate platform compatibility](ca1416.md) | Using platform-dependent APIs on a component makes the code no longer work across all platforms. | > | [CA1417: Do not use `OutAttribute` on string parameters for P/Invokes](ca1417.md) | String parameters passed by value with the `OutAttribute` can destabilize the runtime if the string is an interned string. | > | [CA1418: Use valid platform string](ca1418.md) | Platform compatibility analyzer requires a valid platform name and version. | -> | [CA1419: Provide a parameterless constructor that is as visible as the containing type for concrete types derived from 'System.Runtime.InteropServices.SafeHandle'](ca1419.md) | Providing a parameterless constructor that is as visible as the containing type for a type derived from 'System.Runtime.InteropServices.SafeHandle' enables better performance and usage with source-generated interop solutions. | +> | [CA1419: Provide a parameterless constructor that is as visible as the containing type for concrete types derived from 'System.Runtime.InteropServices.SafeHandle'](ca1419.md) | Providing a parameterless constructor that is as visible as the containing type for a type derived from `System.Runtime.InteropServices.SafeHandle` enables better performance and usage with source-generated interop solutions. | > | [CA1501: Avoid excessive inheritance](ca1501.md) | A type is more than four levels deep in its inheritance hierarchy. Deeply nested type hierarchies can be difficult to follow, understand, and maintain. | > | [CA1502: Avoid excessive complexity](ca1502.md) | This rule measures the number of linearly independent paths through the method, which is determined by the number and complexity of conditional branches. | > | [CA1505: Avoid unmaintainable code](ca1505.md) | A type or method has a low maintainability index value. A low maintainability index indicates that a type or method is probably difficult to maintain and would be a good candidate for redesign. | @@ -198,9 +198,9 @@ The following table lists code quality analysis rules. > | [CA2253: Named placeholders should not be numeric values](ca2253.md) | Named placeholders in the logging message template should not be comprised of only numeric characters. | > | [CA2254: Template should be a static expression](ca2254.md) | The logging message template should not vary between calls. | > | [CA2255: The `ModuleInitializer` attribute should not be used in libraries](ca2255.md) | Module initializers are intended to be used by application code to ensure an application's components are initialized before the application code begins executing. | -> | [CA2256: All members declared in parent interfaces must have an implementation in a DynamicInterfaceCastableImplementation-attributed interface](ca2256.md) | Types attributed with 'DynamicInterfaceCastableImplementationAttribute' act as an interface implementation for a type that implements the 'IDynamicInterfaceCastable' type. As a result, it must provide an implementation of all of the members defined in the inherited interfaces, because the type that implements 'IDynamicInterfaceCastable' will not provide them otherwise. | +> | [CA2256: All members declared in parent interfaces must have an implementation in a DynamicInterfaceCastableImplementation-attributed interface](ca2256.md) | Types attributed with `DynamicInterfaceCastableImplementationAttribute` act as an interface implementation for a type that implements the `IDynamicInterfaceCastable` type. As a result, it must provide an implementation of all of the members defined in the inherited interfaces, because the type that implements `IDynamicInterfaceCastable` will not provide them otherwise. | > | [CA2257: Members defined on an interface with 'DynamicInterfaceCastableImplementationAttribute' should be 'static'](ca2257.md) | Since a type that implements `IDynamicInterfaceCastable` may not implement a dynamic interface in metadata, calls to an instance interface member that is not an explicit implementation defined on this type are likely to fail at run time. Mark new interface members `static` to avoid run-time errors. | -> | [CA2258: Providing a 'DynamicInterfaceCastableImplementation' interface in Visual Basic is unsupported](ca2258.md) | Providing a functional 'DynamicInterfaceCastableImplementationAttribute'-attributed interface requires the Default Interface Members feature, which is unsupported in Visual Basic. | +> | [CA2258: Providing a 'DynamicInterfaceCastableImplementation' interface in Visual Basic is unsupported](ca2258.md) | Providing a functional `DynamicInterfaceCastableImplementationAttribute`-attributed interface requires the Default Interface Members feature, which is unsupported in Visual Basic. | > | [CA2300: Do not use insecure deserializer BinaryFormatter](ca2300.md) | Insecure deserializers are vulnerable when deserializing untrusted data. An attacker could modify the serialized data to include unexpected types to inject objects with malicious side effects. | > | [CA2301: Do not call BinaryFormatter.Deserialize without first setting BinaryFormatter.Binder](ca2301.md) | Insecure deserializers are vulnerable when deserializing untrusted data. An attacker could modify the serialized data to include unexpected types to inject objects with malicious side effects. | > | [CA2302: Ensure BinaryFormatter.Binder is set before calling BinaryFormatter.Deserialize](ca2302.md) | Insecure deserializers are vulnerable when deserializing untrusted data. An attacker could modify the serialized data to include unexpected types to inject objects with malicious side effects. | diff --git a/docs/fundamentals/code-analysis/quality-rules/interoperability-warnings.md b/docs/fundamentals/code-analysis/quality-rules/interoperability-warnings.md index 95d4edb5046e9..19c292db973e1 100644 --- a/docs/fundamentals/code-analysis/quality-rules/interoperability-warnings.md +++ b/docs/fundamentals/code-analysis/quality-rules/interoperability-warnings.md @@ -27,4 +27,4 @@ Portability rules support portability across different platforms. Interoperabili | [CA1416: Validate platform compatibility](ca1416.md) | Using platform-dependent APIs on a component makes the code no longer work across all platforms. | | [CA1417: Do not use `OutAttribute` on string parameters for P/Invokes](ca1417.md) | String parameters passed by value with the `OutAttribute` can destabilize the runtime if the string is an interned string. | | [CA1418: Use valid platform string](ca1418.md) | Platform compatibility analyzer requires a valid platform name and version. | -| [CA1419: Provide a parameterless constructor that is as visible as the containing type for concrete types derived from 'System.Runtime.InteropServices.SafeHandle'](ca1419.md) | Providing a parameterless constructor that is as visible as the containing type for a type derived from 'System.Runtime.InteropServices.SafeHandle' enables better performance and usage with source-generated interop solutions. | +| [CA1419: Provide a parameterless constructor that is as visible as the containing type for concrete types derived from 'System.Runtime.InteropServices.SafeHandle'](ca1419.md) | Providing a parameterless constructor that is as visible as the containing type for a type derived from `System.Runtime.InteropServices.SafeHandle` enables better performance and usage with source-generated interop solutions. | diff --git a/docs/fundamentals/code-analysis/quality-rules/performance-warnings.md b/docs/fundamentals/code-analysis/quality-rules/performance-warnings.md index ba0df0cc1849c..f964a9aaffd65 100644 --- a/docs/fundamentals/code-analysis/quality-rules/performance-warnings.md +++ b/docs/fundamentals/code-analysis/quality-rules/performance-warnings.md @@ -52,12 +52,12 @@ Performance rules support high-performance libraries and applications. | [CA1839: Use Environment.ProcessPath instead of Process.GetCurrentProcess().MainModule.FileName](ca1837.md) | `Environment.ProcessPath` is simpler and faster than `Process.GetCurrentProcess().MainModule.FileName`. | | [CA1840: Use Environment.CurrentManagedThreadId instead of Thread.CurrentThread.ManagedThreadId](ca1837.md) | `Environment.CurrentManagedThreadId` is more compact and efficient than `Thread.CurrentThread.ManagedThreadId`. | | [CA1841: Prefer Dictionary Contains methods](ca1841.md) | Calling `Contains` on the `Keys` or `Values` collection may often be more expensive than calling `ContainsKey` or `ContainsValue` on the dictionary itself. | -| [CA1842: Do not use 'WhenAll' with a single task](ca1842.md) | Using 'WhenAll' with a single task may result in performance loss, await or return the task instead. | -| [CA1843: Do not use 'WaitAll' with a single task](ca1843.md) | Using 'WaitAll' with a single task may result in performance loss, await or return the task instead. | +| [CA1842: Do not use 'WhenAll' with a single task](ca1842.md) | Using `WhenAll` with a single task may result in performance loss, await or return the task instead. | +| [CA1843: Do not use 'WaitAll' with a single task](ca1843.md) | Using `WaitAll` with a single task may result in performance loss, await or return the task instead. | | [CA1844: Provide memory-based overrides of async methods when subclassing 'Stream'](ca1844.md) | To improve performance, override the memory-based async methods when subclassing 'Stream'. Then implement the array-based methods in terms of the memory-based methods. | | [CA1845: Use span-based 'string.Concat'](ca1845.md) | It is more efficient to use `AsSpan` and `string.Concat`, instead of `Substring` and a concatenation operator. | | [CA1846: Prefer `AsSpan` over `Substring`](ca1846.md) | `AsSpan` is more efficient than `Substring`. `Substring` performs an O(n) string copy, while `AsSpan` does not and has a constant cost. `AsSpan` also does not perform any heap allocations. | | [CA1847: Use char literal for a single character lookup](ca1847.md) | Use `string.Contains(char)` instead of `string.Contains(string)` when searching for a single character. | -| [CA1848: Use the LoggerMessage delegates](ca1848.md) | For improved performance, use the LoggerMessage delegates. | +| [CA1848: Use the LoggerMessage delegates](ca1848.md) | For improved performance, use the `LoggerMessage` delegates. | | [CA1849: Call async methods when in an async method](ca1849.md) | In a method which is already asynchronous, calls to other methods should be to their async versions, where they exist. | | [CA1850: Prefer static `HashData` method over `ComputeHash`](ca1850.md) | It's more efficient to use the static `HashData` method over creating and managing a `HashAlgorithm` instance to call `ComputeHash`. | diff --git a/docs/fundamentals/code-analysis/quality-rules/usage-warnings.md b/docs/fundamentals/code-analysis/quality-rules/usage-warnings.md index e12411a223120..1ad8c53163b79 100644 --- a/docs/fundamentals/code-analysis/quality-rules/usage-warnings.md +++ b/docs/fundamentals/code-analysis/quality-rules/usage-warnings.md @@ -58,6 +58,6 @@ Usage rules support proper usage of .NET. |[CA2253: Named placeholders should not be numeric values](ca2253.md)|Named placeholders in the logging message template should not be comprised of only numeric characters.| |[CA2254: Template should be a static expression](ca2254.md)|The logging message template should not vary between calls.| |[CA2255: The `ModuleInitializer` attribute should not be used in libraries](ca2255.md) | Module initializers are intended to be used by application code to ensure an application's components are initialized before the application code begins executing. | -|[CA2256: All members declared in parent interfaces must have an implementation in a DynamicInterfaceCastableImplementation-attributed interface](ca2256.md) | Types attributed with 'DynamicInterfaceCastableImplementationAttribute' act as an interface implementation for a type that implements the 'IDynamicInterfaceCastable' type. As a result, it must provide an implementation of all of the members defined in the inherited interfaces, because the type that implements 'IDynamicInterfaceCastable' will not provide them otherwise. | -|[CA2257: Members defined on an interface with 'DynamicInterfaceCastableImplementationAttribute' should be 'static'](ca2257.md) | Since a type that implements 'IDynamicInterfaceCastable' may not implement a dynamic interface in metadata, calls to an instance interface member that is not an explicit implementation defined on this type are likely to fail at runtime. Mark new interface members 'static' to avoid runtime errors. | -|[CA2258: Providing a 'DynamicInterfaceCastableImplementation' interface in Visual Basic is unsupported](ca2258.md) | Providing a functional 'DynamicInterfaceCastableImplementationAttribute'-attributed interface requires the Default Interface Members feature, which is unsupported in Visual Basic. | +|[CA2256: All members declared in parent interfaces must have an implementation in a DynamicInterfaceCastableImplementation-attributed interface](ca2256.md) | Types attributed with `DynamicInterfaceCastableImplementationAttribute` act as an interface implementation for a type that implements the `IDynamicInterfaceCastable` type. As a result, it must provide an implementation of all of the members defined in the inherited interfaces, because the type that implements `IDynamicInterfaceCastable` will not provide them otherwise. | +|[CA2257: Members defined on an interface with 'DynamicInterfaceCastableImplementationAttribute' should be 'static'](ca2257.md) | Since a type that implements `IDynamicInterfaceCastable` may not implement a dynamic interface in metadata, calls to an instance interface member that is not an explicit implementation defined on this type are likely to fail at runtime. Mark new interface members `static` to avoid runtime errors. | +|[CA2258: Providing a 'DynamicInterfaceCastableImplementation' interface in Visual Basic is unsupported](ca2258.md) | Providing a functional `DynamicInterfaceCastableImplementationAttribute`-attributed interface requires the Default Interface Members feature, which is unsupported in Visual Basic. | From 0110d826ca0e2bd7d07716f46f7a13c56ed21cb3 Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Thu, 20 Jan 2022 11:42:16 +0200 Subject: [PATCH 16/18] Apply suggestions from code review --- .../code-analysis/quality-rules/performance-warnings.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/fundamentals/code-analysis/quality-rules/performance-warnings.md b/docs/fundamentals/code-analysis/quality-rules/performance-warnings.md index f964a9aaffd65..c3c4b0542350b 100644 --- a/docs/fundamentals/code-analysis/quality-rules/performance-warnings.md +++ b/docs/fundamentals/code-analysis/quality-rules/performance-warnings.md @@ -52,8 +52,8 @@ Performance rules support high-performance libraries and applications. | [CA1839: Use Environment.ProcessPath instead of Process.GetCurrentProcess().MainModule.FileName](ca1837.md) | `Environment.ProcessPath` is simpler and faster than `Process.GetCurrentProcess().MainModule.FileName`. | | [CA1840: Use Environment.CurrentManagedThreadId instead of Thread.CurrentThread.ManagedThreadId](ca1837.md) | `Environment.CurrentManagedThreadId` is more compact and efficient than `Thread.CurrentThread.ManagedThreadId`. | | [CA1841: Prefer Dictionary Contains methods](ca1841.md) | Calling `Contains` on the `Keys` or `Values` collection may often be more expensive than calling `ContainsKey` or `ContainsValue` on the dictionary itself. | -| [CA1842: Do not use 'WhenAll' with a single task](ca1842.md) | Using `WhenAll` with a single task may result in performance loss, await or return the task instead. | -| [CA1843: Do not use 'WaitAll' with a single task](ca1843.md) | Using `WaitAll` with a single task may result in performance loss, await or return the task instead. | +| [CA1842: Do not use 'WhenAll' with a single task](ca1842.md) | Using `WhenAll` with a single task may result in performance loss. Await or return the task instead. | +| [CA1843: Do not use 'WaitAll' with a single task](ca1843.md) | Using `WaitAll` with a single task may result in performance loss. Await or return the task instead. | | [CA1844: Provide memory-based overrides of async methods when subclassing 'Stream'](ca1844.md) | To improve performance, override the memory-based async methods when subclassing 'Stream'. Then implement the array-based methods in terms of the memory-based methods. | | [CA1845: Use span-based 'string.Concat'](ca1845.md) | It is more efficient to use `AsSpan` and `string.Concat`, instead of `Substring` and a concatenation operator. | | [CA1846: Prefer `AsSpan` over `Substring`](ca1846.md) | `AsSpan` is more efficient than `Substring`. `Substring` performs an O(n) string copy, while `AsSpan` does not and has a constant cost. `AsSpan` also does not perform any heap allocations. | From 885a1d6287f89d64a0b082f8f38b4ae61fc975ee Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Thu, 20 Jan 2022 11:42:55 +0200 Subject: [PATCH 17/18] Apply suggestions from code review --- docs/fundamentals/code-analysis/quality-rules/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/fundamentals/code-analysis/quality-rules/index.md b/docs/fundamentals/code-analysis/quality-rules/index.md index b03501cb2d306..082858d2a265a 100644 --- a/docs/fundamentals/code-analysis/quality-rules/index.md +++ b/docs/fundamentals/code-analysis/quality-rules/index.md @@ -141,7 +141,7 @@ The following table lists code quality analysis rules. > | [CA1845: Use span-based 'string.Concat'](ca1845.md) | It is more efficient to use `AsSpan` and `string.Concat`, instead of `Substring` and a concatenation operator. | > | [CA1846: Prefer `AsSpan` over `Substring`](ca1846.md) | `AsSpan` is more efficient than `Substring`. `Substring` performs an O(n) string copy, while `AsSpan` does not and has a constant cost. `AsSpan` also does not perform any heap allocations. | > | [CA1847: Use char literal for a single character lookup](ca1847.md) | Use `string.Contains(char)` instead of `string.Contains(string)` when searching for a single character. | -> | [CA1848: Use the LoggerMessage delegates](ca1848.md) | For improved performance, use the LoggerMessage delegates. | +> | [CA1848: Use the LoggerMessage delegates](ca1848.md) | For improved performance, use the `LoggerMessage` delegates. | > | [CA1849: Call async methods when in an async method](ca1849.md) | In a method which is already asynchronous, calls to other methods should be to their async versions, where they exist. | > | [CA1850: Prefer static `HashData` method over `ComputeHash`](ca1850.md) | It's more efficient to use the static `HashData` method over creating and managing a `HashAlgorithm` instance to call `ComputeHash`. | > | [CA2000: Dispose objects before losing scope](ca2000.md) | Because an exceptional event might occur that will prevent the finalizer of an object from running, the object should be explicitly disposed before all references to it are out of scope. | From a3785e36d3160c4e637f9135d7eeb51a0a598e03 Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Thu, 20 Jan 2022 11:46:51 +0200 Subject: [PATCH 18/18] Apply suggestions from code review --- docs/fundamentals/code-analysis/quality-rules/usage-warnings.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/fundamentals/code-analysis/quality-rules/usage-warnings.md b/docs/fundamentals/code-analysis/quality-rules/usage-warnings.md index 1ad8c53163b79..e2c39f3fb1848 100644 --- a/docs/fundamentals/code-analysis/quality-rules/usage-warnings.md +++ b/docs/fundamentals/code-analysis/quality-rules/usage-warnings.md @@ -59,5 +59,5 @@ Usage rules support proper usage of .NET. |[CA2254: Template should be a static expression](ca2254.md)|The logging message template should not vary between calls.| |[CA2255: The `ModuleInitializer` attribute should not be used in libraries](ca2255.md) | Module initializers are intended to be used by application code to ensure an application's components are initialized before the application code begins executing. | |[CA2256: All members declared in parent interfaces must have an implementation in a DynamicInterfaceCastableImplementation-attributed interface](ca2256.md) | Types attributed with `DynamicInterfaceCastableImplementationAttribute` act as an interface implementation for a type that implements the `IDynamicInterfaceCastable` type. As a result, it must provide an implementation of all of the members defined in the inherited interfaces, because the type that implements `IDynamicInterfaceCastable` will not provide them otherwise. | -|[CA2257: Members defined on an interface with 'DynamicInterfaceCastableImplementationAttribute' should be 'static'](ca2257.md) | Since a type that implements `IDynamicInterfaceCastable` may not implement a dynamic interface in metadata, calls to an instance interface member that is not an explicit implementation defined on this type are likely to fail at runtime. Mark new interface members `static` to avoid runtime errors. | +|[CA2257: Members defined on an interface with 'DynamicInterfaceCastableImplementationAttribute' should be 'static'](ca2257.md) | Since a type that implements `IDynamicInterfaceCastable` may not implement a dynamic interface in metadata, calls to an instance interface member that is not an explicit implementation defined on this type are likely to fail at run time. Mark new interface members `static` to avoid run-time errors. | |[CA2258: Providing a 'DynamicInterfaceCastableImplementation' interface in Visual Basic is unsupported](ca2258.md) | Providing a functional `DynamicInterfaceCastableImplementationAttribute`-attributed interface requires the Default Interface Members feature, which is unsupported in Visual Basic. |