Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enforcing using the class name whenever a shared member is accessed

We have a coding standard that says all shared (static) fields and methods must be called with the class name. E.g.

NameOfClass.whatever

Rather then

whatever  

Is there a tool that we can use to check this is in fact the case? (Likewise for modules)

Sorry I should have make it clearer we are using VB.NET.


This is a bigger example of what I mean.

Public Class Class1
    Public Shared Sub SharedMethod()

    End Sub

    Public Shared sharedField As Integer

    Public Sub NotSharedMethod()
        'this next line shold be written as Class1.SharedMethod
        SharedMethod()

        'this next line shold be written as Class1.sharedField
        sharedField = 5
    End Sub

End Class

see also What StyleCop like tools are there for VB.NET

like image 434
Ian Ringrose Avatar asked Dec 04 '25 10:12

Ian Ringrose


1 Answers

Yes,

Use StyleCop and write your custom rule to do your check.

Here's a reference to check how to write custom-rule for StyleCop.

alt text

like image 186
this. __curious_geek Avatar answered Dec 08 '25 14:12

this. __curious_geek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!