A colleague of mine had written some code using C#'s nullable types, and was apparently unaware of the existence of the
operator. Instead he used the
method, specifically the overload that takes one parameter, since in general the type's default values and the logical defaults differed.
I decided to change this to the more idiomatic form. I thought the logical way to go would be to use ReSharper's Structural Search and Replace. Doing that was easy. The search pattern was simply
and the replace pattern was
$exp$ ?? $value$
, with both exp
being expression placeholders without type constraints.
That worked well, and I decided it might not be a bad idea to keep this pattern around as a quick fix. However, I would really prefer if exp
was constrained to only match expressions that match the unbound type
. I have not been able to find any way to do that. I tried using the unconstructed name
, which did not work. I even tried creating a Type placeholder, and using that in the type constraint of the expression placeholder, but that also did not work. Is there some way to add such a constraint using the Structural Search system?
ReSharper team: If it is not currently possible to add such a constraint, please consider adding a way to do so. That seems like a relatively common thing to want to match in a Structural Search and Replace. Also please consider adding a quick fix (probably of hint severity), or even just a context action that performs the above action. That would help to make the idiomatic
operator more discoverable.