|
|
How Do I...Make a ResourceReader?There are two steps to creating a custom resource reader. The first step is to create a class that implements IResourceReader, which requires a Close method and an implementation for GetEnumerator. The following code example demonstrates creating a basic class that implements IResourceReader.
Class CustomReader : Implements IResourceReader
Public Sub Close()
// Close any items allocated for the resources
End Sub
Public Function IEnumerable_GetEnumerator() As IEnumerator Implements IEnumerable.GetEnumerator
return GetEnumerator();
End Function
Public Function GetEnumerator() As IDictionaryEnumerator Implements IResourceReader.GetEnumerator
// Return an enumerator for the resource collection
End Function
End Class
VB
The next step is to generate a custom resource manager that uses the custom reader. To do this, create a derived class of ResourceManager, and override InternalGetResourceSet to allow for the creation of the resource reader defined earlier. The following code example demonstrates a simple ResourceManager.
Public Class CustomManager : Inherits ResourceManager
Protected Overrides Function InternalGetResourceSet( culture As CultureInfo, _
createIfNotExists As Boolean, _
tryParents As Boolean ) As ResourceSet
Return new ResourceSet( new CustomReader() )
End Function
End ClassVB
Example
|