Example #1
0
        public void ValidateRename(string newName)
        {
            if (newName == null)
            {
                throw new ArgumentNullException(nameof(newName));
            }
            if (NameValidator.VerifyName(newName) == false)
            {
                throw new ArgumentException(string.Format(Resources.Exception_InvalidName_Format, newName), nameof(newName));
            }

            var container = this.container;
            var category  = this.category;

            if (container != null)
            {
                var key = this.container.SupportsNonUniqueName == true?ItemName.MakePath(this.category.Path, newName) : newName;

                if (container.Contains(key) == true && container[key] != this)
                {
                    throw new ArgumentException(string.Format(Resources.Exception_AlreadyExistedItem_Format, newName), nameof(newName));
                }
            }

            if (category != null)
            {
                if (category.Categories.ContainsKey(newName) == true)
                {
                    throw new ArgumentException(Resources.Exception_SameFolderInParent);
                }
            }
        }
Example #2
0
        public void ValidateRename(string newName)
        {
            if (newName == null)
            {
                throw new ArgumentNullException(nameof(newName));
            }
            if (this.ItemAttributes.HasFlag(ItemAttributes.UniqueName) == true)
            {
                throw new ArgumentException(Resources.Exception_UniqueObjectCannotRename);
            }
            if (NameValidator.VerifyName(newName) == false)
            {
                throw new ArgumentException(string.Format(Resources.Exception_InvalidName_Format, newName), nameof(newName));
            }

            if (this.Container != null)
            {
                var newPath = CategoryBase <_I, _C, _IC, _CC, _CT> .CreatePath(newName, this.Parent);

                if (this.Container.Contains(newPath) == true && this.Container[newPath] != this)
                {
                    throw new ArgumentException(string.Format(Resources.Exception_AlreadyExistedItem_Format, newName), nameof(newName));
                }
            }

            var parent = this.parent;

            if (parent != null)
            {
                if (parent.Categories.ContainsKey(newName) == true)
                {
                    throw new ArgumentException(string.Format(Resources.Exception_AlreadyExistedItem_Format, newName));
                }
                if (parent.items.ContainsKey(newName) == true)
                {
                    throw new ArgumentException(string.Format(Resources.Exception_AlreadyExistedItem_Format, newName));
                }
                this.ValidateMove(parent);
            }
        }