Question Is it possible to create a Property through Function?

cloudwp

New member
Joined
Oct 16, 2021
Messages
2
Programming Experience
10+
I want to create an property for a user control through function.


or


Change the Attribute of a property through function.

C#:
        [Description( "PlaceHolder Text" ), Category( "SuggestBox" )]
        [Browsable( true ), EditorBrowsable( EditorBrowsableState.Always ), System.ComponentModel.Bindable( true )]
        [DesignerSerializationVisibility( DesignerSerializationVisibility.Visible )]
        public string IPlaceHolderText
            {
            get { return myAutoSuggestBox.PlaceholderText; }
            set { myAutoSuggestBox.PlaceholderText = value; }


Am i able to change the Browsable Attribute through function ?





Thank you for your answers
 
Last edited by a moderator:
No, that is not possible. The attributes are part of the property itself, which is defined in the original assembly. You would have to inherit the class and shadow the property. Overriding would be preferable but the property is not virtual.
 
As a quick aside, this is possible with the ExpandoObject object but only at runtime. The context of your question seems to imply design time exposed by the WinForms designer based on the attributes you have in the code in the original post, but unfortunately, you posted "C# General Discussion" forum. If you really wanted to just cover the WinForms aspect of things, let us know and we can move this thread to the "WinForms" forum.

Nevermind. I just realized that you are specifically talking about user controls, not classes in general.
 

Latest posts

Back
Top Bottom