Kiel
IDisposable ownership semantics
to answer your question bluntly, no C# does not have first class support for...whatever it is you're trying to express. We have try/finally, try/catch, and the various forms of
using
. But it seems like you're pretty much asking for a way to create an object, do work with it, and return it, and dispose it ONLY if an exception is thrown. If you're re-using this logic lots, you could probably use the above suggestion as a wrapper, but otherwise yeah the way you're doing it is probably about as clean as it's gonna get without re-throwing28 replies
IDisposable ownership semantics
If you are using only
try { } finally { }
, perhaps consider using a, well...using
statement or expression?
I'm not sure what the point of setting result
to null is in your original code, but what I just posted above is syntactically equivalent to
28 replies
How to convert a whole json file to C# classes with Newtonsoft.Json?
Personally in the past I used https://quicktype.io/ to make a quick and dirty concept and then I'd refine it from there to my liking
43 replies
✅ Is it possible to clean up all this in a vs release folder?
It looks like you're using Humanizer, it might help to install Humanizer.Core if you JUST want english-language features - it won't produce just an exe file like above mentioned but it will at least keep all those extra folders from being generated
7 replies
✅ Exception handling
There's nothing stopping you from throwing your own exception in a
catch
block, but generally you should have a good reason for doing so. A proper real-world usecase could be if you have your own generic ErrorException
type which wraps other exceptions so you can display more detailed information than a plain old DivideByZeroException
can31 replies