在应用程序C#2.0中使用设置 [英] Using Settings across an application C# 2.0

查看:78
本文介绍了在应用程序C#2.0中使用设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在我的1.1代码中使用这样的语句。


System.Configuration.ConfigurationSettings.AppSett ings [" jobclock.net" ]


我在应用程序引用的DLL中使用它。应用程序

在其app.config文件中包含此数据。我想在2.0中切换到新的

设置文件,但我不知道是否可以从

不同的DLL访问这些设置。我不能在DLL中引用回到应用程序

,因为这会创建一个循环引用。


任何人这样做或有任何想法?


谢谢,


Eric Renken


I currently use statements like this in my 1.1 code.

System.Configuration.ConfigurationSettings.AppSett ings[ "jobclock.net" ]

I use this in DLLs that are referenced by the application. The application
has this data in its app.config file. I would like to switch to the new
Setting files in 2.0, but I don''t know if I can access these settings from a
different DLL. I can''t make a reference in the DLL back to the application
because that would create a circular reference.

Anyone done this or have any ideas?

Thanks,

Eric Renken


推荐答案

Eric,


你有什么需要为应用程序设置一个引用?您在帖子中引用的

行来自System.Configuration命名空间中的ConfigurationSettings

类,以及

中的dll当然没有对你的dll的引用,所以应该没有

的问题。


我不明白你为什么要这么做改变这一点。如果您的DLL已加载,

您可以访问文件中的设置,与在应用程序域中运行的任何其他程序集相同。


希望这会有所帮助。

-

- Nicholas Paldino [.NET / C#MVP]

- mv*@spam.guard.caspershouse.com


" Eric Renken" <尔********* @ newsgroup.nospam>在消息中写道

news:uc ************** @ tk2msftngp13.phx.gbl ...
Eric,

What do you have to set a reference back to the application for? The
line that you referenced in your post is from the ConfigurationSettings
class in the System.Configuration namespace, and the dll that is in
certainly doesn''t have a reference to your dll, so there should be no
problem.

I don''t see why you would have to change this. If your DLL is loaded,
you can access the settings in the file the same as any other assembly
running in the app domain.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Eric Renken" <Er*********@newsgroup.nospam> wrote in message
news:uc**************@tk2msftngp13.phx.gbl...
我目前使用的语句如同这在我的1.1代码中。

System.Configuration.ConfigurationSettings.AppSett ings [" jobclock.net" ]

我在应用程序引用的DLL中使用它。
应用程序在其app.config文件中包含此数据。我想将
切换到2.0中的新设置文件,但我不知道是否可以从不同的DLL访问这些
设置。我不能在DLL中对应用程序进行引用,因为这会创建一个循环引用。

任何人都这样做或有任何想法?
谢谢,

Eric Renken
I currently use statements like this in my 1.1 code.

System.Configuration.ConfigurationSettings.AppSett ings[ "jobclock.net" ]

I use this in DLLs that are referenced by the application. The
application has this data in its app.config file. I would like to switch
to the new Setting files in 2.0, but I don''t know if I can access these
settings from a different DLL. I can''t make a reference in the DLL back
to the application because that would create a circular reference.

Anyone done this or have any ideas?

Thanks,

Eric Renken



我没有必要设置参考使用

ConfirationSettings.AppSettings [],但问题是该方法在2.0中已过时
我现在正试图使用​​2.0设置文件而我想要

知道如何在我的EXE中使用由

EXE引用的DLL中的设置而不将数据传递给它。


Eric Renken


Nicholas Paldino [.NET / C#MVP]" < mv*@spam.guard.caspershouse.com>写在

消息新闻:el ************** @ TK2MSFTNGP11.phx.gbl ...
Right I don''t have to set a reference back for using
ConfirationSettings.AppSettings[], but the problem is that method is
obsolete in 2.0 and I am trying to use 2.0 settings file now and I want to
know how to use the settings from my EXE in a DLL that is referenced by the
EXE without passing that data to it.

Eric Renken

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:el**************@TK2MSFTNGP11.phx.gbl...
Eric,
您需要为应用程序设置一个引用?您在帖子中引用的
行来自System.Configuration命名空间中的ConfigurationSettings
类,而
中的dll当然没有对您的dll的引用,所以应该没有
问题。

我不明白你为什么要改变它。如果您的DLL已加载,
您可以访问文件中的设置与在应用程序域中运行的任何其他程序集相同。

希望这会有所帮助。

-
- Nicholas Paldino [.NET / C#MVP]
- mv*@spam.guard .caspershouse.com

Eric Renken <尔********* @ newsgroup.nospam>在消息中写道
新闻:uc ************** @ tk2msftngp13.phx.gbl ...
Eric,

What do you have to set a reference back to the application for? The
line that you referenced in your post is from the ConfigurationSettings
class in the System.Configuration namespace, and the dll that is in
certainly doesn''t have a reference to your dll, so there should be no
problem.

I don''t see why you would have to change this. If your DLL is loaded,
you can access the settings in the file the same as any other assembly
running in the app domain.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Eric Renken" <Er*********@newsgroup.nospam> wrote in message
news:uc**************@tk2msftngp13.phx.gbl...
我目前在我的1.1中使用这样的语句代码。

System.Configuration.ConfigurationSettings.AppSett ings [" jobclock.net" ]

我在应用程序引用的DLL中使用它。
应用程序在其app.config文件中包含此数据。我想将
切换到2.0中的新设置文件,但我不知道是否可以从不同的DLL访问这些
设置。我不能在DLL中对应用程序进行引用,因为这会创建一个循环引用。

任何人都这样做或有任何想法?
谢谢,

Eric Renken
I currently use statements like this in my 1.1 code.

System.Configuration.ConfigurationSettings.AppSett ings[ "jobclock.net" ]

I use this in DLLs that are referenced by the application. The
application has this data in its app.config file. I would like to switch
to the new Setting files in 2.0, but I don''t know if I can access these
settings from a different DLL. I can''t make a reference in the DLL back
to the application because that would create a circular reference.

Anyone done this or have any ideas?

Thanks,

Eric Renken




嗨Eric,

据我所知,如果是EXE引用的
,我们无法在DLL中获取应用程序设置。您必须将.EXE中的设置传递给DLL,并将
保存在静态变量中。当调用需要

设置的方法时,我们可以将其作为参数传递或让方法直接从

获取静态变量。


HTH。


Kevin Yu

=======

"此帖子已提供按现状没有保证,也没有赋予

权利。

Hi Eric,

As far as I know, we cannot get the app setting in the DLL if it is
referenced by an EXE. You have to pass the setting from .EXE to the DLL and
save it in a static variable. When calling the method that needs the
setting, we can pass it as an argument or let the method get directly from
the static variable.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."


这篇关于在应用程序C#2.0中使用设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆