private Dictionary <string, string> CreateMapOfClassNamesToContents(IdentifyClassType identifyClassType) { // Create a dictionary of file paths to their contents. var pathsToContents = new Dictionary <string, StringBuilder>(); // Now start parsing the raw IL, line by line. using (var reader = new StringReader(rawIl)) { // Read each line string line; string currentClassName = null; while ((line = reader.ReadLine()) != null) { // Is it a class start token? If so, get the class name. string templateSpecification; if (identifyClassType(line)) { ILParseHelper.GetClassNameFromClassDeclarationLine(line, out currentClassName, out templateSpecification); } // If don't have a current class, skip. if (currentClassName == null) { continue; } // Add the line to the class. if (!pathsToContents.ContainsKey(currentClassName)) { pathsToContents[currentClassName] = new StringBuilder(); } pathsToContents[currentClassName].AppendLine(line); // Is it a class end token? If so, clear the current class identifier. if (ILParseHelper.IsLineClassEndDeclaration(line, currentClassName)) { currentClassName = null; } } } // Return the dictionary. return(pathsToContents.ToDictionary(d => d.Key, d => d.Value.ToString())); }
private List <RawILClass> ParseDisassembledIlClasses() { // We'll return a list of raw IL classes. var rootRawILClasses = new List <RawILClass>(); // Now start parsing the raw IL, line by line. using (var reader = new StringReader(RawIL)) { // IL classes can be nested, so when parsing them we must maintain // a stack (so we can nest too). var rawIlClassStack = new Stack <RawILClass>(); // Read each line string line; while ((line = reader.ReadLine()) != null) { if (line.Contains("<GetVisualChildren>")) { Console.WriteLine(); } // Is it a class start token? If so, we can start a new builder. if (ILParseHelper.IsLineAnyLevelIlClassDeclaration(line)) { string fullName, templateSpecification; ILParseHelper.GetClassNameFromClassDeclarationLine(line, out fullName, out templateSpecification); // Create a new raw IL class, parse its name, add it to the list if it's top level, add it to the stack. var rawIlClass = new RawILClass { FullName = fullName, TemplateSpecification = templateSpecification }; if (!rawIlClassStack.Any()) { rootRawILClasses.Add(rawIlClass); } else { rawIlClassStack.Peek().Children.Add(rawIlClass); } rawIlClassStack.Push(rawIlClass); } // If don't have a current class, skip. if (!rawIlClassStack.Any()) { continue; } // Add the line to the class builder. rawIlClassStack.Peek().ILBuilder.AppendLine(line); // Is it a class end token? If so, we've finished the class. if (ILParseHelper.IsLineClassEndDeclaration(line, rawIlClassStack.Peek().FullName)) { // Pop the stack. rawIlClassStack.Pop(); } } } // Return the set of class builders. return(rootRawILClasses); }