Overview

Classes in the System.Diagnostics.CodeAnalysis namespace are used to analyze code for conformance to coding conventions.

ClassDescription
AllowNullAttributeSpecifies that null is allowed as an input even if the corresponding type disallows it.
ConstantExpectedAttributeIndicates that the specified method parameter expects a constant.
DisallowNullAttributeSpecifies that null is disallowed as an input even if the corresponding type allows it.
DoesNotReturnAttributeSpecifies that a method that will never return under any circumstance.
DoesNotReturnIfAttributeSpecifies that the method will not return if the associated Boolean parameter is passed the specified value.
DynamicallyAccessedMembersAttributeIndicates that certain members on a specified Type are accessed dynamically, for example, through System.Reflection.
DynamicDependencyAttributeStates a dependency that one member has on another.
ExcludeFromCodeCoverageAttributeSpecifies that the attributed code should be excluded from code coverage information.
MaybeNullAttributeSpecifies that an output may be null even if the corresponding type disallows it.
MaybeNullWhenAttributeSpecifies that when a method returns ReturnValue, the parameter may be null even if the corresponding type disallows it.
MemberNotNullAttributeSpecifies that the method or property will ensure that the listed field and property members have values that aren’t null.
MemberNotNullWhenAttributeSpecifies that the method or property will ensure that the listed field and property members have non-null values when returning with the specified return value condition.
NotNullAttributeSpecifies that an output is not null even if the corresponding type allows it. Specifies that an input argument was not null when the call returns.
NotNullIfNotNullAttributeSpecifies that the output will be non-null if the named parameter is non-null.
NotNullWhenAttributeSpecifies that when a method returns ReturnValue, the parameter will not be null even if the corresponding type allows it.
RequiresAssemblyFilesAttributeIndicates that the specified member requires assembly files to be on disk.
RequiresDynamicCodeAttributeIndicates that the specified method requires the ability to generate new code at runtime, for example through System.Reflection.
RequiresUnreferencedCodeAttributeIndicates that the specified method requires dynamic access to code that is not referenced statically, for example, through System.Reflection.
SetsRequiredMembersAttributeSpecifies that this constructor sets all required members for the current type, and callers do not need to set any required members themselves.
StringSyntaxAttributeSpecifies the syntax used in a string.
SuppressMessageAttributeSuppresses reporting of a specific code analysis rule violation, allowing multiple suppressions on a single code artifact. Does not apply to compiler diagnostics.
UnconditionalSuppressMessageAttributeSuppresses reporting of a specific rule violation, allowing multiple suppressions on a single code artifact.
UnscopedRefAttributeUsed to indicate a byref escapes and is not scoped

StringSyntaxAttribute

Attribute to indicate what kind of syntax is expected in a string.

For example, you can specify that a string parameter expects a regular expression by attributing the parameter with [StringSyntax(StringSyntaxAttribute.Regex)].