[RESOLVED] [2005] Generator for Singleton code
In the Designer of my forms I usually have this for Singleton purposes.
C# Code:
private static frmMainMenu instance = null;
public static frmMainMenu Instance()
{
if (instance == null)
{
instance = new frmMainMenu();
}
return instance;
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
instance = null;
}
Is there any hack in the IDE that would let me just press a button or something and it will automatically add the code I have above to the selected Designer?
I can always type or copy/paste/modify it but I thought there could be something that I could set to just automate this redundant task.
Re: [2005] Generator for Singleton code
Any reason you can't create a snippet? You should be able to add the code in a couple of keystrokes going that route.
Re: [2005] Generator for Singleton code
Hmmmnn... Okay. I think I tried that previously but was unsuccessful in creating a snippet. Do you have some direction that I could follow?
Re: [2005] Generator for Singleton code
Do you mean creating code snippets in general? If so try this http://msdn.microsoft.com/en-us/libr...93(VS.80).aspx
Re: [2005] Generator for Singleton code
I will try it again when I have more time, I think I have tried it last year but failed and didn't bother with it again. Thanks guys! Will let you know when I am done with it.
Re: [2005] Generator for Singleton code
How should I design the snippet so it will take the name of the form that is currently selected?
Re: [RESOLVED] [2005] Generator for Singleton code
Re: [2005] Generator for Singleton code
Quote:
Originally Posted by dee-u
How should I design the snippet so it will take the name of the form that is currently selected?
This thread has the answer in case someone else is interested.