Question:
You create a class library that is used by applications in three departments of your company. The library contains a Department class with the following definition.
public class Department {
public string name;
public string manager;
}
Each application uses a custom configuration section to store department-specific values in the application configuration file as shown in the following code.
<Department>
<name>Hardware</name>
<manager>Amy</manager>
</Department>
You need to write a code segment that creates a Department object instance by using the field values retrieved from the application configuration file.
Which code segment should you use?
A public class deptElement: ConfigurationElement {
protected override void DeserializeElement(
XmlReader reader, bool serializeCollectionKey) {
Department dept = new Department();
dept.name = reader.GetAttribute("name");
dept.manager = reader.GetAttribute("manager");
}
}B public class deptHandler : IConfigurationSectionHandler { public object Create(object parent, object configContext, System.Xml.XmlNode section) {
Department dept = new Department();
dept.name = section.Attributes["name"].Value;
dept.manager = section.Attributes["manager"].Value;
return dept;
}
}C public class deptElement : ConfigurationElement {
protected override void DeserializeElement(
XmlReader reader, bool serializeCollectionKey) {
Department dept = new Department(); dept.name = ConfigurationManager.AppSettings["name"]; dept.manager = ConfigurationManager.AppSettings["manager"];
return dept;
}
}D public class deptHandler : IConfigurationSectionHandler { public object Create(object parent, object configContext, System.Xml.XmlNode section) {
Department dept = new Department();
dept.name = section.SelectSingleNode("name").InnerText; dept.manager =
section.SelectSingleNode("manager").InnerText;
return dept;
}
}
+ AnswerD
+ Report