How to add a collection, for example. dynamic array as a property of an asp.net user control?

I am trying to add a dynamically extensible property to a composite control that I can remove on the surface of the constructor. I tried this with String Array, List and ArrayList. All with similar results. I’m missing something, and I don’t know what. Here is what I consider the appropriate code:

    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content), 
    NotifyParentProperty(true),
    PersistenceMode(PersistenceMode.InnerProperty)]
    public String[] AccessLevels
    {
        get
        {
            String[] s = (String[])ViewState["AccessLevels"];
            return s;
        }

        set
        {
            ViewState["AccessLevels"] = value;
        }
    }

, . "" Visual Studio 2008 "+ AccessLevels" "String [] Array" elipsis [...]. elipsis, , . " " "AccessLevels", , , , . ! , , , HTML- .

    <cc2:HBAdmin ID="HBAdmin1" runat="server">
        <AccessLevels>
        <system.string></system.string>
        <system.string></system.string>
        <system.string></system.string>
        </AccessLevels>
    </cc2:HBAdmin>

HBAdmin - , cc2 - . . ? intellisense <AccessLevels> , : " " AccessLevels ", < system.string > , " ", System.String ' . , ( , ), :

" "

. , , , , . , , .

, , , - - . , ?

+3
2

- :

:

<cc:SomeClass >
 <CustomLavel key="" value="" />
 <CustomLavel key="" value="" />
 <CustomLavel key="" value="" />
</cc:SomeClass>


public class SomeClass: Control, INamingContainer
{
           private Collection<CustomLabel> _customLabelList;

           protected override void AddParsedSubObject(object obj)
        {
            base.AddParsedSubObject(obj);

            if (obj is CustomLabel)
            {
                _customLabelList.Add((CustomLabel)obj);
                return;
            }
        }

[Category("Behavior")]
        [Description("The fields collection")]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]    
        [PersistenceMode(PersistenceMode.InnerDefaultProperty)]
        [DefaultValue(null), MergableProperty(false), Bindable(false)]
        public Collection<CustomLabel> CustomLabelList
        {
            get
            {
                return _customLabelList;
            }
        }
}

[TypeConverter(typeof(ExpandableObjectConverter))]
public class CustomLabel
{
    private string _key;
    private string _value;

    public CustomLabel()
        : this(string.Empty, string.Empty)
    {
    }

    public CustomLabel(string key, string value)
    {
        _key = key;
        _value = value;
    }


    [Category("Behavior")]
    [DefaultValue("")]
    [Description("Key")]
    [NotifyParentProperty(true)]
    public string Key
    {
        get
        {
            return _key;
        }
        set
        {
            _key = value;
        }
    }

    [Category("Behavior")]
    [DefaultValue("")]
    [Description("Value")]
    [NotifyParentProperty(true)]
    public string Value
    {
        get
        {
            return _value;
        }
        set
        {
            _value = value;
        }
    }
}
+1

Collection<string> string[]

+4

Source: https://habr.com/ru/post/1768634/


All Articles