示例#1
0
        /// <summary>
        /// Adds an output object to the directory with the option of overriding an existing object with the same name.
        /// Returns true if the object was added.
        /// </summary>
        /// <param name="output"></param>
        /// <param name="canOverride"></param>
        /// <returns>Returns true if the object was added.</returns>
        public bool Add(OutputObject output, bool canOverride)
        {
            if (output == null)
                throw new NullReferenceException("File cannot be null.");

            if (Contains(output))
            {
                //throw new Exception(string.Format("A file with the name '{0}' already exists in this directory.", file.Name));

                if (canOverride)
                {
                    //remove (skip) file(s) with the same name
                    outputs = outputs.SkipWhile(f => f.Name.Equals(output.Name, StringComparison.CurrentCultureIgnoreCase)).ToList();
                }
                else
                    return false;
            }

            outputs.Add(output);
            output.ParentDirectory = this;
            return true;
        }
示例#2
0
        /// <summary>
        /// Returns true if the specified object exists in the directory.
        /// </summary>
        /// <param name="output"></param>
        /// <returns></returns>
        public bool Contains(OutputObject output)
        {
            if (output == null)
                throw new NullReferenceException("File cannot be null.");

            return outputs.Any(f => f.Name.Equals(output.Name, StringComparison.CurrentCultureIgnoreCase));
        }