[System.ServiceModel] Prevent crash in Dispatcher.ListenerLoopManager… (#7136)
[mono-project.git] / mono / tests / delegate14.cs
blob36c6f896e8ad9219050f4d5e7c3be2b7a59ffc56
1 using System;
3 // Regression test for bug #58888
5 public static class Program
7 public static int Main (string[] args)
9 // calling delegate on extension method with null target is allowed
10 Func<int> func = null;
11 if (CallFunc(func.CallFuncIfNotNull) != 0)
12 return 2;
14 // constructing delegate on instance method with null target should throw
15 ITest obj = null;
16 try
18 GC.KeepAlive((Action)obj.Func);
20 catch (NullReferenceException)
22 return 0;
25 return 1;
28 interface ITest
30 void Func ();
33 static int CallFunc(Func<int> func)
35 return func();
39 public static class FuncExtensions
41 public static int CallFuncIfNotNull(this Func<int> func)
43 if (func != null)
44 return func();
46 return 0;