You create a class library that is used by applications in three departments of your Braindumps.

You create a class library that is used by applications in three departments of your Braindumps.
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>Braindumps</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 = ConfigurationManager.AppSettings("name")
    dept.manager = _
    ConfigurationManager.AppSettings("manager")
    End Sub
    End Class
B. 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
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").InnerText
    Return dept
    End Function
    End Class
D. 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


Answer: C 


No comments:

Post a Comment