custom-configuration

Polymorphic custom configuration section

跟風遠走 提交于 2021-01-28 10:33:39
问题 Lets say I have the following configuration section.... <yak> <whaa hello="world" /> </yak> <yak> <whaa hello="world" blot="1" /> </yak> Because the second <whaa> element has the extra attribute on it I want to map it to a sub type of the the type that's mapped to the first <whaa> element. So how do I get polymorphic binding? 回答1: Here's one approach by using a programmatic solution which overrides the OnDeserializeUnrecognizedElement method of the ConfigurationSection class. The base and

Unrecognized element exception with custom C# config

。_饼干妹妹 提交于 2020-01-03 07:31:12
问题 I have the following bits in App.config for a .NET 3.5 Windows Service: <configSections> <section name="ConfigurationServiceSection" type="SomeApp.Framework.Configuration.ConfigurationServiceSection, SomeApp.Framework"/> </configSections> <ConfigurationServiceSection configSource="ConfigSections\configurationServiceSection.config" /> I've got this in configurationServiceSection.config: <ConfigurationServiceSection> <ConfigurationServices> <ConfigurationService name="LocalConfig" host=

Recursive Custom Configuration in c#

梦想的初衷 提交于 2020-01-02 06:21:04
问题 I am trying to create a custom configuration section that follows the following recursive structure: <monitorSettings> <monitor description="description1" /> <monitor description="description2" /> <monitor description="description3"> <monitor description="description3.1" /> <monitor description="description3.2" /> </monitor> </monitorSettings> Is this possible? I am not sure how I would lay out the configuration classes. I have the following for the monitor: public class Monitor :

Recursive Custom Configuration in c#

試著忘記壹切 提交于 2020-01-02 06:20:13
问题 I am trying to create a custom configuration section that follows the following recursive structure: <monitorSettings> <monitor description="description1" /> <monitor description="description2" /> <monitor description="description3"> <monitor description="description3.1" /> <monitor description="description3.2" /> </monitor> </monitorSettings> Is this possible? I am not sure how I would lay out the configuration classes. I have the following for the monitor: public class Monitor :

Read web.config section to List

寵の児 提交于 2019-12-23 13:08:09
问题 I have this in a web.config : <MySection> <Setting1 Value="10" /> <Setting2 Value="20" /> <Setting3 Value="30" /> <Setting4 Value="40" /> </MySection> I'd like read the all section "MySection" and get all value to a List<string> (ex : "10","20","30") Thanks, 回答1: First of all, I recommend use to use Unity Configuration. Code: public class MySection : ConfigurationSection { protected static ConfigurationPropertyCollection properties = new ConfigurationPropertyCollection(); private static

TestNG: how do I run a custom TestNG.XML File programmatically

家住魔仙堡 提交于 2019-12-12 16:03:22
问题 I browsed through several different threads and websites (as well as the TestNG API) looking for how to run and create custom tests. I haven't found (or not understood) how I can run a custom testng.xml (test suite) programmatically. I have created a testng.xml file looking like this: <?xml version="1.0" encoding="UTF-8"?> <suite name="The Login Suite'" verbose="1" > <test name="Some login check" > <classes> <class name="tests.first_login"/> </classes> </test> <test name="Another login check"

ConfigurationElementCollection with a number of ConfigurationElements of different type

断了今生、忘了曾经 提交于 2019-12-05 17:10:00
问题 Is it possible to have a CollectionElementCollection with a number of different by type CollectionElements, e.g.: <collection> <add type="MyType1, MyLib" Type1SpecificProp="1" /> <add type="MyType2, MyLib" Type2SpecificProp="2" /> </collection I have all classes required for such solution: class MyCollection : ConfigurationElementCollection { } class MyElement : ConfigurationElement { } class MyType1 : MyElement { } class MyType2 : MyElement { } ... etc but when I start my application I'm

Recursive Custom Configuration in c#

六月ゝ 毕业季﹏ 提交于 2019-12-05 15:27:40
I am trying to create a custom configuration section that follows the following recursive structure: <monitorSettings> <monitor description="description1" /> <monitor description="description2" /> <monitor description="description3"> <monitor description="description3.1" /> <monitor description="description3.2" /> </monitor> </monitorSettings> Is this possible? I am not sure how I would lay out the configuration classes. I have the following for the monitor: public class Monitor : ConfigurationElement { [ConfigurationProperty("description", IsRequired = true)] public String Description { get {

ConfigurationElementCollection with a number of ConfigurationElements of different type

邮差的信 提交于 2019-12-04 02:09:51
Is it possible to have a CollectionElementCollection with a number of different by type CollectionElements, e.g.: <collection> <add type="MyType1, MyLib" Type1SpecificProp="1" /> <add type="MyType2, MyLib" Type2SpecificProp="2" /> </collection I have all classes required for such solution: class MyCollection : ConfigurationElementCollection { } class MyElement : ConfigurationElement { } class MyType1 : MyElement { } class MyType2 : MyElement { } ... etc but when I start my application I'm getting next predictable error: Unrecognized attribute 'Type1SpecificProp'. because Type1SpecificProp is

How do I make my custom config section behave like a collection?

会有一股神秘感。 提交于 2019-12-03 11:31:34
问题 How would I need to write my custom ConfigurationSection so that it is both a section handler and a configuration element collection? Normally, you have one class that inherits from ConfigurationSection , which then has a property that is of a type that inherits from ConfigurationElementCollection , which then returns elements of a collection of a type that inherits from ConfigurationElement . To configure that, you would then need XML that looks something like this: <customSection>