diff --git a/rules/S4545/csharp/rule.adoc b/rules/S4545/csharp/rule.adoc index f5db9e87ac5..a5fabcdc209 100644 --- a/rules/S4545/csharp/rule.adoc +++ b/rules/S4545/csharp/rule.adoc @@ -1,4 +1,37 @@ -include::../rule.adoc[] +The `DebuggerDisplayAttribute` is used to determine how an object is displayed in the debugger window. + + +The `DebuggerDisplayAttribute` constructor takes a single mandatory argument: the string to be displayed in the value column for instances of the type. Any text within curly braces is evaluated as the name of a field or property, or any complex expression containing method calls and operators. + + +Naming a non-existent member between curly braces will result in a CS0103 error in the debug window when debugging objects. Although there is no impact on the production code, providing a wrong value can lead to difficulties when debugging the application. + + +This rule raises an issue when text specified between curly braces refers to members that don't exist in the current context. + + +== Noncompliant Code Example + +[source,text] +---- +[DebuggerDisplay("Name: {Name}")] // Noncompliant - Name doesn't exist in this context +public class Person +{ + public string FullName { get; private set; } +} +---- + + +== Compliant Solution + +[source,text] +---- +[DebuggerDisplay("Name: {FullName}")] +public class Person +{ + public string FullName { get; private set; } +} +---- ifdef::env-github,rspecator-view[] diff --git a/rules/S4545/highlighting.adoc b/rules/S4545/highlighting.adoc index 4eb62825db9..2ef73ed3b18 100644 --- a/rules/S4545/highlighting.adoc +++ b/rules/S4545/highlighting.adoc @@ -1,4 +1,4 @@ === Highlighting -text between curly braces +format string parameter of the `DebuggerDisplayAttribute` diff --git a/rules/S4545/message.adoc b/rules/S4545/message.adoc index 38d16d65e3b..6a8fa140f1f 100644 --- a/rules/S4545/message.adoc +++ b/rules/S4545/message.adoc @@ -1,4 +1,4 @@ === Message -Fix the name between the curly braces so that it matches a field, property or method of this object +Fix the name between the curly braces so that it matches a field or property of this object diff --git a/rules/S4545/rule.adoc b/rules/S4545/rule.adoc deleted file mode 100644 index 8b317ca2b8b..00000000000 --- a/rules/S4545/rule.adoc +++ /dev/null @@ -1,35 +0,0 @@ -The ``++DebuggerDisplayAttribute++`` is used to determine how an object is displayed in the debugger window. - - -The ``++DebuggerDisplayAttribute++`` constructor takes a single argument: the string to be displayed in the value column for instances of the type. Any text within curly braces is evaluated as the name of a field, property, or method. - - -Naming a non-existent field, property or method between curly braces will result in a CS0103 error in the debug window when debugging objects. Although there is no impact on the production code, providing a wrong value can lead to difficulties when debugging the application. - - -This rule raises an issue when text specified between curly braces refers to members that don't exist in the current context. - - -== Noncompliant Code Example - -[source,text] ----- -[DebuggerDisplay("Name: {Name}")] // Noncompliant - Name doesn't exist in this context -public class Person -{ - public string FullName { get; private set; } -} ----- - - -== Compliant Solution - -[source,text] ----- -[DebuggerDisplay("Name: {FullName}")] -public class Person -{ - public string FullName { get; private set; } -} ----- - diff --git a/rules/S4545/vbnet/rule.adoc b/rules/S4545/vbnet/rule.adoc index f5db9e87ac5..e8a46f4b2d9 100644 --- a/rules/S4545/vbnet/rule.adoc +++ b/rules/S4545/vbnet/rule.adoc @@ -1,4 +1,39 @@ -include::../rule.adoc[] +The `DebuggerDisplayAttribute` is used to determine how an object is displayed in the debugger window. + + +The `DebuggerDisplayAttribute` constructor takes a single mandatory argument: the string to be displayed in the value column for instances of the type. Any text within curly braces is evaluated as the name of a field or property, or any complex expression containing method calls and operators. + + +Naming a non-existent member between curly braces will result in a BC30451 error in the debug window when debugging objects. Although there is no impact on the production code, providing a wrong value can lead to difficulties when debugging the application. + + +This rule raises an issue when text specified between curly braces refers to members that don't exist in the current context. + + +== Noncompliant Code Example + +[source,vbnet] +---- + ' Noncompliant - Name doesn't exist in this context +Public Class Person + + Public Property FullName As String + +End Class +---- + + +== Compliant Solution + +[source,vbnet] +---- + +Public Class Person + + Public Property FullName As String + +End Class +---- ifdef::env-github,rspecator-view[]