Re: access the calling user's config info from a dll?
- From: "Norman Yuan" <NotReal@xxxxxxxxxxx>
- Date: Sat, 15 Jul 2006 08:51:49 -0700
You should not read exe's app settings directly from inside dll's code.
DLL, by its nature, is code module that seperates from exe code with
consideration that it could be used by other exes (of course that are other
reasons to use dll).
If you do the app.cofg reading inside dll code, you physically tie the dll
with certain exe, the dll's reuseability is go partially or completely, even
different version of the same exe may break the dll.
Of course you can make the dll to read some type of *.cofg/settings of
certain, or predefined format, say, you can assume there are always certain
settings exist and you would handle the absence of expeted but missing
settings properly. It sounds not elegent at all and I'd never do it, but you
can do it if insist. In this case, you only need pass a file path from the
calling exe app and do you file read, maybe (write) yourself.
Again, I'd never read user/app config in dll. If you need to process
information from *.config in the dll code, you can always read them from the
calling exe app and pass the data itself to a dll object to process it (and
return back the changed data and save to *.config by the exe). In your
example,
Properties.Settings settings =
MyNameSpace.Properties.Settings.Default;
MessageBox.Show(settings.MyProperty);
MyBOObject obj=new MyBOObject()
//assign setting value to the BO object
obj.Property1=setting.MyPropertiy
//Or process the setting value
obj.TheMethod(setting.MyProperty)
"Barry Mossman" <NOSPAM@xxxxxxxxxx> wrote in message
news:ulu07r%23pGHA.4424@xxxxxxxxxxxxxxxxxxxxxxx
Hi,
I am using C#. My WinForm project has a config file created by VS2005
containing some user scoped properties. It has setup as the config file as
follows:
<userSettings>
<MyNameSpace.Properties.Settings>
<setting name="MyProperty" serializeAs="String">
<value>"aaa"</value>
</setting>
</MyNameSpace.Properties.Settings>
</userSettings>
I can easily access the property value in a type-safe manner in my WinForm
via:
Properties.Settings settings =
MyNameSpace.Properties.Settings.Default;
MessageBox.Show(settings.MyProperty);
My WinForm uses some BO's from a dll. How can I access the config
properties from within the dll?
The class which contains the property specification is marked internal to
the WinForm exe.
I have read the helptext regarding ApplicationSettingBase and
ConfigurationManager classes. These are both new with .Net 2.0, so they
most be both current technologies. Neither sections of helptext refer to
the other. I can't understand what job each of them are trying to do, or
how they relate to each other.
If one wants to access the calling user's config info from a dll, which
facility should I be using?
thanks
Barry Mossman
.
- Follow-Ups:
- Re: access the calling user's config info from a dll?
- From: Barry Mossman
- Re: access the calling user's config info from a dll?
- References:
- access the calling user's config info from a dll?
- From: Barry Mossman
- access the calling user's config info from a dll?
- Prev by Date: Re: How could I achieve this?
- Next by Date: Re: How could I achieve this?
- Previous by thread: Re: access the calling user's config info from a dll?
- Next by thread: Re: access the calling user's config info from a dll?
- Index(es):
Relevant Pages
|