MattP
Well-known member
I'm converting the Prism Navigation Framework from C# to VB.NET and have 1 issue with an EventHandler that's giving me headaches.
The original Interface:
The converted interface:
Then here's the original implementation in PrismModuleLoadingService.cs:
And the conversion:
These both compile fine.
The problem is when I convert the file PrismViewLoadingService.cs
Here's the original constructor:
And the conversion:
The problem is with the AddHandler line on the conversion. I'm getting the message that ModuleDownloadStateChanged is not an event of Infrastructure.IPrismModuleLoadingService. Well, yeah...it's an EventHandler.
I have the feeling the solution looks something like this but it's been a long week and the answer is eluding me:
The original Interface:
VB.NET:
using System;
namespace PrismNavigationFramework.Infrastructure
{
public interface IPrismModuleLoadingService
{
bool ModuleNeedsToBeLoaded(string moduleName);
void LoadModule(string moduleUrlFriendlyName);
EventHandler<ModuleDownloadStateChangedEventArgs> ModuleDownloadStateChanged { get; set; }
}
}
The converted interface:
VB.NET:
Namespace Infrastructure
Public Interface IPrismModuleLoadingService
Function ModuleNeedsToBeLoaded(ByVal moduleName As String) As Boolean
Sub LoadModule(ByVal moduleUrlFriendlyName As String)
Property ModuleDownloadStateChanged() As EventHandler(Of ModuleDownloadStateChangedEventArgs)
End Interface
End Namespace
Then here's the original implementation in PrismModuleLoadingService.cs:
VB.NET:
public EventHandler<ModuleDownloadStateChangedEventArgs> ModuleDownloadStateChanged
{
get;
set;
}
And the conversion:
VB.NET:
Public Property ModuleDownloadStateChanged() As EventHandler(Of ModuleDownloadStateChangedEventArgs) _
Implements IPrismModuleLoadingService.ModuleDownloadStateChanged
These both compile fine.
The problem is when I convert the file PrismViewLoadingService.cs
Here's the original constructor:
VB.NET:
public PrismViewLoadingService(
IPrismNavigationConfiguration prismNavigationConfiguration,
IRegionManager regionManager,
IViewCreationService viewCreationService,
IViewToUrlMappingRegistrationService viewToUrlMappingService,
IViewNavigationContextInformationParsingService viewNavigationInformationParsingService,
IPrismModuleLoadingService moduleLoadingService,
IModuleNamesRegistrationService moduleNamesRegistrationService,
IViewInitializationService viewInitializationService,
IKeyValuePairsParsingService keyValuePairsParsingService
)
{
_prismNavigationConfiguration = prismNavigationConfiguration;
_regionManager = regionManager;
_viewCreationService = viewCreationService;
_viewToUrlMappingService = viewToUrlMappingService;
_viewNavigationInformationParsingService = viewNavigationInformationParsingService;
_moduleLoadingService = moduleLoadingService;
_moduleNamesRegistrationService = moduleNamesRegistrationService;
_viewInitializationService = viewInitializationService;
_keyValuePairsParsingService = keyValuePairsParsingService;
this._moduleLoadingService.ModuleDownloadStateChanged += this.ModuleDownloadStateChanged;
}
And the conversion:
VB.NET:
Public Sub New(ByVal prismNavigationConfiguration As IPrismNavigationConfiguration,
ByVal regionManager As IRegionManager,
ByVal viewCreationService As IViewCreationService,
ByVal viewToUrlMappingService As IViewToUrlMappingRegistrationService,
ByVal viewNavigationInformationParsingService As IViewNavigationContextInformationParsingService,
ByVal moduleLoadingService As IPrismModuleLoadingService,
ByVal moduleNamesRegistrationService As IModuleNamesRegistrationService,
ByVal viewInitializationService As IViewInitializationService,
ByVal keyValuePairsParsingService As IKeyValuePairsParsingService)
_prismNavigationConfiguration = prismNavigationConfiguration
_regionManager = regionManager
_viewCreationService = viewCreationService
_viewToUrlMappingService = viewToUrlMappingService
_viewNavigationInformationParsingService = viewNavigationInformationParsingService
_moduleLoadingService = moduleLoadingService
_moduleNamesRegistrationService = moduleNamesRegistrationService
_viewInitializationService = viewInitializationService
_keyValuePairsParsingService = keyValuePairsParsingService
AddHandler _moduleLoadingService.ModuleDownloadStateChanged, AddressOf ModuleDownloadStateChanged
End Sub
The problem is with the AddHandler line on the conversion. I'm getting the message that ModuleDownloadStateChanged is not an event of Infrastructure.IPrismModuleLoadingService. Well, yeah...it's an EventHandler.
I have the feeling the solution looks something like this but it's been a long week and the answer is eluding me:
VB.NET:
Dim handler = _moduleLoadingService.ModuleDownloadStateChanged
If handler IsNot Nothing Then
'...
End If