In .NET there is such a wonderful thing as TransactionScope .
By marking a domain using all the work with the database in a certain domain will be in an implicit transaction.
Does there exist (if not, is it realizable) something similar for ordinary variables?
Let's say that a set of objects is passed to the method and it is important that “all or nothing” be executed in a certain area. If nothing happens, the calling code will not see any changes and seeing the error will be able to try to re-do the method without worrying that the data is in an inconsistent state.
For example:
public bool TryDoWork(Someclass someclass) { using (var tran=new TransactionScope()) { try { someclass.Field = 100500; someclass.Modify("123qwe"); } catch (Exception e) { return false; } tran.Commit(); } } Some abstract class is passed. Accordingly, if Commit is not called, the class variable is not in an inconsistent state and the external code does not need to worry about correcting the data before attempting to do something again.
This article says something similar, but is it possible to create a universal solution taking into account the nature of classes?
PS Question of interest for the sake of.