标签: configurationsection

如何将TypeConverters与ConfigurationSection一起使用?

所以我有一个ConfigurationSection/ConfigurationElementCollection,其配置如下:

<mimeFormats>
    <add mimeFormat="text/html" />
</mimeFormats>
Run Code Online (Sandbox Code Playgroud)

以下是我处理mimeFormats的方法:

 public class MimeFormatElement: ConfigurationElement
{
    #region Constructors
    /// <summary>
    /// Predefines the valid properties and prepares
    /// the property collection.
    /// </summary>
    static MimeFormatElement()
    {
        // Predefine properties here
        _mimeFormat = new ConfigurationProperty(
            "mimeFormat",
            typeof(MimeFormat),
            "*/*",
            ConfigurationPropertyOptions.IsRequired
        );
    }
    private static ConfigurationProperty _mimeFormat;
    private static ConfigurationPropertyCollection _properties;

    [ConfigurationProperty("mimeFormat", IsRequired = true)]
    public MimeFormat MimeFormat
    {
        get { return (MimeFormat)base[_mimeFormat]; }
    }
}

public class MimeFormat
{
    public string Format
    {
        get
        {
            return …
Run Code Online (Sandbox Code Playgroud)

c# system.configuration configurationsection .net-4.0 type-conversion

5
推荐指数
1
解决办法
4573
查看次数

如何遍历configurationSection

我的Web.config文件中有以下部分:

<configSections>
    <section name="mySection" type="myNameSpace, myProject"/>
</configSections>


<mySection>
    <city id="ny" type="nameSpace1" />
    <city id="dc" type="nameSpace2" />
    <city id="nj" type="nameSpace3" />
</mySection>
Run Code Online (Sandbox Code Playgroud)

我需要编写循环遍历cities给定的代码id并返回type.

 if the given id = "ny" --> return nameSpace1
 if the given id = "dc" --> return nameSpace2
 if the given id = "nj" --> return nameSpace3
Run Code Online (Sandbox Code Playgroud)

c# configurationsection

5
推荐指数
1
解决办法
1728
查看次数

帮助使用ConfigurationSection正确读取配置文件

我正在尝试使用ConfigurationSection和ConfigurationElementCollection创建从我的配置文件中读取的类,但是我很难过.

作为配置的示例:


<PaymentMethodSettings>
  <PaymentMethods>
    <PaymentMethod name="blah blah" code="1"/>
    <PaymentMethod name="blah blah" code="42"/>
    <PaymentMethod name="blah blah" code="43"/>
    <Paymentmethod name="Base blah">
      <SubPaymentMethod name="blah blah" code="18"/>
      <SubPaymentMethod name="blah blah" code="28"/>
      <SubPaymentMethod name="blah blah" code="38"/>
    </Paymentmethod>
  </PaymentMethods>
</PaymentMethodSettings>
Run Code Online (Sandbox Code Playgroud)

c# xml web-config configurationsection

4
推荐指数
1
解决办法
4922
查看次数

将web.config部分读取到List

我在web.config中有这个:

<MySection>
    <Setting1 Value="10" />
    <Setting2 Value="20" />
    <Setting3 Value="30" />
    <Setting4 Value="40" />
</MySection>
Run Code Online (Sandbox Code Playgroud)

我想阅读所有部分"MySection"并获取所有值List<string>(例如:"10","20","30")

谢谢,

.net c# configuration configurationsection custom-configuration

4
推荐指数
1
解决办法
7194
查看次数

如何解决"无法识别的元素'elementName'.(第x行)(第x行)"?

我有以下代码

var section = new CustomConfigurationSection();
section.SectionInformation.Type = "System.Configuration.NameValueFileSectionHandler";
section.SectionInformation.SetRawXml(sectionXml);
configuration.Sections.Add(sectionName, section);
Run Code Online (Sandbox Code Playgroud)

最后一行抛出:

ConfigurationErrorsException执行monitor的配置节处理程序时发生错误.

内部异常:

无法识别的元素'屏幕'.(第1行)(第1行)

CustomConfigurationSection的定义:

public class CustomConfigurationSection: ConfigurationSection
{
    public CustomConfigurationSection()
    {
    }
}
Run Code Online (Sandbox Code Playgroud)

configuration是自定义类的实例,它具有名为Sections的属性,其类型为"ConfigurationSectionCollection".

sectionXml中传入的xml是:

<monitor>
  <screens>
    <screen>
      <regions>
        <region>
          <labelCoordinates />
          <startupApplication>Internet</startupApplication>
          <color />
          <width>426</width>
          <height>266</height>
          <x1>0</x1>
          <x2>0</x2>
          <y1>0</y1>
          <y2>0</y2>
        </region>
      </regions>
      <height>800</height>
      <width>1280</width>
    </screen>
    <screen>
      <regions />
      <height>0</height>
      <width>0</width>
    </screen>
  </screens>
</monitor>
Run Code Online (Sandbox Code Playgroud)

我怎样才能让它发挥作用?

c# configurationsection

3
推荐指数
1
解决办法
5116
查看次数

将自定义属性添加到app.config中的Custom Provider Configuration Section

我正在关注如何在.NET中创建Provider框架的这篇伟大文章

基本上,本文大致解释了如何最终得到如下配置文件:

   <configuration>
     <configSections>
        <section name="data" type="DataProviderConfigurationSection" />
      </configSections>
      <data defaultProvider="MyDataProvider">
         <providers>
            <add name="MydataProvider" type="MyDataProvider"  />
         </providers>
      </data>
   </configuration>
Run Code Online (Sandbox Code Playgroud)

<add/>元素允许你定义一个供应商.

但是,我想知道如何add使用自定义属性扩展条目.

例如:

<providers>
  <add name="MydataProvider" type="MyDataProvider" myProperty="myValue" myProperty2="myValue2" ... />
</providers>
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激.

c# provider configurationsection

3
推荐指数
1
解决办法
6763
查看次数

ConfigurationSection多个枚举值

有没有办法在配置部分设置多个枚举值?

就像在.net中一样 object.Filter = Filter.Update | Filter.Create;

<wacther filter="update, created"/>
Run Code Online (Sandbox Code Playgroud)

是否支持这样的东西?

.net c# configuration configurationsection configurationelement

3
推荐指数
1
解决办法
6462
查看次数

为什么ConfigurationSection需要用字符串查找?

ConfigurationSection我在网上找到的例子(例如)都有如下代码:

public class ConnectionSection  : ConfigurationSection
{
    [ConfigurationProperty("Servers")]
    public ServerAppearanceCollection ServerElement
    {
        get { return ((ServerAppearanceCollection)(base["Servers"])); }
        set { base["Servers"] = value; }
    }
}
Run Code Online (Sandbox Code Playgroud)

为什么使用方括号从基数访问值"Servers"?是从xml创建此对象时使用的setter,还是用于覆盖xml文件中的值的setter?如果是这样,为什么在此属性上设置属性?

.net c# configurationsection

3
推荐指数
1
解决办法
132
查看次数

System.Configuration.ConfigurationSection在类库下不可用

我正在将一个功能从我的App_Code目录迁移到一个单独的项目,该项目将构建一个由我的Web应用程序引用的类库.我在App_Code片段中的一个类继承了System.Configuration.ConfigurationSection形式,如下所示:

Imports System.Configuration
Imports System.Web.Configuration
Imports Microsoft.VisualBasic

Namespace P10.WebStore

#Region "WebStore Section"
    Public Class WebStoreSection
        Inherits ConfigurationSection
Run Code Online (Sandbox Code Playgroud)

我绝对不能让项目将ConfigurationSection识别为一个类.我没有关于这个课程的谷歌提到必须做任何特别的事情来使用它.是因为这是一个类库而不是.exe或somethign?我很难过.

vb.net asp.net configurationsection

2
推荐指数
1
解决办法
3509
查看次数

在Magento中添加管理配置选项卡图像

我想添加图片

管理面板 - >系统 - >配置 - >"左侧菜单选项卡"(此处)

只是看下面的图像我想做什么:

在此输入图像描述

任何解决方案.. ??

提前致谢.

configuration image configurationsection magento magento-1.7

2
推荐指数
1
解决办法
1654
查看次数

在Java中读取配置

我最近开始使用Java.我试图找到一种以易于阅读的方式指定应用程序配置值的好方法.我希望能够创建基本配置文件,然后包含在派生配置文件中,该文件也允许覆盖基本文件中的值.

不确定java属性文件是否提供第二个功能.在google上搜索后,我发现了apache commons配置ini4j,但我不确定它们是否得到了积极维护或有多少人实际使用它们.

java parsing configurationsection

1
推荐指数
1
解决办法
584
查看次数