private static string GetEnumEntryName(EnumData en, EnumEntry entry) { return Utils.GetPascalStyleString(GetStrippedEnumName(en.Name, entry.Name)); }
private static string GetEnumItems(EnumData en) { List<string> escapedEnum = new List<string>(); foreach (EnumEntry entry in en.Entries) { escapedEnum.Add(string.Format("\r\n\r\n /// <summary> {0} </summary>\r\n {1} = {2}", GetSanitizedComment(entry.Description), GetEnumEntryName(en, entry), entry.Value)); } return GetCommaSeparatedValues(escapedEnum, ""); }
// __ Impl _______________________________________________________ private void Parse(XmlTextReader reader, ProtocolData result) { ProtocolObject currentObject = null; MessageData currentMsg = null; FieldData currentField = null; EnumData currentEnum = null; EnumEntry currentEntry = null; EnumEntryParameter currentParam = null; int currentEnumValue = 0; bool isExtensionsParam = false; int fieldIndex = 0; while (reader.Read()) { if (reader.IsStartElement()) { switch (reader.Name) { case "include": ProcessInclude(reader.ReadElementContentAsString(), result); break; case "version": result.Version = reader.ReadElementContentAsInt(); break; case "message": isExtensionsParam = false; // if (currentMsg != null) SortFields(currentMsg); //<--- if condition deleted currentMsg = new MessageData(); currentObject = currentMsg; currentMsg.Name = reader.GetAttribute("name"); currentMsg.Id = GetIntFromString(reader.GetAttribute("id")); if (currentMsg.Id < 256) // Msg id field is a byte, discard anything beyond 255 { result.Messages.Add(currentMsg.Name, currentMsg); } break; case "description": currentObject.Description = reader.ReadString(); break; case "field": currentField = new FieldData(); currentField.Index = fieldIndex++; currentField.Name = reader.GetAttribute("name"); currentField.TypeString = reader.GetAttribute("type"); currentField.Type = GetFieldTypeFromString(currentField.TypeString); currentField.NumElements = GetFieldTypeNumElements(currentField.TypeString); currentField.IsExtension = isExtensionsParam; currentField.Description = reader.ReadElementContentAsString(); UpdateEnumFields(result, currentField); currentMsg.Fields.Add(currentField); break; case "extensions": isExtensionsParam = true; break; case "enum": currentEnum = GetEnumDataForName(result, reader.GetAttribute("name")); currentObject = currentEnum; result.Enumerations[currentEnum.Name] = currentEnum; currentEnumValue = 0; isExtensionsParam = true; break; case "entry": currentEntry = new EnumEntry(); currentObject = currentEntry; currentEntry.Name = reader.GetAttribute("name"); currentEntry.Value = GetIntFromString(reader.GetAttribute("value"), ++currentEnumValue); currentEnumValue = currentEntry.Value; currentEnum.Entries.Add(currentEntry); break; case "param": currentParam = new EnumEntryParameter(); currentParam.Index = GetIntFromString(reader.GetAttribute("index")); currentParam.Description = reader.ReadElementContentAsString(); currentEntry.Parameters.Add(currentParam); break; } } else //<----- Else condition added to control closing of the current node; *** BEGIN **** { if (reader.Name == "message") { if (currentMsg != null) { SortFields(currentMsg, false); SortFields(currentMsg, true); } } } //<----- *** END *** } }
private EnumData GetEnumDataForName(ProtocolData data, string name) { EnumData result; if (!data.Enumerations.TryGetValue(name, out result)) { result = new EnumData(); result.Name = name; } return result; }
// __ Impl _______________________________________________________ private void Parse(XmlTextReader reader, ProtocolData result) { ProtocolObject currentObject = null; MessageData currentMsg = null; FieldData currentField = null; EnumData currentEnum = null; EnumEntry currentEntry = null; EnumEntryParameter currentParam = null; while (reader.Read()) { if (reader.IsStartElement()) { switch (reader.Name) { case "include": ProcessInclude(reader.ReadElementContentAsString(), result); break; case "version": result.Version = reader.ReadElementContentAsInt(); break; case "message": if (currentMsg != null) { SortFields(currentMsg); } currentMsg = new MessageData(); currentObject = currentMsg; currentMsg.Name = reader.GetAttribute("name"); currentMsg.Id = GetIntFromString(reader.GetAttribute("id")); result.Messages.Add(currentMsg.Name, currentMsg); break; case "description": currentObject.Description = reader.ReadString(); break; case "field": currentField = new FieldData(); currentField.Name = reader.GetAttribute("name"); currentField.TypeString = reader.GetAttribute("type"); currentField.Type = GetFieldTypeFromString(currentField.TypeString); currentField.NumElements = GetFieldTypeNumElements(currentField.TypeString); currentField.Description = reader.ReadElementContentAsString(); UpdateEnumFields(result, currentField); currentMsg.Fields.Add(currentField); break; case "enum": currentEnum = GetEnumDataForName(result, reader.GetAttribute("name")); currentObject = currentEnum; result.Enumerations[currentEnum.Name] = currentEnum; break; case "entry": currentEntry = new EnumEntry(); currentObject = currentEntry; currentEntry.Name = reader.GetAttribute("name"); currentEntry.Value = GetIntFromString(reader.GetAttribute("value")); currentEnum.Entries.Add(currentEntry); break; case "param": currentParam = new EnumEntryParameter(); currentParam.Index = GetIntFromString(reader.GetAttribute("index")); currentParam.Description = reader.ReadElementContentAsString(); currentEntry.Parameters.Add(currentParam); break; } } } }