Пример #1
0
        /// <summary>
        /// Merges this set of dependencies with another set of dependencies.
        /// </summary>
        /// <param name="dependencies">Other dependencies that should be added onto the current dependencies.</param>
        /// <returns>A set of dependencies that contains all dependencies of the merged sets.</returns>
        public CodeDependencies Merge(CodeDependencies dependencies)
        {
            if (dependencies == null)
            {
                throw new ArgumentNullException(nameof(dependencies));
            }

            // Just concatenate the sequences; distinct is done
            // in construction of the resulting set.
            return(new CodeDependencies(
                       CodeFragments.Concat(dependencies.CodeFragments),
                       Imports.Concat(dependencies.Imports)));
        }
Пример #2
0
        /// <summary>
        /// Creates a <see cref="CodeFragment"/>.
        /// </summary>
        /// <param name="id">ID that is used to refer to this code fragment.</param>
        /// <param name="code">Actual code of this code fragment.</param>
        /// <param name="dependencies">Dependencies that this code fragment requires to be valid.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="id"/> or <paramref name="dependencies"/> is null.</exception>
        /// <exception cref="ArgumentException">Thrown when <paramref name="code"/> is null or empty.</exception>
        public CodeFragment(CodeFragmentId id, string code, CodeDependencies dependencies)
        {
            if (dependencies == null)
            {
                throw new ArgumentNullException(nameof(dependencies));
            }
            if (string.IsNullOrWhiteSpace(code))
            {
                throw new ArgumentException("Code cannot be empty.", nameof(code));
            }

            Id   = id ?? throw new ArgumentNullException(nameof(id));
            Code = code;

            // A code fragment does not need to indicate a dependency on itself.
            Dependencies = dependencies.WithoutCodeFragment(id);
        }