String interpolation is great and snippets are great, but they don't play nice together. I have a snippet that looks (in part) like this:
job.Location = $"{e["$locationfield$"]}";
return true;
The locationfield
part is supposed to be the replacement, but of course it will see as '"{e["
being a replacement. So when you try to use the snippet, that part is messed up:
job.Location = locationfield
And the rest of the code following is gone (because it can't match another $
presumably).
Is there a way around that? Or can you just not use string interpolation in your snippets?
Structure of an interpolated string. To identify a string literal as an interpolated string, prepend it with the $ symbol. You can't have any white space between the $ and the " that starts a string literal. To concatenate multiple interpolated strings, add the $ special character to each string literal.
String Interpolation is a process in which the placeholder characters are replaced with the variables (or strings in this case) which allow to dynamically or efficiently print out text output. String Interpolation makes the code more compact and avoids repetition of using variables to print the output.
Ok, as it turns out, it's dead simple. I did this on a whim and it worked:
job.Location = $$"{e["$locationfield$"]}";
return true;
Another solution that I didn't try, is that you can actually specify what the snippet should use as a delimiter:
<Code Language="csharp" Delimiter="$">
Just change the $
to something else you aren't using in this particular block of code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With