public static void CreateTemplate(string Name, string Expansion, string CategoryName, ContextPickerData Context) { Template Template = GetOrCreateTemplateByNameAndCat(Name, CategoryName, CodeRush.Language.Active); TemplateData Data = new TemplateData(); Data.Expansion = Expansion; Data.SetContext(Context); switch (Template.Items.Count) { case 0: Template.Items.Add(Data); break; case 1: DialogResult Replace = MessageBox.Show("This Template already exists. Would you like to replace the old Template?", "Template already exists", MessageBoxButtons.YesNoCancel); switch (Replace) { case DialogResult.Yes: //Replace Existing Template Variations Template.Items.Clear(); Template.Items.Add(Data); break; case DialogResult.No: // Add this variation to those already existing. Template.Items.Add(Data); break; default: return; // Cancel } break; default: // Many alternatives MessageBox.Show("Multiple Template expansions found. Aborting."); return; } CodeRush.Templates.Save(); }