Ejemplo n.º 1
0
        /// <summary>
        /// Mark the specified dependency for inclusion.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="position">The position.</param>
        /// <returns></returns>
#pragma warning disable CS0618 // Type or member is obsolete
        public WebDependencies Include(WebDependency value, WebDependencyPosition position = WebDependencyPosition.Default)
        {
            if (this.includes == null)
            {
                this.includes = new Dictionary <string, Tuple <WebDependency, WebDependencyPosition> >();
            }

            Tuple <WebDependency, WebDependencyPosition> includeCandidate;

            if (!this.includes.TryGetValue(value.Name, out includeCandidate))
            {
                // not included yet
                this.includes.Add(value.Name, new Tuple <WebDependency, WebDependencyPosition>(value, position));
            }
            else
            {
                // already included. Take the highest position
                var replace = false;
                if (position != WebDependencyPosition.Default)
                {
                    if (includeCandidate.Item2 == WebDependencyPosition.Default)
                    {
                        replace = true;
                    }
                    else if (position < includeCandidate.Item2)
                    {
                        replace = true;
                    }
                    else
                    {
                        // do not replace
                    }
                }
                else
                {
                    // position is default, do not replace
                }

                if (replace)
                {
                    this.includes[value.Name] = new Tuple <WebDependency, WebDependencyPosition>(value, position);
                }
            }

            return(this);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Renders the specified dependency.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns>HTML</returns>
        /// <exception cref="System.ArgumentNullException">value</exception>
        public MvcHtmlString Render(WebDependency value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            if (value.Files != null)
            {
                var sb = new StringBuilder();
                for (int i = 0; i < value.Files.Count; i++)
                {
                    RenderDependency(value.Files[i], sb);
                }

                return(MvcHtmlString.Create(sb.ToString()));
            }

            return(MvcHtmlString.Empty);
        }