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 name As String

Public manager As String

End Class

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
Inherits ConfigurationElement

Protected Overrides Sub DeserializeElement( _
ByVal reader As XmlReader, _
ByVal serializeCollectionKey As Boolean)
Dim dept As Department = New Department()
dept.name = reader.GetAttribute("name")
dept.manager = reader.GetAttribute("manager")
End Sub
End Class 

B Public Class deptHandler
Implements IConfigurationSectionHandler
Public Function Create(ByVal parent As Object, _
ByVal configContext As Object, _
ByVal section As System.Xml.XmlNode) As Object _
Implements IConfigurationSectionHandler.Create

Dim dept As Department = new Department()
dept.name = section.Attributes("name").Value
dept.manager = section.Attributes("manager").Value
Return dept
End Function
End Class 

C Public Class deptHandler
Implements IConfigurationSectionHandler
Public Function Create(ByVal parent As Object, _
ByVal configContext As Object, _
ByVal section As System.Xml.XmlNode) As Object _
Implements IConfigurationSectionHandler.Create
Dim dept As Department = new Department()
dept.name = section.SelectSingleNode("name").InnerText dept.manager = _ section.SelectSingleNode("manager").InnerTex
Return dept
End Function
End Class 

D Public Class deptElement
Inherits ConfigurationElement
Protected Overrides Sub DeserializeElement( _
ByVal reader As XmlReader, _
ByVal serializeCollectionKey As Boolean)
Dim dept As Department = New Department(
) dept.name = ConfigurationManager.AppSettings("name") "A Composite Solution With Just One Click"-
Certification Guaranteed 189 Microsoft 70-536 Exam

dept.manager = _
ConfigurationManager.AppSettings("manager")
End Sub
End Class 

+ Answer
+ Report
Total Preview: 752

Copyright © 2024. Powered by Intellect Software Ltd