/Community

A Support Community for SubMain Products
in Search
Welcome to SubMain Community Sign in | Join | Help

Control Naming - Hungarian 2

Last post 07-08-2008, 12:55 AM by Serge B.. 1 replies.
Sort Posts: Previous Next
  •  06-24-2008, 6:48 PM 572

    Control Naming - Hungarian 2

    Hi,

    I have two custom rules as below:

    1. Ensure all private field use underscore as prefix.
    2. Ensure UI control use corresponding prefix, for example txt for textbox, cbo for combobox, chk for checkbox and etc.

    I was having test as below with "Exclude *.designer files" OFF:

    1. I dropped some UI controls on form and run CIR to analysis.
    2. CIR complaint my UI controls declaration in *.designer file not using underscore as prefix (since UI controls are declared as private by default)

    I don't really want my UI control name to use under prefix. Instead, I want them to follow prefix as mentioned in 2nd custom rule.

    Shall we have "Exclude *.designer files" OFF" tight to rule level instead of only global?
    As you can see the above scenario, I want rule 1 to apply to all code file except *.designer.

    On the other hand, I want rule 2 to apply to *.designer file as well.

     Please advice. Thank you

  •  07-08-2008, 12:55 AM 583 in reply to 572

    Re: Control Naming - Hungarian 2

    Attachment: CustomRules1.zip

    There are currently few ways of doing this (although neither is perfect):

    • Create multiple profiles and switch between them

    • Add [System.Diagnostics.CodeAnalysis.SuppressMessage("SubMain.CodeItRight.Rules.Naming", "NA00016:UseOrAvoidCertainPrefixes")] attribute in fron of each of the control declarations in the form - this will tell CIR to ignore the rule that that forces the underscores to controls.

    • Custom Rule. I'm attaching excample that will add underscores to private fields that are not controls and "txt" TextBox controls. The example is just plain hardcoded but should give you idea.

     


    Thank you,
    Serge Baranovsky
    http://submain.com - .NET Developer Tools  |  Microsoft VB MVP  |  http://vbcity.com - VB Developer Community
    » » (Static Code Analysis + Automatic Refactoring) / Painless Coding Guidelines = CodeIt.Right - http://submain.com/codeit.right
    » » C#/VB .NET Coding Guidelines - FREE 100+ page ebook (PDF) http://submain.com/guidelines
View as RSS news feed in XML