Use reflection instead of Activator to create new driver instance
This commit is contained in:
@@ -86,7 +86,12 @@ namespace TestApp
|
||||
|
||||
if (_Driver is null || !_Driver.GetType().Equals(driverType))
|
||||
{
|
||||
var newDriverObject = Activator.CreateInstance(driverType);
|
||||
var newDriverConstructor = driverType.GetConstructor(Array.Empty<Type>());
|
||||
if (newDriverConstructor is null) {
|
||||
throw new InvalidOperationException($"Type {driverType} does not have a parameterless constructor!");
|
||||
}
|
||||
|
||||
var newDriverObject = newDriverConstructor.Invoke(null, Array.Empty<object>());
|
||||
if (newDriverObject is null)
|
||||
{
|
||||
throw new InvalidOperationException("Could not instantiate driver!");
|
||||
|
||||
Reference in New Issue
Block a user