Question: The problem looks like I've had about 500 files with `if` statements looking like the one I have below. How might I replace these `if` statements without manually overwriting them each by each?

The `if` statement below returns a null reference exception if \_azon is null so that is the main reason behind the replacement of the if statements.

```
 string _azon;
 public string azon
 {
     get { return _azon; }
     set {
         if (((_azon == null) && (value != null)) || !_azon.Equals(value)) {
              _azon = value;
              NotifyPropertyChanged();
          }
      }
  }

```

Answer: 
Based on your question and the code snippet in one of your comments, my understanding is that you want to replace this:

```
if (((_azon == null) && (value != null)) || !_azon.Equals(value)) {

```

with this:

```
if ((_azon == null) && (value != null)) {

```

You can do that with the [Capture groups and replacement patterns](https://learn.microsoft.com/en-us/visualstudio/ide/using-regular-expressions-in-visual-studio?view=vs-2022#capture-groups-and-replacement-patterns) feature in VisualStudio. You need to capture your variable name and use a replacement pattern to substitute it in the replacement string. Capturing the variable name is easy enough using the `\w` character class.

So your search expression would be:

```
if \(\(\((\w+) == null\) && \(value != null\)\) \|\| !\w+\.Equals\(value\)\) {

```

and your replacement pattern would be:

```
if (($1 == null) && (value != null)) {

```

Note the `(\w+)` in the search expression captures your variable, and the `$1` in the replacement pattern substitutes it into the replacement text.

I find this site very useful for creating and testing regular expressions: <https://regex101.com/>

To do [multi-file replacement in VisualStudio 2022](https://learn.microsoft.com/en-us/visualstudio/ide/replace-in-files?view=vs-2022), you bring up the search dialog with the menu using "Edit/Find and Replace/Replace in Files" or use the Ctrl+Shift+H hotkey. On that dialog, you need to check the "Use regular expressions" checkbox.
Assuming your `NotifyPropertyChanged` method is implemented something like this:

```
private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")  
{  
    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}  

```

You could write a function that looks something like:

```
private void SetIfNeeded<T>(T value, ref T prop, [CallerMemberName] string propertyName = "") where T: class, IEquatable<T>
{
    if ((prop == null && value != null) || !prop.Equals(value))
    {
        prop = value;
        NotifyPropertyChanged(propertyName);
    }
}

```

and then consume in within your property setters this way:

```
string _azon;
public string azon
{
    get { return _azon; }
    set {
            SetIfNeeded(value, ref _azon);
        }
    }
}

```