示例#1
0
        /// <summary>
        /// Compose content with placeholders provided by <see cref="Converters"/> and template from file system.
        /// </summary>
        /// <param name="path">The template location in file system.</param>
        /// <param name="encoding">The encoding that is applied to the contents of the template.</param>
        /// <returns>The content after composition.</returns>
        /// <exception cref="ArgumentException">
        /// <paramref name="path"/> is a zero-length string, contains only white space, 
        /// or contains one or more invalid characters as defined by the <see cref="Path.GetInvalidPathChars"/> method.
        /// </exception>
        /// <exception cref="IOException">An I/O error occurred while opening the template.</exception>
        public IEnumerable<string> Compose(string path, Encoding encoding)
        {
            var template = File.ReadLines(path, encoding);
            var placeholders = this.converters.SelectMany(ConversionUnit.CreateFrom);
            var operation = new EnumerableOperation(new StringBuilderLazyReplacer(placeholders), BufferSize);

            Parallel.ForEach(template, operation.ParallelLoopBody);

            return operation.GetResult();
        }
示例#2
0
        /// <summary>
        /// Composes content with placeholders from <see cref="Converters"/> and given template. 
        /// </summary>
        /// <param name="template">The template used to compose.</param>
        /// <returns>The content after composition.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="template"/> is null.</exception>
        public IEnumerable<string> Compose(IEnumerable<string> template)
        {
            if (template == null) throw new ArgumentNullException("template");

            var placeholders = this.converters.SelectMany(ConversionUnit.CreateFrom);
            var operation = new EnumerableOperation(new StringBuilderLazyReplacer(placeholders), BufferSize);

            Parallel.ForEach(template, operation.ParallelLoopBody);

            return operation.GetResult();
        }