예제 #1
0
파일: DOM.cs 프로젝트: zzc000/AngleSharp
        public void HtmlHasRightHeadElement()
        {
            var document = new HtmlDocument();
            var root     = new HtmlHtmlElement(document);

            document.AppendChild(root);
            var head = new HtmlHeadElement(document);

            root.AppendChild(head);
            Assert.AreEqual(head, document.Head);
        }
        /// <summary> Registers a <see cref="HtmlHeadElement"/>. </summary>
        /// <remarks>
        ///   All calls to <see cref="RegisterHeadElement"/> must be completed before
        ///   <see cref="SetAppended"/> is called. (Typically during the <c>Render</c> phase.)
        /// </remarks>
        /// <param name="key">
        ///   The unique key identifying the header element in the collection. Must not be <see langword="null"/> or empty.
        /// </param>
        /// <param name="headElement">
        ///   The <see cref="HtmlHeadElement"/> representing the head element. Must not be <see langword="null"/>.
        /// </param>
        /// <param name="priority">
        ///   The priority level of the head element. Elements are rendered in the following order:
        ///   Library, UserControl, Page.
        /// </param>
        /// <exception cref="InvalidOperationException">
        ///   Thrown if method is called after <see cref="SetAppended"/> has executed.
        /// </exception>
        public void RegisterHeadElement(string key, HtmlHeadElement headElement, Priority priority)
        {
            ArgumentUtility.CheckNotNullOrEmpty("key", key);
            ArgumentUtility.CheckNotNull("headElement", headElement);

            EnsureStateIsClearedAfterServerTransfer();

            if (_hasAppendExecuted)
            {
                throw new InvalidOperationException("RegisterHeadElement must not be called after SetAppended has been called.");
            }

            if (!IsRegistered(key))
            {
                _registeredKeys.Add(key, null);
                _prioritizedHeadElements.Add(priority, headElement);
            }
        }