我正在寻找一种方法来处理更复杂的结果缓冲区,如深度嵌套的列表。我希望它能把结果缓冲区转换成一个List
。如果有人有代码,他们想分享我会很感激。这是我目前掌握的情况。
- ///
- /// Converts a to . If the Lisp arguments are below the minimum or above the maximum required, an exception will be thrown.
- ///
- ///
- ///
- ///
- ///
- ///
- public static List HandleLispArguments(ResultBuffer arguments, int minimum, int maximum)
- {
- if (arguments == null)
- throw new System.Exception("too few arguments");
- TypedValue[] rawArgs = arguments.AsArray();
- List Arguments = new List();
-
- // List Depth
- int depth = 0;
-
- Action, int, object> Add = null;
-
- Add = (list, depth, item) =>
- {
- if (depth == 0)
- list.Add(item);
- else
- Add((List)list[list.Count - 1], --depth, item);
- };
- foreach (TypedValue item in rawArgs)
- {
- object selected = item;
- if (item.TypeCode == (short)LispDataType.ListBegin)
- {
- Add(Arguments, depth, new List());
- depth++;
- selected = null;
- }
- else if(item.TypeCode == (short)LispDataType.ListEnd)
- {
- depth--;
- selected = null;
- }
- if (selected != null)
- Add(Arguments, depth, selected);
- }
- if (Arguments.Count maximum)
- throw new System.Exception("too many arguments");
- return Arguments;
- }
本帖以下内容被隐藏保护;需要你回复后,才能看到! 游客,如果您要查看本帖隐藏内容请 回复 |