public void TestGetContentByExtension() { CopyrightCore.Load(); var txt = CopyrightCore.GetContentByExtension(".cs"); Assert.IsNotNull(txt); }
/// <summary> /// This function is the callback used to execute the command when the menu item is clicked. /// See the constructor to see how the menu item is associated with this function using /// OleMenuCommandService service and MenuCommand class. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event args.</param> private void MenuItemCallback(object sender, EventArgs e) { //获取服务,这玩意儿……可以理解为vs的服务对象吧。 var dte = this.ServiceProvider.GetService(typeof(DTE)) as DTE; var selection = dte.ActiveDocument.Selection as TextSelection; if (selection == null) { return; } //获取拓展名 var ext = Path.GetExtension(dte.ActiveDocument.FullName); //删除所选内容 if (!selection.IsEmpty) { selection.Delete(); } var txt = CopyrightCore.GetContentByExtension(ext); if (txt == null) { return; } //Insert to top if (CopyrightCore.CurrentStoreConfig.IsInsertToTop) { selection.StartOfDocument(); } selection.Insert(txt); //selection.Insert("//Demo test~~~" + Environment.NewLine + "//Test line 2"); }