So, I have a general class (this is basically a container class) with implicit casting, for example:
public class Container<T> { public T Value { get; set; } public static implicit operator T(Container<T> t) { return t.Value; } public static implicit operator Container<T>(T t) { return new Container<T>() { Value = t }; } }
So, at runtime, I would like to cast the Container<int> instance to int using reflection, but I canโt find a way, I tried the Cast method mentioned in several places, but I get a Specified cast is not valid. exception Specified cast is not valid. .
Any help would be appreciated.
source share