void WriteReaderString(TypeInfo typeInfo, string name, CodeStringBuilder builder, bool field = true) { if (typeInfo.IsPrimitive) { if (!field) { builder.AppendLine("var {0} = {1};", name, Util.CreateReaderString(typeInfo)); } else { builder.AppendLine("{0} = {1};", name, Util.CreateReaderString(typeInfo)); } } else if (typeInfo.IsEnum) { EnumInfo enumType = (EnumInfo)typeInfo; if (!field) { builder.AppendLine("var {0} = {1};", name, Util.CreateReaderString(enumType)); } else { builder.AppendLine("{0} = {1};", name, Util.CreateReaderString(enumType)); } } else { if (!field) { builder.AppendLine("var {0} = new {1}();", name, typeInfo.UsableType); } builder.AppendLine("{0}.Unpack(reader);", name); } }
string BuildEnumItems(XElement node, EnumInfo myInfo) { CodeStringBuilder returnText = new CodeStringBuilder(2); foreach (var item in node.Elements()) { if (item.Name == "value" || item.Name == "mask") { BuildEnumItem(item, returnText, myInfo); } } return(returnText.ToString().RemoveEndingComma()); }
void WriteWriterString(TypeInfo typeInfo, string name, CodeStringBuilder builder) { if (typeInfo.IsPrimitive) { builder.AppendLine(Util.CreateWriterString(typeInfo, name) + ";"); } else if (typeInfo.IsEnum) { EnumInfo enumType = (EnumInfo)typeInfo; builder.AppendLine(Util.CreateWriterString(enumType, name) + ";"); } else { builder.AppendLine("{0}.Pack(writer);", name); } }
void BuildEnumItem(XElement node, CodeStringBuilder returnText, EnumInfo myInfo) { string itemValue = node.GetAttribute("value"); string itemName = node.GetAttribute("name"); if (String.IsNullOrWhiteSpace(itemName)) { itemName = "Unknown" + BlankCounter++; } myInfo.ValueMap.Add(itemName, itemValue); var itemText = node.Attribute("text"); if (itemText != null && itemText.IsValid()) { returnText.AppendLine(); returnText.AppendSummary(itemText.Value); } returnText.AppendLine("{0} = {1},", itemName, itemValue); }