private object ReadNode() { var name = reader.ReadString(); var node = Serialization.CreateNode(name); var folder = node as Folder; if (folder != null) { folder.Name = name; } reader.ReadStringArray(attributes); SetAttributes(node); int childrenCount = reader.ReadInt32(); if (childrenCount > 0) { var treeNode = (TreeNode)node; for (int i = 0; i < childrenCount; i++) { var child = ReadNode(); treeNode.AddChild(child); } } if (node is Build build && formatSupportsEmbeddedProjectImportsArchive) { build.SourceFilesArchive = reader.ReadByteArray(); } return(node); }
private object ReadNode() { var name = reader.ReadString(); var node = Serialization.CreateNode(name); var folder = node as Folder; if (folder != null) { folder.Name = name; } reader.ReadStringArray(attributes); SetAttributes(node); int childrenCount = reader.ReadInt32(); if (childrenCount > 0) { if (!(node is TreeNode)) { // OK we got ourselves into a situation here. // https://github.com/KirillOsenkov/MSBuildStructuredLog/issues/242 // There's a design flaw in the BuildLog format. I took a shortcut // and for Folder nodes I just write the name of the folder instead // of specifying that the element is a Folder in the first place. // Unfortunately I didn't think about Folders named "Property", // "Target", etc. // So the deserialization logic when it sees a string called "Property" // it assumes we have a property here, instead of a Folder named // "Property". But properties have children! We're in a pickle now. // Longer term I need to modify the format to not do this optimization // and always write "Folder" for folders and write the name separately. // For now I don't have time to do this right, so put in the dirty // hack to recover from this situation. If it says it's a "Property" // but expects children, it means it's actually a folder with name // "Property". folder = new Folder(); folder.Name = Serialization.GetNodeName(node); node = folder; } var treeNode = (TreeNode)node; for (int i = 0; i < childrenCount; i++) { var child = ReadNode(); treeNode.AddChild(child); } } if (node is Build build && formatSupportsEmbeddedProjectImportsArchive) { build.SourceFilesArchive = reader.ReadByteArray(); } return(node); }