/// <summary> /// 解析 /// </summary> /// <param name="context"></param> public void Interpreter(CollectionInterpreterContext context) { keys = new List <FormatKey>(); keyValuesList = new List <Dictionary <string, string> >(); SetFormateKey(context.Format); SetFormateValue(context.Data); SetResult(context); }
/// <summary> /// 设置结果 /// </summary> /// <param name="context"></param> private void SetResult(CollectionInterpreterContext context) { foreach (var keyValues in keyValuesList) { int offset = 0; string Result = context.Format; foreach (var item in keys) { var value = keyValues[item.key]; StringBuilder sbResult = new StringBuilder(Result); sbResult.Replace(item.key, value, item.beginIndex + offset, item.key.Length); offset += value.Length - item.key.Length; Result = sbResult.ToString(); } context.Result.Add(Result); } }
private void SetFormatValue() { var collectionExepression = new CollectionExepression(); var entityExepression = new EntityExepression(); foreach (var item in formates) { if (item.IsCollection) { var context = new CollectionInterpreterContext(item.Key, item.Data); collectionExepression.Interpreter(context); item.FormatValue.AddRange(context.Result); } else { var context = new EntityInterpreterContext(item.Key, item.Data); entityExepression.Interpreter(context); item.FormatValue.Add(context.Result); } } }