I am adding a new section "users" to app.config. I have added config handler to read values from app.config. The problem is I am always getting null when I try to read users. Below are files, please help me if I miss any thing.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="specFlow" type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow" />
<section name="users" type="Browser_Feature_Tests.UserConfigHandler, Browser_Feature_Tests" />
</configSections>
<specFlow>
<users>
<user usertype="csr" username="abc" password="xxx" />
<user usertype="admin" username="xyz" password="xxx" />
</users>
</configuration>
namespace Browser_Feature_Tests
{
public class UserConfigHandler : ConfigurationSection
{
[ConfigurationProperty("users")]
[ConfigurationCollection(typeof(UserCollection), AddItemName = "user")]
public UserCollection Users
{
get { return (UserCollection)base["users"]; }
set { this["users"] = value; }
}
}
public class UserCollection : ConfigurationElementCollection
{
protected override ConfigurationElement CreateNewElement()
{
return new UserElement();
}
protected override object GetElementKey(ConfigurationElement element)
{
return ((UserElement)element).UserType;
}
}
public class UserElement : ConfigurationElement
{
[ConfigurationProperty("usertype", IsRequired=true)]
public string UserType
{
get { return (string)this["usertype"]; }
set { this["usertype"] = value; }
}
[ConfigurationProperty("username", IsRequired = true)]
public string UserName
{
get { return (string)this["username"]; }
set { this["username"] = value; }
}
[ConfigurationProperty("password", IsRequired = true)]
public string Password
{
get { return (string)this["password"]; }
set { this["password"] = value; }
}
}
}