public void SetFromContents(string contents, bool removeComments, bool trimClassContents) { if (removeComments) { contents = ParsedClass.RemoveComments(contents); } int startOfNamespace = contents.IndexOf("namespace "); if (startOfNamespace != -1) { int i = GetClosingBracketOfNamespace(contents); try { string parsedNamespaceString = contents.Substring(startOfNamespace, i - startOfNamespace + 1); ParsedNamespace parsedNamespace = new ParsedNamespace(parsedNamespaceString, removeComments, trimClassContents); mNamespaces.Add(parsedNamespace); } catch { int m = 3; } } }
internal static void InsertMethodCallInElementIfNecessary(IElement iElement, string methodName) { string currentFileName = FileManager.RelativeDirectory + iElement.Name + ".Events.cs"; string className = FileManager.RemovePath(iElement.Name); string fullFileContents = null; if (!FileManager.FileExists(currentFileName)) { string startingTemplate = Resources.Resource1.EventTemplate; startingTemplate = startingTemplate.Replace("CLASS___NAME", className); string namespaceName = ProjectManager.ProjectNamespace + '.' + FileManager.GetDirectoryKeepRelative(iElement.Name).Replace("\\", "."); // remove the ending slash: namespaceName = namespaceName.Substring(0, namespaceName.Length - 1); startingTemplate = startingTemplate.Replace("NAMESPACE___NAME", namespaceName); FileManager.SaveText(startingTemplate, currentFileName); ProjectManager.CodeProjectHelper.CreateAndAddPartialCodeFile(currentFileName, false); fullFileContents = startingTemplate; } else { fullFileContents = FileManager.FromFileText(currentFileName); } #region Find the parsedClassToUse ParsedNamespace parsedNamespace = new ParsedNamespace(fullFileContents); ParsedClass parsedClassToUse = null; foreach (ParsedClass parsedClass in parsedNamespace.Classes) { if (parsedClass.Name == className) { parsedClassToUse = parsedClass; break; } } #endregion if (parsedClassToUse != null) { // See if there is already a method here if (parsedClassToUse.GetMethod(methodName) == null) { DialogResult result = MessageBox.Show("The method\n\n" + methodName + "\n\ndoes not exist. Create this " + "method in your .Event.cs code file?", "Create method?", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { string newMethodCode = "\r\n\t\tvoid " + methodName + "(object sender, EventArgs e)\r\n" + "\t\t{\r\n" + "\t\t\t\r\n" + "\t\t}\r\n"; int indexToInsertAt = EventManager.GetLastLocationInClass(fullFileContents, startOfLine:true); fullFileContents = fullFileContents.Insert(indexToInsertAt, newMethodCode); FileManager.SaveText(fullFileContents, currentFileName); } } } }