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 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 { } } }