Movatterモバイル変換


[0]ホーム

URL:


Skip to main content

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Download Microsoft EdgeMore info about Internet Explorer and Microsoft Edge
Table of contentsExit focus mode

CA1200: Avoid using cref tags with a prefix

  • 2023-04-22
Feedback

In this article

PropertyValue
Rule IDCA1200
TitleAvoid using cref tags with a prefix
CategoryDocumentation
Fix is breaking or non-breakingNon-breaking
Enabled by default in .NET 9No

Cause

Thecref tag in an XML documentation comment uses aprefix.

Rule description

Thecref attribute in an XML documentation tag means "code reference". It specifies that the inner text of the tag is a code element, such as a type, method, or property. Avoid usingcref tags with prefixes, because it prevents the compiler from verifying references. It also prevents the Visual Studio integrated development environment (IDE) from finding and updating these symbol references during refactorings. It is recommended that you use the full syntax without prefixes to reference symbol names in cref tags.

How to fix violations

To fix a violation of this rule, remove the prefix from thecref tag. For example, the following two code snippets show a violation of the rule and how to fix it:

// Violates CA1200/// <summary>/// Type <see cref="T:C" /> contains method <see cref="F:C.F" />/// </summary>class C{    public void F() { }}
// Does not violate CA1200/// <summary>/// Type <see cref="C" /> contains method <see cref="F" />/// </summary>class C{    public void F() { }}

When to suppress warnings

It's safe to suppress this warning if the code reference must use a prefix because the referenced type is not findable by the compiler. For example, if a code reference references a special attribute in the full framework, but the file compiles against the portable framework, you can suppress this warning.

Suppress a warning

If you just want to suppress a single violation, add preprocessor directives to your source file to disable and then re-enable the rule.

#pragma warning disable CA1200// The code that's violating the rule is on this line.#pragma warning restore CA1200

To disable the rule for a file, folder, or project, set its severity tonone in theconfiguration file.

[*.{cs,vb}]dotnet_diagnostic.CA1200.severity = none

For more information, seeHow to suppress code analysis warnings.

See also

Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, seeour contributor guide.

Feedback

Was this page helpful?

YesNo

In this article

Was this page helpful?

YesNo