public override ActionResult ApplyActionTo(StringBuilder sb)
        {
            int    searchStart = PropertyToChange.TextRange.StartOffset;
            int    searchEnd   = PropertyToChange.TextRange.EndOffset;
            string text        = sb.ToString();

            if (InsertAtStart)
            {
                sb.Insert(searchStart, NewModifier + " ");
                PropertyToChange.Modifiers.Insert(0, NewModifier);
                return(new ActionResult(searchStart, NewModifier.Length + 1, null));
            }

            int nameIndex = InsertionHelpers.GetPropertyNameIndex(text, PropertyToChange, searchStart, searchEnd);

            // Search Property TextRange for class keyword
            // The last "word" between the start of the property and the name is the type.
            var    substring = text.Substring(0, nameIndex);
            string typeName  = InsertionHelpers.GetLastWord(substring);

            if (typeName == null)
            {
                log.ErrorFormat("Could not find type of property {0} to change, so can't insert modifier before it.", PropertyToChange.Name);
                return(new ActionResult());
            }

            // Find the index of the existing type
            int typeIndex = substring.LastIndexOf(typeName);

            //Insert the new modifier just before the class keyword
            sb.Insert(typeIndex, NewModifier + " ");
            PropertyToChange.Modifiers.Add(NewModifier);

            return(new ActionResult(typeIndex, NewModifier.Length + 1, null));
        }
        public override ActionResult ApplyActionTo(StringBuilder sb)
        {
            if (PropertyToChange.DataType.ToString() == NewType.ToString())
            {
                return(new ActionResult());
            }

            // Search PropertyToChange TextRange for name
            int    searchStart = PropertyToChange.TextRange.StartOffset;
            int    searchEnd   = PropertyToChange.TextRange.EndOffset;
            string text        = sb.ToString();

            int nameIndex = InsertionHelpers.GetPropertyNameIndex(text, PropertyToChange, searchStart, searchEnd);

            // The last "word" between the start of the property and the name is the type.
            var substring     = text.Substring(searchStart, nameIndex - searchStart);
            int dataTypeStart = substring.IndexOf(PropertyToChange.DataType.ToString());
            var typeName      = substring.Substring(dataTypeStart).TrimEnd();       // PropertyToChange.DataType.ToString();

            if (typeName == null)
            {
                log.ErrorFormat("Could not find type of property {0} to change.", PropertyToChange.Name);
                return(new ActionResult());
            }

            // Find the index of the existing type
            int typeIndex  = substring.LastIndexOf(typeName);
            int typeLength = typeName.Length;

            // Replace the old type with the new one.
            var newTypeName = NewType.ToString();

            sb.Replace(typeName, newTypeName, searchStart + typeIndex, typeLength);
            PropertyToChange.DataType = NewType;

            return(new ActionResult(searchStart + typeIndex, newTypeName.Length - typeLength, null));
        }
        public override ActionResult ApplyActionTo(StringBuilder sb)
        {
            if (PropertyToChange.Name == NewName)
            {
                return(new ActionResult());
            }

            // Search PropertyToChange TextRange for name
            int    searchStart = PropertyToChange.TextRange.StartOffset;
            int    searchEnd   = PropertyToChange.TextRange.EndOffset;
            string text        = sb.ToString();

            int nameIndex = InsertionHelpers.GetPropertyNameIndex(text, PropertyToChange, searchStart, searchEnd);

            // The last "word" between the start of the property and the name is the type.
            var substring = text.Substring(nameIndex, searchEnd - nameIndex);
            var name      = Regex.Split(substring, @"\s+").Where(s => !string.IsNullOrEmpty(s)).FirstOrDefault();

            //int dataTypeStart = substring.IndexOf(PropertyToChange.DataType.Name);
            //var name = substring.Substring(dataTypeStart).TrimEnd();

            if (string.IsNullOrEmpty(name))
            {
                log.ErrorFormat("Could not find name of property {0} to change.", PropertyToChange.Name);
                return(new ActionResult());
            }

            // Find the index of the existing type
            int nameLength = name.Length;

            // Replace the old type with the new one.
            sb.Replace(name, NewName, nameIndex, nameLength);
            PropertyToChange.Name = NewName;

            return(new ActionResult(searchStart + nameIndex, NewName.Length - nameLength, null));
        }