Beef icon indicating copy to clipboard operation
Beef copied to clipboard

[Enhancement] Dynamic casting

Open RogueMacro opened this issue 5 years ago • 3 comments

By dynamic casting, I mean to cast an object to a Type at runtime. Specifically being able to cast it to an interface that can be passed to a constructor invoked at runtime.

RogueMacro avatar Jan 21 '21 10:01 RogueMacro

Something like this?

(T*)Internal.UnsafeCastToPtr(xy);

xposure avatar Jan 22 '21 00:01 xposure

No, not generic. I meant using a Type object. Like typeof(T)

RogueMacro avatar Jan 22 '21 12:01 RogueMacro

@bfiete You could close this as dynamic casting it provided by Variants.

BaseItem item;
Item itemImpl = scope .();
Variant variant = Variant.Create(typeof(BaseItem), &itemImpl);
item = variant.Get<BaseItem>(); // or Get<Object>()

RogueMacro avatar Feb 04 '21 12:02 RogueMacro