使用 MS Enterprise Library 5.0 创建类型化配置类

发布于 2024-09-28 19:21:35 字数 919 浏览 0 评论 0原文

我有一个 ASP.Net 4.0 Web 应用程序,我需要为其创建类型化配置类。我的意思如下:

class SettingsClass
{
    int count;
    string name;
    decimal amount;
}

应该映射到配置文件为:

<MyAppSettings>
    <xmlSerializationSection type="...">
        <SettingsClass>
            <count>2<count>
            <name>Moiz</name>
            <decimal>10.66</decimal>
        </SettingsClass>
    </xmlSerializationSection>
</MyAppSettings>

配置文件在 web.config 中通过配置部分进行如下标识(将 ColorSettings 读取为 MyAppSettings) web.config 中的配置部分

这在 ASP.Net 2.0 和 Enterprise Library 1.0 中是直接的,

我正在尝试实现相同的目标ASP.Net 4.0 和 Enterprise Library 5.0 中的东西。但是,5.0 版企业库控制台的工作方式与 1.0 版企业库配置工具的工作方式不同。

我想知道我应该如何在 .Net 4.0 和 Ent Lib 5.0 中实现同样的要求。是否有更好的方法可以处理 .Net 4.0/ent lib 5.0 中类型化类的配置?

I have a ASP.Net 4.0 web application for which I need to create typed configuration class. What I mean is as follows:

class SettingsClass
{
    int count;
    string name;
    decimal amount;
}

Should map to the configuration file as:

<MyAppSettings>
    <xmlSerializationSection type="...">
        <SettingsClass>
            <count>2<count>
            <name>Moiz</name>
            <decimal>10.66</decimal>
        </SettingsClass>
    </xmlSerializationSection>
</MyAppSettings>

The configuration file was identified in the web.config as follows by a configuration section (Read ColorSettings as MyAppSettings)
Configuration section in web.config

This was straight forward in ASP.Net 2.0 and Enterprise library 1.0

I am trying to achieve the same thing in ASP.Net 4.0 and Enterprise Library 5.0. However, the Enterprise Library Console of 5.0 does not work the same way as the Enterprise Library Configuration tool of 1.0.

I wanted to know how I should be going about in .Net 4.0 and Ent Lib 5.0 to achieve this same requirement. Is there a better means by which configuration can be handled for typed class in .Net 4.0/ent lib 5.0?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不喜欢何必死缠烂打 2024-10-05 19:21:35

XML 配置在 .NET 2.0 中发生了根本性的变化(而且并没有真正变得更好)。您将需要查看 System.Configuration 命名空间和其中的类。这不再是一个企业库问题,而是一个关于框架本身的问题。

XML configuration changed radically (and not really for the better) in .NET 2.0. You're going to want to look at the System.Configuration namespace and the classes there. This is no longer an enterprise library question, but really one about the framework itself.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文