开发者

How do you override attributes of a .NET framework class in child class?

开发者 https://www.devze.com 2023-04-02 19:40 出处:网络
The base class WebPart has a property defined like this: [WebBrowsable(true)] public virtual string CatalogIconImageUrl { get; set; }

The base class WebPart has a property defined like this:

 [WebBrowsable(true)]
 public virtual string CatalogIconImageUrl { get; set; }

Can I have a child class which will just override the attribute as shown below? I have tried but it doesn't work.

 [WebBrowsable(false)]
    public override string CatalogIconImageUrl
    {
        get
        {
            return base.CatalogIconImageUrl;
        }
        set
        {开发者_高级运维
            base.CatalogIconImageUrl = value;
        }
    }

The base class is a .NET framework class, documented here:

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.webparts.webpart.catalogiconimageurl.aspx


i am not a 100% sure but should the code be more like

internal string _catalogIconImageUrl;
[WebBrowsable(false)]
public override string CatalogIconImageUrl
{
    get
    {
        return _catalogIconImageUrl;
    }
    set
    {
        _catalogIconImageUrl = value;
    }
}

this is so the variable is attached to the child object and the variable will still be available when the CatalogIconImageUrl property is called by the parent class/type.

0

精彩评论

暂无评论...
验证码 换一张
取 消