use-string-empty
What it does
Section titled “What it does”Reports "" (or @"") where string.Empty can be used. It is not reported where a constant is required: const, attribute arguments, default parameter values, case labels and patterns.
Why it matters
Section titled “Why it matters”string.Empty states that the string is empty on purpose, while "" can be a value that was forgotten. It is a convention that some projects choose and others do not.
To fix, write string.Empty.
Example
Section titled “Example”... string F(string s = "") {... switch (s) { case "": break; } return s ?? @""; } [System.Obsolete("")] void G() { }}... string F(string s = "") {... switch (s) { case "": break; } return s ?? string.Empty; } [System.Obsolete("")] void G() { }}Configuration
Section titled “Configuration”csharp: lint: rules: use-string-empty: warn # off (default), warn, errorEnabled by the presets: csharp/stylecop.
Suppress one line with sudsy-disable-next-line use-string-empty in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.
| Tool | Rule | Match | What differs |
|---|---|---|---|
| StyleCop | SA1122 |
partial | Only the string.Empty direction; no option for the opposite style (RCS1078) because no preset needs it |