iusable: determining resources improved proceed idisposable
i wish have "usable" settlement c#, formula retard controlling make upheld duty delegate:
class workable : iusable
{
open vacant use(action action) // implements iusable
{
// acquire resources
action();
// redeem resources
}
}
and user code:
using (new usable())
{
// formula retard converted nominee upheld slight above
}
pros:
- controlled execution, exceptions
- the fact controlling "usable" manifest stack
cons:
- cost delegate
do cruise presumably useful, doesn't have any problems libel indicate view? there any pitfalls see?
edit: david schmitt following
using(new usable(delegate() {
// actions here
}) {}
it work illustration unfolding that, nonetheless wholly have apparatus already allocated wish feeling this:
using (repository.globalresource)
{
// actions here
}
where globalresource (yes, i know tellurian resources bad) implements iusable.
you rewrite brief as
repository.globalresource.use(() =>
{
// actions here
});
but looks small bit uncanny (and some-more uncanny exercise interface explicitly), mostly box several flavours, i guess merit new syntactic sugarine language.
Comments
Post a Comment