3
\$\begingroup\$

I define in the Settings Tab of a VB.Net class library some user scoped settings. I want to expose these settings to other projects that reference the class library. I chose to do this using a public Module. This works, but it requires exposing each and every setting manually. Is there a better way?

Public Module Settings
 Public Property SomeSetting As Integer
 Get
 Return My.Settings.SomeSetting
 End Get
 Set(value As Integer)
 My.Settings.SomeSetting = value
 My.Settings.Save()
 End Set
 End Property
End Module
Malachi
29k11 gold badges86 silver badges188 bronze badges
asked Jan 15, 2013 at 9:48
\$\endgroup\$
4
  • 2
    \$\begingroup\$ You could expose the Settings module wholesale. \$\endgroup\$ Commented Jan 15, 2013 at 10:09
  • \$\begingroup\$ @KonradRudolph Can you elaborate? \$\endgroup\$ Commented Jan 15, 2013 at 10:28
  • 1
    \$\begingroup\$ Just have a (read-only) property which returns the My.Settings object (no setter required). \$\endgroup\$ Commented Jan 15, 2013 at 10:47
  • \$\begingroup\$ If you're going to expose getters and setters, you might as well make the settings public, no? \$\endgroup\$ Commented Nov 14, 2013 at 1:00

1 Answer 1

2
\$\begingroup\$

I think it's a fairly verbose way of exposing app settings. How about this?

enter image description here

(taken from an answer on this SO question)

This essentially comes down to what @KonradRudolph's comment was saying - the reason you "need" your Settings module is probably because the settings' access modifier is set to Internal, which means it's not accessible to other assemblies.

If you need to expose app settings to other assemblies, you just change that access modifier to Public and you're done.

Doing this:

Public Module Settings
 Public Property AppSettings As Settings
 Get
 Return My.Settings
 End Get
 End Property
End Module

Is then totally redundant. Even more so, doing what you've done (exposing each setting individually) becomes more painful to maintain than it needs to be; if the settings are public then you expose the settings class itself and whatever you change is immediately available to client assemblies.

answered Nov 19, 2013 at 2:15
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.