/// <summary> /// Implements the code snippet. /// </summary> /// <param name="instance">The instance.</param> /// <param name="codeSnippet">The code snippet.</param> /// <param name="formatFunctionParameters">if set to <c>true</c> [format function parameters].</param> public static void ImplementCodeSnippet( this ProjectItem instance, CodeSnippet codeSnippet, bool formatFunctionParameters) { TraceService.WriteLine("ProjectItemExtensions::ImplementCodeSnippet in file " + instance.Name); if (codeSnippet.UsingStatements != null && codeSnippet.UsingStatements.Any()) { IEnumerable <string> statements = instance.GetUsingStatements(); foreach (string reference in codeSnippet.UsingStatements) { string contains = statements.FirstOrDefault(x => x.Contains(reference)); if (contains == null) { instance.AddUsingStatement(reference); TraceService.WriteLine("Using statement added " + reference); } } } instance.GetFirstClass().ImplementCodeSnippet( codeSnippet, formatFunctionParameters); //// now apply any variable substitutions if (codeSnippet.ReplacementVariables != null) { foreach (KeyValuePair <string, string> item in codeSnippet.ReplacementVariables) { instance.ReplaceText(item.Key, item.Value); } } }
/// <summary> /// Implements the code snippet. /// </summary> /// <param name="instance">The instance.</param> /// <param name="codeSnippet">The code snippet.</param> public static void ImplementCodeSnippet( this ProjectItem instance, CodeSnippet codeSnippet) { TraceService.WriteLine("ProjectItemExtensions::ImplementCodeSnippet in file " + instance.Name); if (codeSnippet.UsingStatements.Any()) { List <string> statements = instance.GetUsingStatements(); foreach (string reference in codeSnippet.UsingStatements) { string contains = statements.FirstOrDefault(x => x.Contains(reference)); if (contains == null) { instance.AddUsingStatement(reference); } } } instance.GetFirstClass().ImplementCodeSnippet(codeSnippet); }
/// <summary> /// Adds the plugins. /// </summary> /// <param name="visualStudioService">The visual studio service.</param> /// <param name="plugins">The plugins.</param> /// <param name="viewModelName">Name of the view model.</param> /// <param name="codeSnippetsPath">The code snippets path.</param> public void AddPlugins( IVisualStudioService visualStudioService, List <Plugin> plugins, string viewModelName, string codeSnippetsPath) { Project coreProject = visualStudioService.CoreProject; this.AddProjectPlugins(coreProject, plugins, "Core", "Core"); this.AddProjectPlugins(visualStudioService.DroidProject, plugins, "Droid", "Droid"); this.AddProjectPlugins(visualStudioService.iOSProject, plugins, "iOS", "Touch"); this.AddProjectPlugins(visualStudioService.WindowsPhoneProject, plugins, "WindowsPhone", "WindowsPhone"); this.AddProjectPlugins(visualStudioService.WindowsStoreProject, plugins, "WindowsStore", "WindowsStore"); this.AddProjectPlugins(visualStudioService.WpfProject, plugins, "Wpf", "Wpf"); if (string.IsNullOrEmpty(viewModelName) == false) { ProjectItem projectItem = coreProject.GetProjectItem(viewModelName); if (projectItem != null) { foreach (Plugin plugin in plugins) { string snippetPath = string.Format(@"{0}\Plugins.{1}.txt", codeSnippetsPath, plugin.FriendlyName); if (File.Exists(snippetPath)) { FileInfo fileInfo = new FileInfo(snippetPath); //// only do if the snippet contains some text :-) if (fileInfo.Length > 0) { string assemblyName = Path.GetFileNameWithoutExtension(plugin.FileName); projectItem.AddUsingStatement("Cirrious.CrossCore"); projectItem.AddUsingStatement(assemblyName); projectItem.InsertMethod(snippetPath); //// tidy up the using statements. projectItem.Save(); projectItem.MoveUsingStatements(); projectItem.Save(); projectItem.SortAndRemoveUsingStatements(); projectItem.Save(); if (projectItem.Document != null) { projectItem.Document.ActiveWindow.Close(); } } } } } } DTE2 dte2 = coreProject.DTE as DTE2; dte2.SaveAll(); }