Question Dynamic Properties

StoneCodeMonkey

Well-known member
Joined
Apr 17, 2009
Messages
56
Programming Experience
5-10
I have been using app.config to store various setting for my applications in several small projects recently. I created a class that would expose the app.config values as properties. For example:

VB.NET:
Public Class ConfigManagement
    Private config As System.Configuration.Configuration

    Public Sub New()
        config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
    End Sub


    Public ReadOnly Property DebugMode() As Boolean
        Get
            Return config.AppSettings.Settings("Debug").Value
        End Get
    End Property

    Public ReadOnly Property AppTitle() As String
        Get
            Return config.AppSettings.Settings("AppTitle").Value
        End Get
    End Property
End Class

I find myself editing this class often to add new properties as required by each project. I would like to convert this class to a Component that will allow me to use a design time editor to add properties dynamically or maybe something as simple when the main application starts, instance.AddProprty(ByVal ElementName, ByVal ReturnType as Object).

How would I go about adding a property dynamically to the componet such that I can still use the instance.xxxx = abc or abc = instance.xxxx notation.

It is simple enough to create the component class: Public Class AppManager : Inherits Component.

I just don't see a method to add a property dynamically.

Best regards,
 
Ok, forget the porperty thing for the moment.

I'd really be happy to just have Intellisense display items as they were added to a list, hashtable, etc.

For instance:

Public Class x : Inherits Component
Dim y as SomeKindOfContainer

Public Sub Add(ByVal SomeName as String")
y.Add(SomeName)
End Sub

End Class


Then through a designer the SomeName could be populated and then intellisense could pick up on the items.
 
Are you aware this is included in VS? That is how application settings work, you add settings using the Settings dialog in Project properties and IDE generates a strongly typed class (My.Settings) with a property for each setting. These settings/properties are also available to bind to control properties in designer.
 
Hello everyone, happy holidays.

While I'd prefer not to raise old threads, I finally have a few days off from work and thought I'd try understanding how the Settings designer in VS works. For most of my applications, using the built-in designer and support for settings is adequate, but I can't help but wonder what it would take to create a custom component that has a designer like that of the built-in Settings designer.

I'm most interested in the ability of the designer that allows you to create a setting such as MyValue and then simply refer to it as My.Settings.MyValue from within your application.

So I'm off to see if I can create a component with a designer that would allow me to accomplish this functionality. Not entirely sure where to start, so if anyone has any ideas, feel free to ping.
 
Well, spent the entire day trying to figure this all out. No luck.

However, after reading over material all day, I think that emulating Settings functionality isn't what I'm looking for.

What I really want to do is a have a Custom Component Designer that will insert code into a 'Partial' class.

Does anyone know how to hook into the IDE and insert code into a code file?
 
I found an easy enough means of creating the code using CodeDOM. So, having a 'designer' that can output code elements is straight forward, this much I've tested. Next steps will be how to locate a specific Partial Class within the IDE and hook into it for modification.

Regards
 
Back
Top