Another approach using a local function to simplify the call:
void add(string s) => if (s != null) builder.Attachments.Add(s, CraftAttachment(data));
add( data.Subscriber.Protocol switch
{
"email json" => "Očitanje.json",
"email text" => "Očitanje.txt",
_ => null
});
(Although I think that some folks would criticize that as "too cute...)
NOTE: This solution (like the other solutions) suffers from a drawback.
The code will always make an additional test against null, which the straightforward switch doesn't do - so this is (very marginally) less efficient.
I personally would do it like this (which avoids the drawback):
void add(string s) => builder.Attachments.Add(s, CraftAttachment(data));
switch (data.Subscriber.Protocol)
{
case "email json": add("Očitanje.json"); break;
case "email text": add("Očitanje.txt") break;
default: /* Do nothing */ break;
}
Simple local functions like that are very likely to be inlined by the JIT compiler, so there should be no overhead.