public static IAppCommand DeleteKey(DeleteKeyCommandContext context) { return new AppCommand<DeleteKeyCommandContext>(context, ctx => { File.Delete(ctx.TempFile); using(var key = ctx.Key.Root.OpenSubKey(ctx.Key.Path, true)) { NativeMethods.RegSaveKeyEx(key.Handle, ctx.TempFile, IntPtr.Zero); } ctx.Name = ctx.Key.Text; ctx.Key.Root.DeleteSubKeyTree(ctx.Key.Path); ctx.Key.Parent.SubItems.Remove(ctx.Key); }, ctx => { var parentKey = (RegistryKeyItem)ctx.Key.Parent; var item = parentKey.CreateNewKey(ctx.Name); using(var parent = item.Root.OpenSubKey(item.Path, true)) { NativeMethods.RegRestoreKey(parent.Handle, ctx.TempFile); } item.Refresh(); File.Delete(ctx.TempFile); }) { Description = "Delete key" }; }
public static IAppCommand DeleteKey(DeleteKeyCommandContext context) { return(new AppCommand <DeleteKeyCommandContext>(context, ctx => { File.Delete(ctx.TempFile); using (var key = ctx.Key.Root.OpenSubKey(ctx.Key.Path, true)) { NativeMethods.RegSaveKeyEx(key.Handle, ctx.TempFile, IntPtr.Zero); } ctx.Name = ctx.Key.Text; ctx.Key.Root.DeleteSubKeyTree(ctx.Key.Path); ctx.Key.Parent.SubItems.Remove(ctx.Key); }, ctx => { var parentKey = (RegistryKeyItem)ctx.Key.Parent; var item = parentKey.CreateNewKey(ctx.Name); using (var parent = item.Root.OpenSubKey(item.Path, true)) { NativeMethods.RegRestoreKey(parent.Handle, ctx.TempFile); } item.Refresh(); File.Delete(ctx.TempFile); }) { Description = "Delete key" }); }