0
我想要一个配置部分,看起来像这样:ConfigurationManager中 - 配置部分错误
<MailMessage>
<from value="[email protected]" />
<subject value ="Subject goes here" />
<body value="Hello. You've got mail!" />
</MailMessage>
而且我在这个环节上的第二个答案中实现的类,如: How to implement a ConfigurationSection with a ConfigurationElementCollection
现在对我来说,部分MAILMESSAGE的元素是不是集合,但是这不应该是一个问题,但我收到的错误,当我尝试访问属性:
Unrecognized element 'from'
我得到了部分的代码:
private static MailMessageSection emailSection = ConfigurationManager.GetSection("MailMessage") as MailMessageSection;
这里是要素的实施:
public class MailMessageSection : ConfigurationSection
{
[ConfigurationProperty("from")]
public FromElement From
{
get { return base["from"] as FromElement; }
}
[ConfigurationProperty("subject")]
public SubjectElement Subject
{
get { return base["subject"] as SubjectElement; }
}
[ConfigurationProperty("body")]
public BodyElement Body
{
get { return base["body"] as BodyElement; }
}
}
public class FromElement : ConfigurationElement
{
[ConfigurationProperty("value")]
public string From
{
get { return base["value"] as string; }
}
}
public class SubjectElement : ConfigurationElement
{
[ConfigurationProperty("value")]
public string Subject
{
get { return base["value"] as string; }
}
}
public class BodyElement : ConfigurationElement
{
[ConfigurationProperty("value")]
public string Body
{
get { return base["value"] as string; }
}
}
任何想法可能是错误的?谢谢你的时间!