Design patters are a point of arguments between developers, but I use them very often.开发者_开发百科 Even more, I use one of the most controversial of all common patterns - singleton.
Here is how I implement it in C#:
class MySingletonClass
{
private static volatile MySingletonClass _instance;
private static object syncRoot = new Object();
public static MySingletonClass Instance
{
get
{
if (_instance == null)
{
lock (syncRoot)
{
if (_instance == null)
_instance = new MySingletonClass();
}
}
return _instance;
}
}
private MySingletonClass()
{
}
}
I want to be able to automatically create singleton classes while developing, with only entering a name for the class.
How can I implement this functionality with ReSharper? Can ReSharper pattern catalog be used for this?
Thank you.
You can create a Code Template for it (a File Template if you wish every singleton in a new file).
There are instructions on how to create a template from scratch and from existing code in the help files.
精彩评论