Ejemplo n.º 1
0
 /// <summary>
 /// Allows calling the <see cref="IMyInterface.MyInterfaceMethod"/> method against the null reference.
 /// </summary>
 /// <param name="myInterface">An instance of the <see cref="IMyInterface"/>.</param>
 /// <exception cref="ArgumentNullException"> - it the <paramref name="myInterface"/> is null.</exception>
 public static void ProtectedMyInterfaceMethodCall(this IMyInterface myInterface)
 {
     if (myInterface == null)
     {
         throw new ArgumentNullException($"{nameof(myInterface)} cannot be null.");
     }
     myInterface.MyInterfaceMethod();
 }
Ejemplo n.º 2
0
        public void NullCallExceptionTest()
        {
            IMyInterface _myInterface = null;

            _myInterface.MyInterfaceMethod(); //Here the runtime throws the exception NullReferenceException.
        }