Generically Using Properties.Settings

  • Thread starter Thread starter Jonathan Wood
  • Start date Start date
J

Jonathan Wood

In a WinForms app, I can access my project's setting using
MyApp.Properties.Settings...

But what if I want to do this from a class library that is used in different
projects? Is there a way to generically access the properties for the
current application (without directly referencing MyApp)?

Thanks for any tips.

Jonathan
 
In a WinForms app, I can access my project's setting using
MyApp.Properties.Settings...

But what if I want to do this from a class library that is used in different
projects? Is there a way to generically access the properties for the
current application (without directly referencing MyApp)?

Thanks for any tips.

I don't think it could be possible. In order to be able to do this,
you would have to pass the application's namespace name as some kind
of parameter. Seems that a namespace is not a Type.
 
I don't think it could be possible. In order to be able to do this,
you would have to pass the application's namespace name as some kind
of parameter. Seems that a namespace is not a Type.

One other thing, I actually did this for one project I worked on. So
if I need to do this for another project I plan to just copy the
class.

Besides, each project probably has it's own unique set of settings.
 
if you mean the appSettings in the program config file you can always use
(even from the library dll)

System.Configuration.ConfigurationManager.AppSettings[Key] ;

you need to add a reference to SystemConfiguration to the project

/LM
 
Thanks for that. I was having hard time finding information on this.

However, my data is actually stored in userSettings:

<userSettings>
<TestApp.Properties.Settings>
<setting name="EmailHost" serializeAs="String">
<value>www.softcircuits.com</value>
</setting>
</TestApp.Properties.Settings>
</userSettings>

I see ConfigurationManager doesn't have a UserSetting member. Is that
possible?

Thanks.

Jonathan

Luc E. Mistiaen said:
if you mean the appSettings in the program config file you can always use
(even from the library dll)

System.Configuration.ConfigurationManager.AppSettings[Key] ;

you need to add a reference to SystemConfiguration to the project

/LM

Jonathan Wood said:
In a WinForms app, I can access my project's setting using
MyApp.Properties.Settings...

But what if I want to do this from a class library that is used in
different projects? Is there a way to generically access the properties
for the current application (without directly referencing MyApp)?

Thanks for any tips.

Jonathan
 
Actually, I seem to have trouble getting this to work for application
settings as well. It just returns null.

<applicationSettings>
<TestApp.Properties.Settings>
<setting name="EmailHost" serializeAs="String">
<value>www.softcircuits.com</value>
</setting>
</TestApp.Properties.Settings>
</applicationSettings>

Thanks.

Jonathan

Luc E. Mistiaen said:
if you mean the appSettings in the program config file you can always use
(even from the library dll)

System.Configuration.ConfigurationManager.AppSettings[Key] ;

you need to add a reference to SystemConfiguration to the project

/LM

Jonathan Wood said:
In a WinForms app, I can access my project's setting using
MyApp.Properties.Settings...

But what if I want to do this from a class library that is used in
different projects? Is there a way to generically access the properties
for the current application (without directly referencing MyApp)?

Thanks for any tips.

Jonathan
 
Sorry, I am used to the old appSettings and have no experience with the more
recent applicationSettings. I know for sure that appSettings works as I use
it in my applications.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="Base8" value="Int8" />
<add key="Base8U" value="UInt8" />
</appSettings>
</configuration>
 
Back
Top