private string ProcessFields(string input, List <FieldEntry> mFields) { StringBuilder sb = new StringBuilder(); MatchCollection collection = Interpreter.REGEX_FIELD.Matches(input); foreach (Match match in collection) { sb.Clear(); int count = mFields?.Count ?? 0; if (count > 0) { string splitChar = match.Groups[1].Value; splitChar = splitChar == "\\n" ? Environment.NewLine : splitChar; for (int i = 0; i < count; i++) { FieldEntry field = mFields[i]; string content = match.Groups[2].Value.Replace("[field_type]", field.clsType); content = content.Replace("[field_name]", field.id); if (i != count - 1) { content += splitChar; } sb.Append(content); } } input = input.Replace(match.Value, sb.ToString()); } return(input); }
private string ProcessSerialize(string input, List <FieldEntry> mFields) { StringBuilder sb = new StringBuilder(); MatchCollection collection = Interpreter.REGEX_RW_BUFFER.Matches(input); foreach (Match match in collection) { sb.Clear(); int count = mFields?.Count ?? 0; if (count > 0) { string splitChar = match.Groups[1].Value; splitChar = splitChar == "\\n" ? Environment.NewLine : splitChar; for (int i = 0; i < count; i++) { FieldEntry field = mFields[i]; string content = this.ProcessSerializeField(match.Groups[2].Value, field); content = content.Replace("[field_name]", field.id); content = content.Replace("[write_method]", Interpreter.BUFFER_WRITE.GetString(field.clsType)); content = content.Replace("[read_method]", Interpreter.BUFFER_READ.GetString(field.clsType)); if (i != count - 1) { content += splitChar; } sb.Append(content); } } input = input.Replace(match.Value, sb.ToString()); } return(input); }
private string ProcessSerializeField(string input, FieldEntry field) { MatchCollection collection = Interpreter.REGEX_LIST.Matches(input); if (field.type == "alist") { foreach (Match match in collection) { input = match.Groups[2].Value; input = input.Replace("[sub_dto_cls_name]", field.subDTO.ClsName()); } } else { foreach (Match match in collection) { input = input.Replace(match.Value, string.Empty); } } input = input.Replace("[field_name]", field.id); return(input); }
private void ParseField(IFieldHolder parent, XML parentNode, XMLList nodeElements) { XMLList fieldNodes = parentNode.Elements(); foreach (XML fieldNode in fieldNodes) //parse packets { switch (fieldNode.name) { case "field": FieldEntry field = new FieldEntry(); field.id = fieldNode.GetAttribute("id"); field.type = fieldNode.GetAttribute("type"); parent.AddField(field); if (field.type == "alist") { string dtoName = fieldNode.GetAttribute("struct"); XML subDTONode = FindId(nodeElements, dtoName); if (!this.CreateStruct(ushort.Parse(subDTONode.GetAttribute("id")), dtoName, out DTOEntry subDTO)) { this.ParseField(subDTO, subDTONode, nodeElements); } field.subDTO = subDTO; } break; case "conditions": XMLList conditionNodes = fieldNode.Elements(); foreach (XML conditionNode in conditionNodes) { Condition condition = new Condition(parent); condition.key = conditionNode.GetAttribute("key"); condition.values = conditionNode.GetAttribute("value").Split(','); parent.conditions.Add(condition); this.ParseField(condition, conditionNode, nodeElements); } break; } } }
public void AddField(FieldEntry field) { this._fieldsMap[field.id] = field; }