Question

I hope you guys might help me become smarter. I am making a simple VS2012 Addin. The Addin is a more extensive search/replace functionality specific to a task regularly performed at our company. I have a Tools menu option added in Visual Studio which should open an extended Find/Replace dialog where I may input several Find/Replace textboxes. In the end I need to include the options checkboxes that are available in the original dialog ('Match case','Match whole word','Use Regular Expressions').

The problem is that in the ReplaceText or ReplacePattern methods they only allow for one optional int parameter to be passed, the enum used to provide one of the options is vsFindOptions which looks like this:

[Guid("A457303F-D058-4415-A2B4-A81B148C7689")]
public enum vsFindOptions
{
    vsFindOptionsNone = 0,
    vsFindOptionsMatchWholeWord = 2,
    vsFindOptionsMatchCase = 4,
    vsFindOptionsRegularExpression = 8,
    vsFindOptionsBackwards = 128,
    vsFindOptionsFromStart = 256,
    vsFindOptionsMatchInHiddenText = 512,
    vsFindOptionsWildcards = 1024,
    vsFindOptionsSearchSubfolders = 4096,
    vsFindOptionsKeepModifiedDocumentsOpen = 8192,
}

I was looking through the documentation at MSDN [1] where I can see an example:

[...].ReplacePattern("test", "done deal", 
    (int)vsFindOptions.vsFindOptionsNone, ref dummy); 

That is all good, but what I would like to do is more like this:

[...].ReplacePattern(@"<span (.\w.+?>)", string.Empty,
    (int)vsFindOptions.vsFindOptionsRegularExpression, 
    (int)vsFindOptions.vsFindOptionsMatchWholeWord);

Consider the original find/replace dialog - the options are checkboxes, this multiple choice options but the ReplacePattern method only accept one int. May I simply add the values together as such:

(int)vsFindOptions.vsFindOptionsRegularExpression+
(int)vsFindOptions.vsFindOptionsMatchWholeWord ? 

(Will try this later but having debug problems atm, addin not available anymore in vs)

Was it helpful?

Solution

You should be able to use the bitwise OR operator '|', so

[...].ReplacePattern(@"<span (.\w.+?>)", string.Empty,
    vsFindOptions.vsFindOptionsRegularExpression | 
    vsFindOptions.vsFindOptionsMatchWholeWord);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top