Skip to content

Commit

Permalink
Use switch expression
Browse files Browse the repository at this point in the history
  • Loading branch information
luiscantero committed Oct 29, 2024
1 parent a1eae7d commit 19b79e0
Showing 1 changed file with 10 additions and 30 deletions.
40 changes: 10 additions & 30 deletions src/PluginNodes/UserDefinedPluginNodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,35 +182,15 @@ public void CreateBaseVariable(NodeState parent, ConfigNode node)
_plcNodeManager.CreateBaseVariable(parent, node.NodeId, node.Name, new NodeId((uint)nodeDataType), node.ValueRank, accessLevel, node.Description, NamespaceType.OpcPlcApplications, node?.Value);
}

private static object UpdateArrayValue(ConfigNode node, JArray jArrayValue)
{
object arrayValue = jArrayValue;

if (node.DataType == "String")
{
arrayValue = jArrayValue.ToObject<string[]>();
}

if (node.DataType == "Boolean")
{
arrayValue = jArrayValue.ToObject<bool[]>();
}

if (node.DataType == "Float")
{
arrayValue = jArrayValue.ToObject<float[]>();
}

if (node.DataType == "UInt32")
{
arrayValue = jArrayValue.ToObject<uint[]>();
}

if (node.DataType == "Int32")
{
arrayValue = jArrayValue.ToObject<int[]>();
}

return arrayValue;
private static object UpdateArrayValue(ConfigNode node, JArray jArrayValue)
{
return node.DataType switch {
"String" => jArrayValue.ToObject<string[]>(),
"Boolean" => jArrayValue.ToObject<bool[]>(),
"Float" => jArrayValue.ToObject<float[]>(),
"UInt32" => jArrayValue.ToObject<uint[]>(),
"Int32" => jArrayValue.ToObject<int[]>(),
_ => throw new NotImplementedException($"Node type not implemented: {node.DataType}."),
};
}
}

0 comments on commit 19b79e0

Please sign in to comment.