Repeated string literal (ARCH715)
Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.
Key dotnet.codequality.repeated-string-literal · Severity info · Category codequality
Flags a string literal of five or more characters used four or more times in one type. A value spelled out in several places drifts: one copy gets changed and the others do not. Attribute arguments, case labels, patterns, constant initialisers, log calls and seed data are not counted.
Incorrect
Section titled “Incorrect”if (status == "awaiting-payment") ...return "awaiting-payment";log.Info("awaiting-payment");filter.Add("awaiting-payment");Correct
Section titled “Correct”private const string AwaitingPayment = "awaiting-payment";
if (status == AwaitingPayment) ...return AwaitingPayment;