public static void InternalExecute(ProjectItem projectItem)
		{
			var ctors = new List<CodeFunction>();

			foreach (CodeFunction constructor in projectItem.FindContructors().Where(m => m.Parameters.Count > 0))
			{
				var codeElement = constructor.As<CodeElement>();
				string ctorText = codeElement.InnerText();
				var editPoint = codeElement.AtTheFirstLineAfterTheOpeningBrakect();

				bool lineAdded = false;
				foreach (var param in constructor.Parameters().Reverse())
				{
					if (param.Type.CodeType.Kind != vsCMElement.vsCMElementStruct && !ctorText.Contains($"ArgumentNullException(\"{param.Name}\")"))
					{
						lineAdded = true;
						projectItem.AddLine(editPoint, param.Name.ToCtorNullCheck());
					}
				}

				if (lineAdded)
				{
					ctors.Add(constructor);
				}
			}

			if (ctors.Any())
			{
				if (!projectItem.Contains("using System;"))
				{
					projectItem.AddLine(projectItem.FindNameSpace().As<CodeElement>().AtTheFirstLineAfterTheOpeningBrakect(), "using System;");
				}
			}

			foreach (CodeFunction constructor in projectItem.FindContructors().Where(m => m.Parameters.Count > 0))
			{
				if (string.IsNullOrWhiteSpace(constructor.DocComment))
				{
					AddCommentsToCodeElements.AddDocCommentToCtor(constructor);
				}

				var docComment = constructor.DocComment;
				var codeElement = constructor.As<CodeElement>();
				if ((codeElement.Contains("throw new ArgumentNullException") || codeElement.Contains("throw new System.ArgumentNullException"))
					&& (!docComment.Contains(exceptionMessage1) && !docComment.Contains(exceptionMessage2)))
				{
					codeElement.AppendToDocComment(exceptionMessage1);
				}
			}

			if (ctors.Any())
			{
				var dte = (DTE)Package.GetGlobalService(typeof(SDTE));
				try
				{
					dte.ExecuteCommand("Edit.FormatDocument");
				}
				catch { }
			}
		}
		public static void Execute(ProjectItem projectItem)
		{
			if (projectItem.Name.EndsWith(".config", StringComparison.CurrentCulture) && projectItem.Contains("<moduleConfiguration") && !projectItem.ContainingProject.IsTestProject())
			{
				var dte = (DTE)Package.GetGlobalService(typeof(SDTE));
				string configFile = projectItem.ReadAllText();

				var moduleConfig = configFile.Deserialize<XmlModuleConfig>();
				if (moduleConfig != null)
				{
					var project = dte.Solution.FindProject(p => p.Name == moduleConfig.AssemblyName);
					var moduleProjectItem = project.FindProjectItem(p => p.Name == moduleConfig.CsFileName);

					string csFile = moduleProjectItem.ReadAllText();

					string newConfig = DetermineNewConfig(configFile, csFile);

					if (!(configFile.EqualsExcludingWhitespace(newConfig)))
					{
						projectItem.Document?.Activate();
						projectItem.ClearAllText();
						projectItem.SetText(newConfig);
					}
				}
			}
		}
        public static void InternalExecute(ProjectItem projectItem)
        {
            var ctors = new List <CodeFunction>();

            foreach (CodeFunction constructor in projectItem.FindContructors().Where(m => m.Parameters.Count > 0))
            {
                var    codeElement = constructor.As <CodeElement>();
                string ctorText    = codeElement.InnerText();
                var    editPoint   = codeElement.AtTheFirstLineAfterTheOpeningBrakect();

                bool lineAdded = false;
                foreach (var param in constructor.Parameters().Reverse())
                {
                    if (param.Type.CodeType.Kind != vsCMElement.vsCMElementStruct && !ctorText.Contains($"ArgumentNullException(\"{param.Name}\")"))
                    {
                        lineAdded = true;
                        projectItem.AddLine(editPoint, param.Name.ToCtorNullCheck());
                    }
                }

                if (lineAdded)
                {
                    ctors.Add(constructor);
                }
            }

            if (ctors.Any())
            {
                if (!projectItem.Contains("using System;"))
                {
                    projectItem.AddLine(projectItem.FindNameSpace().As <CodeElement>().AtTheFirstLineAfterTheOpeningBrakect(), "using System;");
                }
            }

            foreach (CodeFunction constructor in projectItem.FindContructors().Where(m => m.Parameters.Count > 0))
            {
                if (string.IsNullOrWhiteSpace(constructor.DocComment))
                {
                    AddCommentsToCodeElements.AddDocCommentToCtor(constructor);
                }

                var docComment  = constructor.DocComment;
                var codeElement = constructor.As <CodeElement>();
                if ((codeElement.Contains("throw new ArgumentNullException") || codeElement.Contains("throw new System.ArgumentNullException")) &&
                    (!docComment.Contains(exceptionMessage1) && !docComment.Contains(exceptionMessage2)))
                {
                    codeElement.AppendToDocComment(exceptionMessage1);
                }
            }

            if (ctors.Any())
            {
                var dte = (DTE)Package.GetGlobalService(typeof(SDTE));
                try
                {
                    dte.ExecuteCommand("Edit.FormatDocument");
                }
                catch { }
            }
        }
        public static void Execute(ProjectItem projectItem)
        {
            if (projectItem.Name.EndsWith(".config", StringComparison.CurrentCulture) && projectItem.Contains("<moduleConfiguration") && !projectItem.ContainingProject.IsTestProject())
            {
                var    dte        = (DTE)Package.GetGlobalService(typeof(SDTE));
                string configFile = projectItem.ReadAllText();

                var moduleConfig = configFile.Deserialize <XmlModuleConfig>();
                if (moduleConfig != null)
                {
                    var project           = dte.Solution.FindProject(p => p.Name == moduleConfig.AssemblyName);
                    var moduleProjectItem = project.FindProjectItem(p => p.Name == moduleConfig.CsFileName);

                    string csFile = moduleProjectItem.ReadAllText();

                    string newConfig = DetermineNewConfig(configFile, csFile);

                    if (!(configFile.EqualsExcludingWhitespace(newConfig)))
                    {
                        projectItem.Document?.Activate();
                        projectItem.ClearAllText();
                        projectItem.SetText(newConfig);
                    }
                }
            }
        }
Пример #5
0
 public static bool IsModuleClass(this ProjectItem projectItem)
 {
     return(projectItem.Name.EndsWith(".cs", StringComparison.CurrentCulture) && projectItem.Contains(": IModule"));
 }
Пример #6
0
 public static bool IsModuleConfig(this ProjectItem projectItem)
 {
     return(projectItem.Name.EndsWith(".config", StringComparison.CurrentCulture) && projectItem.Contains("<moduleConfiguration"));
 }