Guest User

Passive MVP Implementation

a guest
Jan 30th, 2015
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.95 KB | None | 0 0
  1.     /// <summary>
  2.     /// Defines a presenter.
  3.     /// </summary>
  4.     /// <typeparam name="TView">The type of the view the presenter uses.</typeparam>
  5.     public interface IPresenter<TView>
  6.         where TView : IView
  7.     {
  8.         /// <summary>
  9.         /// Gets the view.
  10.         /// </summary>
  11.         TView View { get; }
  12.     }
  13.  
  14.  
  15.  
  16.     /// <summary>
  17.     /// Base implementation of a presenter.
  18.     /// </summary>
  19.     /// <typeparam name="TView">The type of view the presenter uses.</typeparam>
  20.     public class Presenter<TView> : IPresenter<TView>
  21.         where TView : IView
  22.     {
  23.         /// <summary>
  24.         /// Gets the view.
  25.         /// </summary>
  26.         public TView View { get { return _view; } }
  27.         private readonly TView _view;
  28.  
  29.         /// <summary>
  30.         /// Creates a new <see cref="Presenter"/>.
  31.         /// </summary>
  32.         /// <param name="view">The view attached to the presenter.</param>
  33.         public Presenter(TView view)
  34.         {
  35.             ThrowIf.Null(() => view);
  36.  
  37.             _view = view;
  38.         }
  39.     }
  40.  
  41.  
  42.  
  43.     /// <summary>
  44.     /// Defines a view.
  45.     /// </summary>
  46.     public interface IView
  47.     {
  48.     }
  49.  
  50.  
  51.  
  52.     /// <summary>
  53.     /// Event args that requires to invoke and action.
  54.     /// </summary>
  55.     public class ActionEventArgs : EventArgs
  56.     {
  57.         /// <summary>
  58.         /// Defines an empty value.
  59.         /// </summary>
  60.         public static new ActionEventArgs Empty = new ActionEventArgs(null);
  61.  
  62.         /// <summary>
  63.         /// Gets the action.
  64.         /// </summary>
  65.         /// <value>The action.</value>
  66.         public Action Action { get { return _action; } }
  67.         private readonly Action _action;
  68.  
  69.         /// <summary>
  70.         /// Gets a value indicating whether this instance has an action.
  71.         /// </summary>
  72.         /// <value><c>true</c> if this instance has an action; otherwise, <c>false</c>.</value>
  73.         public bool HasAction {get{ return _action != null; }}
  74.  
  75.         public ActionEventArgs (Action action)
  76.             : base()
  77.         {
  78.             _action = action;
  79.         }
  80.     }
Advertisement
Add Comment
Please, Sign In to add comment