2
Vote

Partial Text Replacement

description

Suppose I have a block of code like this from which I want to create a snippet.
public class MapObjectComparer : IComparer<MapObject>
{
    public int Compare(MapObject o1, MapObject o2)
    {
        if (o1 == null)
        {
            if (o2 == null)
                return 0;
            else
                return -1;
        }
        if (o2 == null)
            return 1;

        if (o1.ObjectID < o2.ObjectID)
            return -1;
        else if (o1.ObjectID > o2.ObjectID)
            return 1;
        else
            return 0;
    }
}
I wish to replace every occurence of "MapObject" with $ComparerClassName$.
If I highlight only the substring "MapObject" in the class name "MapObjectComparer" the snippet designer replaces
only the full word "MapObject". Is it possible to have an option to replace also the substrings?

comments

mmanela wrote Jun 11, 2011 at 6:35 PM

While it is possible it can start to behave oddly. For example if you choose the letter "i" are your replacement, then there are many words that have i in them but it would be wrong to turn them all into replacements.

slear wrote Jun 12, 2011 at 8:46 PM

I understand your objection, though I still think it is a desirable feature.
There are many ways to shoot yourself in the foot, but, as programmers, we should avoid doing things so stupid.
Thanks anyway for the answer.