CSharp · Console
/*
PS: code omitted for brevity
http://stackoverflow.com/q/40026856/1842065
*/
using System;
public class Program
{
public class ApiException : Exception
{
public static ApiException FromResult(object result)
{
return new ApiException();
}
}
[STAThread]
public static void Main(string[] args)
{
// Error:
dynamic value1 = 0;
throw ApiException.FromResult(value1);
// OK:
dynamic value2 = 0;
throw ApiException.FromResult((object)value2);
// OK:
var value3 = 0;
throw ApiException.FromResult(value3);
}
}