/// <summary> /// Expand auto property into a normal property /// </summary> /// <param name="prop"></param> /// <param name="parentWriter"></param> /// <remarks></remarks> public void ExpandAutoProperty(CodeProperty2 prop, Writer parentWriter) { //Save existing doc comment var comment = prop.AsCodeElement().GetDocComment(); //Get its attribute var propAttrs = prop.GetText(vsCMPart.vsCMPartAttributesWithDelimiter); //Interface implementation var interfaceImpl = prop.GetInterfaceImplementation(); var tsWriter = new Writer(parentWriter) { SegmentType = Types.Region, TagComment = string.Format("{0} auto expanded by", prop.Name), GenAttribute = { RegenMode = GeneratorAttribute.RegenModes.Once } }; //only do this once, since once it is expanded it will no longer be detected as auto property var completeProp = GetIsolatedOutput(() => OutProperty(tsWriter.CreateTaggedRegionName(), prop.Name, prop.Type.SafeFullName(), comment, propAttrs, interfaceImpl)); //Replace all code starting from comment to endPoint of the property var ep = prop.GetCommentStartPoint().CreateEditPoint(); const int options = (int)(vsEPReplaceTextOptions.vsEPReplaceTextAutoformat | vsEPReplaceTextOptions.vsEPReplaceTextNormalizeNewlines); ep.ReplaceText(prop.EndPoint, completeProp, options); }
public static string GetInterfaceImplementation(this CodeProperty2 prop) { var g = GetInterfaceImplementation_regex.Match(prop.GetText(vsCMPart.vsCMPartHeader)).Groups["impl"]; //add space to separate if (g.Success) { return(" " + g.Value); } return(null); }
/// <summary> /// Expand auto property into a normal property /// </summary> /// <param name="prop"></param> /// <param name="parentWriter"></param> /// <remarks></remarks> public void ExpandAutoProperty(CodeProperty2 prop, ManagerType.Writer parentWriter) { //Save existing elements of the property //doc comment var comment = prop.AsCodeElement().GetDocComment(); //attributes var propAttrs = prop.GetText(vsCMPart.vsCMPartAttributesWithDelimiter); //Interface implementation var interfaceImpl = prop.GetInterfaceImplementation(); var code = General.GetTemplateOutput(output => GenProperty(output, prop.Name, prop.Type.SafeFullName(), comment, propAttrs, interfaceImpl) ); var writer = new ManagerType.Writer(parentWriter) { TargetRange = new TaggedRange { SegmentType = SegmentTypes.Region }, TagNote = string.Format("{0} expanded by", prop.Name), //OptionTag, Content = code }; var text = AutoPropertyExpansionIsTagged ? writer.GenText() : code; //only do this once, since once it is expanded it will no longer be detected as auto property //Replace all code starting from comment to endPoint of the property // ReSharper disable once BitwiseOperatorOnEnumWithoutFlags const int options = (int)(vsEPReplaceTextOptions.vsEPReplaceTextAutoformat | vsEPReplaceTextOptions.vsEPReplaceTextNormalizeNewlines); prop.GetCommentStartPoint() .CreateEditPoint() .ReplaceText(prop.EndPoint, text, options); }
/// <summary> /// Expand auto property into a normal property /// </summary> /// <param name="prop"></param> /// <param name="parentWriter"></param> /// <remarks></remarks> public void ExpandAutoProperty(CodeProperty2 prop, Writer parentWriter) { //Save existing doc comment var comment = prop.AsCodeElement().GetDocComment(); //Get its attribute var propAttrs = prop.GetText(vsCMPart.vsCMPartAttributesWithDelimiter); //Interface implementation var interfaceImpl = prop.GetInterfaceImplementation(); var tsWriter = new Writer(parentWriter) { SegmentType = Types.Region, TagComment = string.Format("{0} auto expanded by", prop.Name), GenAttribute = {RegenMode = GeneratorAttribute.RegenModes.Once} }; //only do this once, since once it is expanded it will no longer be detected as auto property var completeProp = GetIsolatedOutput(() => OutProperty(tsWriter.CreateTaggedRegionName(), prop.Name, prop.Type.SafeFullName(), comment, propAttrs, interfaceImpl)); //Replace all code starting from comment to endPoint of the property var ep = prop.GetCommentStartPoint().CreateEditPoint(); const int options = (int)( vsEPReplaceTextOptions.vsEPReplaceTextAutoformat | vsEPReplaceTextOptions.vsEPReplaceTextNormalizeNewlines); ep.ReplaceText(prop.EndPoint, completeProp, options); }