From b3ae1519e2f93ea5e8f66461283c2bb9d9a704d8 Mon Sep 17 00:00:00 2001 From: parallelbgls Date: Tue, 7 Mar 2017 20:34:47 +0800 Subject: [PATCH] Tag Union Fix. --- Modbus.Net/Modbus.Net.OPC/OpcConnector.cs | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/Modbus.Net/Modbus.Net.OPC/OpcConnector.cs b/Modbus.Net/Modbus.Net.OPC/OpcConnector.cs index 69cf2f6..d78d95e 100644 --- a/Modbus.Net/Modbus.Net.OPC/OpcConnector.cs +++ b/Modbus.Net/Modbus.Net.OPC/OpcConnector.cs @@ -54,26 +54,37 @@ namespace Modbus.Net.OPC return AsyncHelper.RunSync(() => SendMsgAsync(message)); } - private string[] SplitTag(string tag, char split) + private void FoldWith(List tagSplitList, char splitChar, char startChar, char endChar) { - var tagSplitList = tag.Split(split).ToList(); for (int i = 0; i < tagSplitList.Count; i++) { - if (tagSplitList[i].Contains("(")) + if (tagSplitList[i].Count(ch=>ch == startChar) > tagSplitList[i].Count(ch=>ch == endChar)) { - for (int j = i; j < tagSplitList.Count; j++) + for (int j = i + 1; j < tagSplitList.Count; j++) { - if (tagSplitList[j].Contains(")")) + if (tagSplitList[j].Contains(endChar)) { for (int k = i + 1; k <= j; k++) { - tagSplitList[i] += split + tagSplitList[i + 1]; + tagSplitList[i] += splitChar + tagSplitList[i + 1]; tagSplitList.RemoveAt(i + 1); } + i--; + break; } } } } + } + + private string[] SplitTag(string tag, char split) + { + var tagSplitList = tag.Split(split).ToList(); + + FoldWith(tagSplitList, split, '(', ')'); + FoldWith(tagSplitList, split, '[', ']'); + FoldWith(tagSplitList, split, '{', '}'); + return tagSplitList.ToArray(); }