Answer the question
In order to leave comments, you need to log in
Confirmation of Major Operations
When performing serious operations, it is customary to ask users for their confirmation.
And than users of classes are worse? :)
public class AreYouSure
{
private readonly Action _yes ;
public void Yes ( ) { _yes ( ) ; }
public void No ( ) { /*do nothing*/ }
public AreYouSure ( Action yes ) { this ._yes = yes ?? ( ( ) => { } ) ; }
}
***
public class LocalFile
{
private readonly string _filename ;
public LocalFile ( string filename ) { this ._filename = filename ; }
public AreYouSure Delete ( ) { return new AreYouSure ( ( ) => File. Delete ( this ._filename ) ) ; }
}
***
class Program
{
static void Main( string [ ] args )
{
LocalFile file = new LocalFile ( @"c:test.txt" ) ;
AreYouSure confirmation = file. delete ( ) ;
confirmation. Yes ( ) ;
}
}
Answer the question
In order to leave comments, you need to log in
We are waiting for an extension for Visual Studio that will automatically compile Confirm.Yes() for all objects of this class :-D
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question