How to handle singleton naming?

Hi,

I have this pattern that I usually use for singletons:

        static private readonly Bootstrap instance = new Bootstrap();
        static public Bootstrap Instance
        {
            get
            {
                return instance;
            }
        }



Resharper wants to rename the "instance" variable to "Instance" which obviously is going to have a problem as that's what the property is called.

What is the recommended way of achieving this pattern?

Matt.
4 comments

Well you could change the pattern for private static members...
Go to Resharper -> Options for the options dialog, locate in the left tree Languages -> Common -> Naming Style and on the right side in the list Static field (private) and double click on it.
Then change it the way your naming style is.

0

Hi,

I figured I could possibly change the profile however given the Singleton is a standard pattern that most people use I wondered what the standard conventions were regarding it that were covered by Resharper - or is it that it doesn't really cover this and I *will* need to adjust the config? (no problem if that's the case, i'm just trying to use ReSharper to sharpen my code, not potentially dumb it down to my level :) ).

Thanks

Matt.

0

I don't know what namingstyle the default Resharper Settings are following.
The question is do you have already some naming guideline in your company?

When we defined ours we took the microsoft rules as base and then adjusted it a little bit.

For me private static members in UperCamelCase would be in conflict with Property names (especially in Singleton scenario) and so it may be some good idea to name then in lowerCamelCase.
To distinguish class members with object member you could use some prefix (wich is against microsofts naming style but makes some thing perhaps a little bit less confuse)

So yes, I would change the Resharper settings at this point and see how it works.

Here is a link describing microsofts internal guidelines
http://blogs.msdn.com/b/brada/archive/2005/01/26/361363.aspx

I guess if you use StyleCop you will also see some rules regarding naming style.

Here are some other sites with some naming guideline topics
http://weblogs.asp.net/scottdockendorf/archive/2005/01/26/361020.aspx
http://10rem.net/articles/net-naming-conventions-and-programming-standards---best-practices

0

Many thanks, that's good enough for me :)

Matt.

0

Please sign in to leave a comment.