Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify rule S4545: Add VB.NET specifics, Move C# specifics #1571

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 34 additions & 1 deletion 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[]

Expand Down
2 changes: 1 addition & 1 deletion rules/S4545/highlighting.adoc
@@ -1,4 +1,4 @@
=== Highlighting

text between curly braces
format string parameter of the `DebuggerDisplayAttribute`

2 changes: 1 addition & 1 deletion 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
mary-georgiou-sonarsource marked this conversation as resolved.
Show resolved Hide resolved

35 changes: 0 additions & 35 deletions rules/S4545/rule.adoc

This file was deleted.

37 changes: 36 additions & 1 deletion 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]
----
<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
----

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

Expand Down