コード例 #1
0
        protected override ProjectElement CreateChildElement(string name)
        {
            switch (name)
            {
            case "When":
                var when = RootElement.CreateWhenElement(null);
                PrependChild(when);
                return(when);

            case "Otherwise":
                var other = RootElement.CreateOtherwiseElement();
                AppendChild(other);
                return(other);

            default:
                throw new InvalidOperationException(String.Format(
                                                        "Child \"{0}\" is not a known node type.", name));
            }
        }
コード例 #2
0
        /// <summary>
        /// Adds an &lt;Otherwise /&gt; element to the current project.
        /// </summary>
        /// <param name="label">An optional label to add to the Otherwise.</param>
        /// <returns>The current <see cref="ProjectCreator"/>.</returns>
        /// <exception cref="ProjectCreatorException">A &lt;When /&gt; element has not been added
        /// -or-
        /// An &lt;Otherwise /&gt; has already been added to the current &lt;Choose /&gt; element.</exception>
        public ProjectCreator Otherwise(string label = null)
        {
            if (_lastWhen == null)
            {
                throw new ProjectCreatorException(Strings.ErrorOtherwiseRequiresWhen);
            }

            if (_lastChoose.OtherwiseElement != null)
            {
                throw new ProjectCreatorException(Strings.ErrorOtherwiseCanOnlyBeSetOnce);
            }

            ProjectOtherwiseElement projectOtherwiseElement = RootElement.CreateOtherwiseElement();

            projectOtherwiseElement.Label = label;
            LastChoose.AppendChild(projectOtherwiseElement);

            return(this);
        }