Advertisement
konalisp

Fail Fast

Feb 15th, 2017
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.31 KB | None | 0 0
  1.  
  2. using System;
  3.  
  4. namespace FailFast
  5. {
  6.     public static class Assert
  7.     {
  8.         public static Action<String> LogCallback { set; get; }
  9.        
  10.         static Assert()
  11.         {
  12.             LogCallback = (msg) => Console.WriteLine(msg);
  13.         }
  14.        
  15.         public static void NotNull(Object o, String message)
  16.         {
  17.             if (o == null)
  18.             {
  19.                 if (!String.IsNullOrEmpty(message))
  20.                     LogCallback(message);
  21.                 throw new AssertNullReferenceException();
  22.             }
  23.         }
  24.         public static void NotNull(Object o)
  25.         {
  26.             NotNull(o, "");
  27.         }
  28.     }
  29.    
  30.     [Serializable()]
  31.     public class AssertNullReferenceException : System.Exception
  32.     {
  33.         public AssertNullReferenceException() : base() { }
  34.         public AssertNullReferenceException(string message) : base(message) { }
  35.         public AssertNullReferenceException(string message, System.Exception inner) : base(message, inner) { }
  36.  
  37.         // A constructor is needed for serialization when an
  38.         // exception propagates from a remoting server to the client.
  39.         protected AssertNullReferenceException(System.Runtime.Serialization.SerializationInfo info,
  40.             System.Runtime.Serialization.StreamingContext context) { }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement