所以我有一个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
我的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) 我正在尝试使用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) 我在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
我有以下代码
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)
我怎样才能让它发挥作用?
我正在关注如何在.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)
任何帮助将不胜感激.
有没有办法在配置部分设置多个枚举值?
就像在.net中一样 object.Filter = Filter.Update | Filter.Create;
<wacther filter="update, created"/>
Run Code Online (Sandbox Code Playgroud)
是否支持这样的东西?
.net c# configuration configurationsection configurationelement
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?如果是这样,为什么在此属性上设置属性?
我正在将一个功能从我的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?我很难过.
我想添加图片
管理面板 - >系统 - >配置 - >"左侧菜单选项卡"(此处)
只是看下面的图像我想做什么:

任何解决方案.. ??
提前致谢.
configuration image configurationsection magento magento-1.7
我最近开始使用Java.我试图找到一种以易于阅读的方式指定应用程序配置值的好方法.我希望能够创建基本配置文件,然后包含在派生配置文件中,该文件也允许覆盖基本文件中的值.
不确定java属性文件是否提供第二个功能.在google上搜索后,我发现了apache commons配置和ini4j,但我不确定它们是否得到了积极维护或有多少人实际使用它们.