Skip to content

Commit

Permalink
Modify rule S4545: Add VB.NET specifics, Move C# specifics
Browse files Browse the repository at this point in the history
  • Loading branch information
antonioaversa committed Feb 13, 2023
1 parent 8a5ec88 commit 0c34ec6
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 28 deletions.
35 changes: 35 additions & 0 deletions rules/S4545/csharp/rule-except-see.adoc
@@ -0,0 +1,35 @@
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; }
}
----

2 changes: 1 addition & 1 deletion rules/S4545/csharp/rule.adoc
@@ -1,4 +1,4 @@
include::../rule.adoc[]
include::rule-except-see.adoc[]

ifdef::env-github,rspecator-view[]

Expand Down
27 changes: 1 addition & 26 deletions rules/S4545/rule.adoc
Expand Up @@ -4,32 +4,7 @@ The ``++DebuggerDisplayAttribute++`` is used to determine how an object is displ
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.
Naming a non-existent field, property or method between curly braces will result in an 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; }
}
----

37 changes: 37 additions & 0 deletions rules/S4545/vbnet/rule-except-see.adoc
@@ -0,0 +1,37 @@
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 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]
----
<DebuggerDisplay("Name: {Name}")> ' Noncompliant - Name doesn't exist in this context
Public Class Person
Public Property FullName As String
End Class
----


== Compliant Solution

[source,vbnet]
----
<DebuggerDisplay("Name: {FullName}")>
Public Class Person
Public Property FullName As String
End Class
----

2 changes: 1 addition & 1 deletion rules/S4545/vbnet/rule.adoc
@@ -1,4 +1,4 @@
include::../rule.adoc[]
include::rule-except-see.adoc[]

ifdef::env-github,rspecator-view[]

Expand Down

0 comments on commit 0c34ec6

Please sign in to comment.