Is there a way to do dynamic implicit type casting in C#?
问题 Given this class with an implicit cast operator: public class MyDateTime { public static implicit operator MyDateTime(System.Int64 encoded) { return new MyDateTime(encoded); } public MyDateTime(System.Int64 encoded) { _encoded = encoded; } System.Int64 _encoded; } I can now do the following: long a = 5; MyDateTime b = a; But NOT the following: long f = 5; object g = f; MyDateTime h = g; This gives a compile time: Cannot implicitly convert type 'object' to 'MyDateTime'. Makes sense to me. Now