C# dynamically casting generic object at runtime -
edit: changed wrong term boxing casting.
i have following problem:
if create new delegate of type action or func casted type of delegate.
var @delegate = delegate.createdelegate(type, @object, methodinfo);
but need generic class right casted object.
consider following example:
class example<t> { type generictype() { return typeof(t); } } static example<t> create<t>(t @delegate) { return new example<t>(); } example.create(@delegate).generictype();
this return delegate type, since type of casted object (@delegate).
one solution cast delegate so:
if(@delegate action) example.create((action)@delegate).generictype();
but since delegate.createdelegate create action or func delegates, impossible check variations.
i can't change generic class, must cast delegate.
i hope able explain problem. not native english speaker...
edit: problem typeof(t) not return "real" type of object. i'm afraid there no solution.
what's wrong @delegate.gettype()
actual type of delegate?
also, side note: misusing term "boxing".
Comments
Post a Comment