Example #1
0
        /// <summary>
        /// Rename specified block to new name
        /// </summary>
        /// <param name="oldName">
        /// The block to be renamed, must exist in current file</param>
        /// <param name="newName">
        /// New name of the block, must not exist</param>
        /// <returns>Returns true if successfully renamed, else false</returns>
        public bool Rename(string newName)
        {
            string kMethodName = "DSBlock.Rename";

            if (string.IsNullOrEmpty(Name))
            {
                throw new ArgumentException(string.Format(Properties.Resources.InvalidInput, Name, kMethodName), "oldName");
            }

            if (string.IsNullOrEmpty(newName))
            {
                throw new ArgumentException(string.Format(Properties.Resources.InvalidInput, newName, kMethodName), "newName");
            }

            IBlockHelper helper = HostFactory.Factory.GetBlockHelper();

            if (null == helper)
            {
                throw new InvalidOperationException(string.Format(Properties.Resources.OperationFailed, kMethodName));
            }

            if (helper.RenameBlock(Name, newName))
            {
                Name = newName;
                return(true);
            }

            return(false);
        }