public static TextNode ParseTypeIntoNodes(this string typeDef) { if (string.IsNullOrEmpty(typeDef)) return null; var node = new TextNode(); var lastBlockPos = typeDef.IndexOf('<'); if (lastBlockPos >= 0) { node.Text = typeDef.Substring(0, lastBlockPos); var blockStartingPos = new Stack<int>(); blockStartingPos.Push(lastBlockPos); while (lastBlockPos != -1 || blockStartingPos.Count == 0) { var nextPos = typeDef.IndexOfAny(blockChars, lastBlockPos + 1); if (nextPos == -1) break; var blockChar = typeDef.Substring(nextPos, 1); if (blockChar == "<") { blockStartingPos.Push(nextPos); } else { var startPos = blockStartingPos.Pop(); if (blockStartingPos.Count == 0) { var endPos = nextPos; var childBlock = typeDef.Substring(startPos + 1, endPos - startPos - 1); var args = SplitGenericArgs(childBlock); foreach (var arg in args) { if (arg.IndexOfAny(blockChars) >= 0) { var childNode = ParseTypeIntoNodes(arg); if (childNode != null) { node.Children.Add(childNode); } } else { node.Children.Add(new TextNode { Text = arg }); } } } } lastBlockPos = nextPos; } } else { node.Text = typeDef; } return node; }
public static TextNode ParseTypeIntoNodes(this string typeDef) { if (string.IsNullOrEmpty(typeDef)) { return(null); } var node = new TextNode(); var lastBlockPos = typeDef.IndexOf('<'); if (lastBlockPos >= 0) { node.Text = typeDef.Substring(0, lastBlockPos); var blockStartingPos = new Stack <int>(); blockStartingPos.Push(lastBlockPos); while (lastBlockPos != -1 || blockStartingPos.Count == 0) { var nextPos = typeDef.IndexOfAny(blockChars, lastBlockPos + 1); if (nextPos == -1) { break; } var blockChar = typeDef.Substring(nextPos, 1); if (blockChar == "<") { blockStartingPos.Push(nextPos); } else { var startPos = blockStartingPos.Pop(); if (blockStartingPos.Count == 0) { var endPos = nextPos; var childBlock = typeDef.Substring(startPos + 1, endPos - startPos - 1); var args = SplitGenericArgs(childBlock); foreach (var arg in args) { if (arg.IndexOfAny(blockChars) >= 0) { var childNode = ParseTypeIntoNodes(arg); if (childNode != null) { node.Children.Add(childNode); } } else { node.Children.Add(new TextNode { Text = arg }); } } } } lastBlockPos = nextPos; } } else { node.Text = typeDef; } return(node); }