示例#1
0
 /// <summary>
 /// Sets the builder context this element can be build within
 /// </summary>
 /// <param name="context">Builder context</param>
 public void SetContext(IHtmlBuilderContext context)
 {
     if (context == null)
     {
         throw new ArgumentNullException("context");
     }
     ParentContext = context;
     Depth         = context.Depth;
     OnBuilderContextAttached();
 }
        /// <summary>
        /// Initializes this builder instance
        /// </summary>
        /// <param name="htmlHelper">HtmlHelper to use</param>
        /// <param name="element">Element to build</param>
        /// <param name="buildOnConstruction">
        /// Shows whether this builder should build the buildable immediately after
        /// successful construction
        /// </param>
        /// <param name="parentBuilderContext"></param>
        protected HtmlBuilderBase(HtmlHelper <TModel> htmlHelper, TElement element,
                                  bool buildOnConstruction = true,
                                  IHtmlBuilderContext parentBuilderContext = null)
        {
            if (htmlHelper == null)
            {
                throw new ArgumentNullException("htmlHelper");
            }
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }

            HtmlHelper           = htmlHelper;
            ParentBuilderContext = parentBuilderContext;
            Element = element;
            Element.SetContext(this);
            Depth               = parentBuilderContext == null ? 0 : parentBuilderContext.Depth + 1;
            TextWriter          = htmlHelper.ViewContext.Writer;
            BuildOnConstruction = buildOnConstruction;
            ConstructionTimeBuild();
        }