예제 #1
0
        public static IAppCommand RenameKey(RenameKeyCommandContext context)
        {
            return new AppCommand<RenameKeyCommandContext>(context, ctx => {
                var parent = ctx.Key.Parent as RegistryKeyItem;
                Debug.Assert(parent != null);
                using(var key = parent.Root.OpenSubKey(parent.Path ?? string.Empty, true)) {
                    int error = NativeMethods.RegRenameKey(key.Handle, ctx.OldName, ctx.NewName);
                    if(error != 0)
                        throw new Win32Exception(error);
                }

                ctx.Key.Text = ctx.NewName;

                // swap names for undo
                var temp = ctx.OldName;
                ctx.OldName = ctx.NewName;
                ctx.NewName = temp;
            }) { Description = "Rename key" };
        }
예제 #2
0
        public static IAppCommand RenameKey(RenameKeyCommandContext context)
        {
            return(new AppCommand <RenameKeyCommandContext>(context, ctx => {
                var parent = ctx.Key.Parent as RegistryKeyItem;
                Debug.Assert(parent != null);
                using (var key = parent.Root.OpenSubKey(parent.Path ?? string.Empty, true)) {
                    int error = NativeMethods.RegRenameKey(key.Handle, ctx.OldName, ctx.NewName);
                    if (error != 0)
                    {
                        throw new Win32Exception(error);
                    }
                }

                ctx.Key.Text = ctx.NewName;

                // swap names for undo
                var temp = ctx.OldName;
                ctx.OldName = ctx.NewName;
                ctx.NewName = temp;
            })
            {
                Description = "Rename key"
            });
        }