/// <summary> /// Checks to see if a block equals this one. /// </summary> public override bool Equals(object obj) { if (!(obj is PersistenceBlock)) { return(false); } PersistenceBlock block = (PersistenceBlock)obj; return(block == this); }
/// <summary> /// Takes in line of takes and parses out the persistence block and the closing /// project tag. /// </summary> private void ParsePersistenceBlock(StreamReader reader, string text, ref int line) { string closeTag = reader.ReadLine(); if (!string.Equals(closeTag, "EndProject")) { throw new ParseException("Expected closing tag 'EndProject' on line " + (line + 1)); } // Parse the block PersistenceBlock block = PersistenceBlock.Parse(text); // Add it _blocks.Add(block); // We skipped a line so move next line++; }
/// <summary> /// Given a line of text this function will parse it and create a persistence block /// </summary> /// <param name="text">The text you want to parse</param> /// <returns>The parsed block</returns> internal static PersistenceBlock Parse(string text) { // Example: // Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProjectParseTests", "ProjectParseTests\ProjectParseTests.csproj", "{7E0C5121-B5D3-4A45-AACF-9623C87BADB9}" PersistenceBlock block = new PersistenceBlock(); // Create a reader Console.WriteLine("Reading: " + text); int fieldIndex = 0; int index = 0; while (index < text.Length) { int start = 0; int length = 0; char c = text[index]; if (c == '"') { start = index + 1; do { index++; length++; c = text[index]; } while (c != '"'); length -= 1; if (length > 0) { string content = text.Substring(start, length); switch (fieldIndex) { case 0: block.typeGuid = content; break; case 1: block.instanceID = content; break; case 2: block.path = content; break; case 3: block.typeGuid = content; break; } if (fieldIndex >= 3) { // All fields assigned break; } fieldIndex++; } } index++; } if (fieldIndex > 3) { throw new ParseException("Unable to parse all fields of Persistence Block. Expect four but found " + fieldIndex); } return(block); }