public override void Run() { TaskView view = (TaskView)Owner; foreach (Task t in new List<Task>(view.SelectedTasks)) { FxCopTaskTag tag = t.Tag as FxCopTaskTag; if (tag == null) continue; CodeGenerator codegen = tag.ProjectContent.Language.CodeGenerator; if (codegen == null) continue; FilePosition p; if (tag.MemberName == null) p = GetAssemblyAttributeInsertionPosition(tag.ProjectContent); else p = GetPosition(tag.ProjectContent, tag.TypeName, tag.MemberName); if (p.CompilationUnit == null || p.FileName == null || p.Line <= 0) continue; IViewContent viewContent = FileService.OpenFile(p.FileName); ITextEditorControlProvider provider = viewContent as ITextEditorControlProvider; if (provider == null) continue; IDocument document = new TextEditorDocument(provider.TextEditorControl.Document); if (p.Line >= document.TotalNumberOfLines) continue; IDocumentLine line = document.GetLine(p.Line); StringBuilder indentation = new StringBuilder(); for (int i = line.Offset; i < document.TextLength; i++) { char c = document.GetCharAt(i); if (c == ' ' || c == '\t') indentation.Append(c); else break; } string code = codegen.GenerateCode(CreateSuppressAttribute(p.CompilationUnit, tag), indentation.ToString()); if (!code.EndsWith("\n")) code += Environment.NewLine; document.Insert(line.Offset, code); provider.TextEditorControl.ActiveTextAreaControl.Caret.Line = p.Line - 1; provider.TextEditorControl.ActiveTextAreaControl.ScrollToCaret(); document.UpdateView(); TaskService.Remove(t); ParserService.ParseViewContent(viewContent); } }
void AddImplementInterfaceCommandItems(List<ToolStripItem> subItems, IClass c, bool explicitImpl) { CodeGenerator codeGen = c.ProjectContent.Language.CodeGenerator; IAmbience ambience = AmbienceService.CurrentAmbience; ambience.ConversionFlags = ConversionFlags.None; foreach (IReturnType rt in c.BaseTypes) { IClass interf = rt.GetUnderlyingClass(); if (interf != null && interf.ClassType == ClassType.Interface) { IReturnType rtCopy = rt; // copy for access by anonymous method EventHandler eh = delegate { TextEditorDocument d = new TextEditorDocument(GetDocument(c)); if (d != null) codeGen.ImplementInterface(rtCopy, d, explicitImpl, c); ParserService.ParseCurrentViewContent(); }; subItems.Add(new MenuCommand(ambience.Convert(interf), eh)); } } }