WebControl

本文详细解析了 ASP.NET 中 WebControl 类的工作原理,包括其构造函数、属性及渲染过程等关键细节,为开发者提供深入理解 WebControl 的途径。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

[PersistChildren(), ParseChildren(), PermissionSet(SecurityAction.LinkDemand, XML=), PermissionSet(SecurityAction.InheritanceDemand, XML=)]
  WebControl : Control, IAttributeAccessor
{
    
      int accessKeySet = ;
     AttributeCollection attrColl;
     StateBag attrState;
     Style controlStyle;
      int deferStyleLoadViewState = ;
      int disabled = ;
      int disabledDirty = ;
     SimpleBitVector32 flags;
      int tabIndexSet = ;
     HtmlTextWriterTag tagKey;
     string tagName;
      int toolTipSet = ;

    
     WebControl() : this(HtmlTextWriterTag.Span)
    {
    }

     WebControl(string tag)
    {
        .tagKey = HtmlTextWriterTag.Unknown;
        .tagName = tag;
    }

     WebControl(HtmlTextWriterTag tag)
    {
        .tagKey = tag;
    }

      void AddAttributesToRender(HtmlTextWriter writer)
    {
        string accessKey;
         (.ID != )
        {
            writer.AddAttribute(HtmlTextWriterAttribute.Id, .ClientID);
        }
         (.flags[])
        {
            accessKey = .AccessKey;
             (accessKey.Length > )
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Accesskey, accessKey);
            }
        }
         (!.Enabled)
        {
            writer.AddAttribute(HtmlTextWriterAttribute.Disabled, );
        }
         (.flags[])
        {
            int tabIndex = .TabIndex;
             (tabIndex != )
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Tabindex, tabIndex.ToString(NumberFormatInfo.InvariantInfo));
            }
        }
         (.flags[])
        {
            accessKey = .ToolTip;
             (accessKey.Length > )
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Title, accessKey);
            }
        }
         (.ControlStyleCreated && !.ControlStyle.IsEmpty)
        {
            .ControlStyle.AddAttributesToRender(writer, );
        }
         (.attrState != )
        {
            AttributeCollection attributes = .Attributes;
            IEnumerator enumerator = attributes.Keys.GetEnumerator();
             (enumerator.MoveNext())
            {
                string current = (string) enumerator.Current;
                writer.AddAttribute(current, attributes[current]);
            }
        }
    }

     void ApplyStyle(Style s)
    {
         ((s != ) && !s.IsEmpty)
        {
            .ControlStyle.CopyFrom(s);
        }
    }

     void CopyBaseAttributes(WebControl controlSrc)
    {
         (controlSrc.flags[])
        {
            .AccessKey = controlSrc.AccessKey;
        }
         (!controlSrc.Enabled)
        {
            .Enabled = ;
        }
         (controlSrc.flags[])
        {
            .ToolTip = controlSrc.ToolTip;
        }
         (controlSrc.flags[])
        {
            .TabIndex = controlSrc.TabIndex;
        }
         (string str  controlSrc.Attributes.Keys)
        {
            .Attributes[str] = controlSrc.Attributes[str];
        }
    }

      Style CreateControlStyle()
    {
          Style(.ViewState);
    }

      void LoadViewState(object savedState)
    {
         (savedState != )
        {
            Pair pair = (Pair) savedState;
            .LoadViewState(pair.First);
             (.ControlStyleCreated || (.ViewState[] != ))
            {
                .ControlStyle.LoadViewState();
            }
            
            {
                .flags[] = ;
            }
             (pair.Second != )
            {
                 (.attrState == )
                {
                    .attrState =  StateBag();
                    .attrState.TrackViewState();
                }
                .attrState.LoadViewState(pair.Second);
            }
        }
        object obj2 = .ViewState[];
         (obj2 != )
        {
            .flags[] = !((bool) obj2);
            .flags[] = ;
        }
         (((IDictionary) .ViewState).Contains())
        {
            .flags[] = ;
        }
         (((IDictionary) .ViewState).Contains())
        {
            .flags[] = ;
        }
         (((IDictionary) .ViewState).Contains())
        {
            .flags[] = ;
        }
    }

     void MergeStyle(Style s)
    {
         ((s != ) && !s.IsEmpty)
        {
            .ControlStyle.MergeWith(s);
        }
    }

      void Render(HtmlTextWriter writer)
    {
        .RenderBeginTag(writer);
        .RenderContents(writer);
        .RenderEndTag(writer);
    }

      void RenderBeginTag(HtmlTextWriter writer)
    {
        .AddAttributesToRender(writer);
        HtmlTextWriterTag tagKey = .TagKey;
         (tagKey != HtmlTextWriterTag.Unknown)
        {
            writer.RenderBeginTag(tagKey);
        }
        
        {
            writer.RenderBeginTag(.TagName);
        }
    }

      void RenderContents(HtmlTextWriter writer)
    {
        .Render(writer);
    }

      void RenderEndTag(HtmlTextWriter writer)
    {
        writer.RenderEndTag();
    }

      object SaveViewState()
    {
        Pair pair = ;
         (.flags[])
        {
            .ViewState[] = !.flags[];
        }
         (.ControlStyleCreated)
        {
            .ControlStyle.SaveViewState();
        }
        object x = .SaveViewState();
        object y = ;
         (.attrState != )
        {
            y = .attrState.SaveViewState();
        }
         ((x == ) && (y == ))
        {
             pair;
        }
          Pair(x, y);
    }

    string IAttributeAccessor.GetAttribute(string name)
    {
         (.attrState == )
        {
             ;
        }
         (string) .attrState[name];
    }

    void IAttributeAccessor.SetAttribute(string name, string value)
    {
        .Attributes[name] = value;
    }

      void TrackViewState()
    {
        .TrackViewState();
         (.ControlStyleCreated)
        {
            .ControlStyle.TrackViewState();
        }
         (.attrState != )
        {
            .attrState.TrackViewState();
        }
    }

    
    [WebSysDescription(), DefaultValue(), Bindable(), WebCategory()]
      string AccessKey
    {
        
        {
             (.flags[])
            {
                string str = (string) .ViewState[];
                 (str != )
                {
                     str;
                }
            }
             string.Empty;
        }
        
        {
             (( != ) && (.Length > ))
            {
                  ArgumentOutOfRangeException();
            }
            .ViewState[] = ;
            .flags[] = ;
        }
    }

    [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), WebSysDescription(), Browsable()]
     AttributeCollection Attributes
    {
        
        {
             (.attrColl == )
            {
                 (.attrState == )
                {
                    .attrState =  StateBag();
                     (.IsTrackingViewState)
                    {
                        .attrState.TrackViewState();
                    }
                }
                .attrColl =  AttributeCollection(.attrState);
            }
             .attrColl;
        }
    }

    [WebCategory(), DefaultValue((Color), ), WebSysDescription(), TypeConverter((WebColorConverter)), Bindable()]
      Color BackColor
    {
        
        {
             (!.ControlStyleCreated)
            {
                 Color.Empty;
            }
             .ControlStyle.BackColor;
        }
        
        {
            .ControlStyle.BackColor = ;
        }
    }

    [Bindable(), WebCategory(), WebSysDescription(), TypeConverter((WebColorConverter)), DefaultValue((Color), )]
      Color BorderColor
    {
        
        {
             (!.ControlStyleCreated)
            {
                 Color.Empty;
            }
             .ControlStyle.BorderColor;
        }
        
        {
            .ControlStyle.BorderColor = ;
        }
    }

    [DefaultValue(), Bindable(), WebCategory(), WebSysDescription()]
      BorderStyle BorderStyle
    {
        
        {
             (!.ControlStyleCreated)
            {
                 BorderStyle.NotSet;
            }
             .ControlStyle.BorderStyle;
        }
        
        {
            .ControlStyle.BorderStyle = ;
        }
    }

    [Bindable(), DefaultValue((Unit), ), WebSysDescription(), WebCategory()]
      Unit BorderWidth
    {
        
        {
             (!.ControlStyleCreated)
            {
                 Unit.Empty;
            }
             .ControlStyle.BorderWidth;
        }
        
        {
             (.Value < )
            {
                  ArgumentOutOfRangeException();
            }
            .ControlStyle.BorderWidth = ;
        }
    }

    [WebSysDescription(), Browsable(), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
     Style ControlStyle
    {
        
        {
             (.controlStyle == )
            {
                .controlStyle = .CreateControlStyle();
                 (.IsTrackingViewState)
                {
                    .controlStyle.TrackViewState();
                }
                 (.flags[])
                {
                    .flags[] = ;
                    .controlStyle.LoadViewState();
                }
            }
             .controlStyle;
        }
    }

    [Browsable(), WebSysDescription(), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
     bool ControlStyleCreated
    {
        
        {
             (.controlStyle != );
        }
    }

    [WebCategory(), DefaultValue(), WebSysDescription(), Bindable()]
      string CssClass
    {
        
        {
             (!.ControlStyleCreated)
            {
                 string.Empty;
            }
             .ControlStyle.CssClass;
        }
        
        {
            .ControlStyle.CssClass = ;
        }
    }

    [WebCategory(), DefaultValue(), WebSysDescription(), Bindable()]
      bool Enabled
    {
        
        {
             !.flags[];
        }
        
        {
            bool flag = !.flags[];
             (flag != )
            {
                .flags[] = !;
                 (.IsTrackingViewState)
                {
                    .flags[] = ;
                }
            }
        }
    }

    [NotifyParentProperty(), DefaultValue((string) ), WebSysDescription(), DesignerSerializationVisibility(DesignerSerializationVisibility.Content), WebCategory()]
      FontInfo Font
    {
        
        {
             .ControlStyle.Font;
        }
    }

    [WebSysDescription(), TypeConverter((WebColorConverter)), Bindable(), WebCategory(), DefaultValue((Color), )]
      Color ForeColor
    {
        
        {
             (!.ControlStyleCreated)
            {
                 Color.Empty;
            }
             .ControlStyle.ForeColor;
        }
        
        {
            .ControlStyle.ForeColor = ;
        }
    }

     bool HasAttributes
    {
        
        {
             (((.attrColl != ) && (.attrColl.Count > )) || ((.attrState != ) && (.attrState.Count > )));
        }
    }

    [WebCategory(), WebSysDescription(), DefaultValue((Unit), ), Bindable()]
      Unit Height
    {
        
        {
             (!.ControlStyleCreated)
            {
                 Unit.Empty;
            }
             .ControlStyle.Height;
        }
        
        {
             (.Value < )
            {
                  ArgumentOutOfRangeException();
            }
            .ControlStyle.Height = ;
        }
    }

    [WebSysDescription(), Browsable(), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
     CssStyleCollection Style
    {
        
        {
             .Attributes.CssStyle;
        }
    }

    [WebCategory(), DefaultValue((short) ), WebSysDescription()]
      short TabIndex
    {
        
        {
             (.flags[])
            {
                object obj2 = .ViewState[];
                 (obj2 != )
                {
                     (short) obj2;
                }
            }
             ;
        }
        
        {
            .ViewState[] = ;
            .flags[] = ;
        }
    }

    [Browsable(), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
      HtmlTextWriterTag TagKey
    {
        
        {
             .tagKey;
        }
    }

    [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable()]
      string TagName
    {
        
        {
             ((.tagName == ) && (.tagKey != HtmlTextWriterTag.Unknown))
            {
                .tagName = Enum.Format((HtmlTextWriterTag), .tagKey, ).ToLower(CultureInfo.InvariantCulture);
            }
             .tagName;
        }
    }

    [Bindable(), DefaultValue(), WebSysDescription(), WebCategory()]
      string ToolTip
    {
        
        {
             (.flags[])
            {
                string str = (string) .ViewState[];
                 (str != )
                {
                     str;
                }
            }
             string.Empty;
        }
        
        {
            .ViewState[] = ;
            .flags[] = ;
        }
    }

    [DefaultValue((Unit), ), WebSysDescription(), Bindable(), WebCategory()]
      Unit Width
    {
        
        {
             (!.ControlStyleCreated)
            {
                 Unit.Empty;
            }
             .ControlStyle.Width;
        }
        
        {
             (.Value < )
            {
                  ArgumentOutOfRangeException();
            }
            .ControlStyle.Width = ;
        }
    }
}

转载于:https://www.cnblogs.com/sincerefire/archive/2010/02/21/1670596.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值