/// <summary> /// Updates the code attribute argument. /// </summary> /// <param name="codeAttribute">The code attribute.</param> /// <param name="argumentName">Name of the argument.</param> /// <param name="argumentValue">The argument value.</param> /// <param name="createIfNew">if set to <c>true</c> [create if new].</param> /// <returns></returns> public static bool UpdateCodeAttributeArgument( CodeAttribute codeAttribute, string argumentName, string argumentValue, bool createIfNew) { Guard.ArgumentNotNull(codeAttribute, "codeAttribute"); Guard.ArgumentNotNullOrEmptyString(argumentName, "argumentName"); bool result = false; EnvDTE80.CodeAttribute2 attribute2 = (EnvDTE80.CodeAttribute2)codeAttribute; EnvDTE80.CodeAttributeArgument argumentMatch = null; foreach (EnvDTE80.CodeAttributeArgument argument in attribute2.Arguments) { if (argument.Name.Equals(argumentName, StringComparison.InvariantCultureIgnoreCase)) { argumentMatch = argument; break; } } if (argumentMatch != null) { argumentMatch.Value = argumentValue; result = true; } else if (createIfNew) { attribute2.AddArgument(argumentValue, argumentName, attribute2.Arguments.Count); result = true; } return(result); }
protected virtual void OnEditText(object sender, EventArgs args) { EnvDTE._DTE dte = GetService(typeof(EnvDTE._DTE)) as EnvDTE._DTE; EnvDTE80.CodeClass2 codeClass = GetCodeClass(dte.ActiveDocument.ProjectItem.FileCodeModel.CodeElements, "MyForm"); EnvDTE80.CodeAttribute2 codeAttribute = GetCodeAttribute(codeClass, "MyCustom"); if (codeAttribute != null) { string newValue = Microsoft.VisualBasic.Interaction.InputBox("Current Text", "Edit MyCustomAttribute text", RemoveQuote(codeAttribute.Value), -1, -1); codeAttribute.Value = (!string.IsNullOrWhiteSpace(newValue) ? "\"" + newValue + "\"" : ""); } }