Use of Bang Notation

Identifies the use of bang notation, formally known as dictionary access expression.

Reasoning

A dictionary access expression looks like a strongly typed call, but it actually is a stringly typed access to the parameterized default member of the object.

Default severity

Warning

Inspection type

CodeQualityIssues

Examples

This example should trigger a result

MyModule (StandardModule)
Public Sub DoSomething(ByVal wkb As Excel.Workbook) wkb.Worksheets!MySheet.Range("A1").Value = 42 End Sub

This example should trigger a result

MyModule (StandardModule)
Public Sub DoSomething(ByVal wkb As Excel.Workbook) With wkb.Worksheets !MySheet.Range("A1").Value = 42 End With End Sub

This example should NOT trigger a result

MyModule (StandardModule)
Public Sub DoSomething(ByVal wkb As Excel.Workbook) wkb.Worksheets("MySheet").Range("A1").Value = 42 End Sub

This example should NOT trigger a result

MyModule (StandardModule)
Public Sub DoSomething(ByVal wkb As Excel.Workbook) wkb.Worksheets.Item("MySheet").Range("A1").Value = 42 End Sub

This example should NOT trigger a result

MyModule (StandardModule)
Public Sub DoSomething(ByVal wkb As Excel.Workbook) With wkb.Worksheets .Item("MySheet").Range("A1").Value = 42 End With End Sub

Rubberduck.CodeAnalysis.Inspections.Concrete.UseOfBangNotationInspection.cs (Prerelease-v2.5.9.6289)