Add safety check for casting device into interface

(device as IRoutingInputsOutputs).InputPorts will throw Exception on accessing InputPorts property if device do not implement such interface.
This commit is contained in:
Maxim Batourine
2021-01-07 19:31:24 -05:00
parent 522c107ce6
commit 08fe408dc1

View File

@@ -360,9 +360,9 @@ namespace PepperDash.Essentials.Core
{ {
var device = GetDeviceForKey(s); var device = GetDeviceForKey(s);
if (device == null) return; if (device == null) return;
var inputPorts = (device as IRoutingInputsOutputs).InputPorts; var inputPorts = ((device as IRoutingInputs) != null) ? (device as IRoutingInputs).InputPorts : null;
var outputPorts = (device as IRoutingInputsOutputs).OutputPorts; var outputPorts = ((device as IRoutingOutputs) != null) ? (device as IRoutingOutputs).OutputPorts : null;
if (inputPorts != null) if (inputPorts != null)
{ {
Debug.Console(0, "Device {0} has {1} Input Ports:", s, inputPorts.Count); Debug.Console(0, "Device {0} has {1} Input Ports:", s, inputPorts.Count);