I tried this:
var info = App.GetResourceStream(picUri);
if (info != null) ...
This works less well than I hoped, because GetResourceStream throws an exception if the resource doesn't exist, rather than simply return null. OK, I do kinda like this approach that methods should always throw exceptions when they don't do what they were
asked to do, rather than return null possibly leading to some much-harder-to-fathom NullReferenceException down the line. Surely I can just use the TryGetResourceStream method, right? Wrong - there's no such method. Nor did I, in a few minutes of searching,
find any other method that serves the same purpose.
While I could of course catch the exception that's hardly "best practice", and in this case I'll be looping and doing this over and over (only ~330 times, but still). More to the point though, I may find myself in a situation where it (the performance
impact of causing and catching a bunch of needless exceptions) *really* matters in the future, so I'd like to know how to do it properly.
På forhånd takk, merci d'avance, Bob (if the trend keeps up) or whoever provides an answer to this hopefully simple question.
View Complete Post