G
G
googman2012-02-24 22:05:00
C++ / C#
googman, 2012-02-24 22:05:00

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 ( ) ;
    }
}

PS I couldn't post it in Codebred, so I'm posting it here.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vampiro, 2012-02-25
@Vampiro

and where to check the box "for all the next 100500 operations"?

A
Alexander Kouznetsov, 2012-02-25
@unconnected

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 question

Ask a Question

731 491 924 answers to any question