private void AddCollNodes(TreeNode parent, GffFieldCollection coll) { System.Text.StringBuilder b = new System.Text.StringBuilder(1024); int i = 0; foreach (GffField field in coll) { string name = "Entry_" + i.ToString(); i++; if (field.IsList) { TreeNode node = parent.Nodes.Add(name); AddCollNodes(node, ((GffListField) field).Value); } else if (field.IsStruct) { TreeNode node = parent.Nodes.Add(name); AddDictNodes(node, ((GffStructField) field).Value); } else { b.Length = 0; b.AppendFormat ("{0} = [{1}]", name, field.Value.ToString()); parent.Nodes.Add(b.ToString()); } } }
/// <summary> /// Override to deserialize the object from the GFF file's binary data. /// </summary> /// <param name="rawField">The raw field from the GFF</param> /// <param name="rawData">The GFF's raw file data</param> void IGffFieldSerialize.Deserialize(RawGffData.RawGffField rawField, RawGffData rawData) { // Get the list of structure indeces for the items in the list uint[] indeces = rawData.GetListIndeces(rawField.DataOrDataOffset); // Create a field collection for the structures, and loop through // the index array. GffFieldCollection fields = new GffFieldCollection(); for (int i = 0; i < indeces.Length; i++) { // Get the raw structure data for this structure. RawGffData.RawGffStruct rawStruct = rawData.GetStruct(indeces[i]); // Create a GffStructField object for the structure and set it's // structure type. GffStructField field = (GffStructField) GffFieldFactory.CreateField(GffFieldType.Struct); field.StructureType = rawStruct.Type; // Create a dummy field object so we can deserialize the structure, // set it's DataOrDataOffset to the structure index. RawGffData.RawGffField dummyField = new RawGffData.RawGffField(GffFieldType.Struct); dummyField.LabelIndex = 0; dummyField.DataOrDataOffset = indeces[i]; // Deserialize the structure. ((IGffFieldSerialize) field).Deserialize(dummyField, rawData); // Add the structure to the collection. fields.Add(field); } Value = fields; }
/// <summary> /// Class constructor. /// </summary> /// <param name="stream">The memory stream containing the data</param> public GffListField(GffFieldCollection coll) : base(GffFieldType.List, coll) { }