diff --git a/td/tl/tl_dotnet_object.h b/td/tl/tl_dotnet_object.h index b60f2863..e763eb61 100644 --- a/td/tl/tl_dotnet_object.h +++ b/td/tl/tl_dotnet_object.h @@ -100,13 +100,36 @@ auto CLRCALL FromUnmanaged(td::td_api::object_ptr &from) -> decltype(FromUnma return FromUnmanaged(*from.get()); } +#if TD_CLI +template +ref class CallFromUnmanagedRes { +public: + [System::ThreadStaticAttribute] + static property ResT res; +}; + +template +struct CallFromUnmanaged { + template + void operator()(T &val) const { + CallFromUnmanagedRes::res = FromUnmanaged(val); + } +}; +#endif + template inline ResT DoFromUnmanaged(T &from) { +#if TD_WINRT ResT res; downcast_call(from, [&](auto &from_downcasted) { res = FromUnmanaged(from_downcasted); }); return res; +#elif TD_CLI + CallFromUnmanaged res; + downcast_call(from, res); + return CallFromUnmanagedRes::res; +#endif } inline BaseObject^ FromUnmanaged(td::td_api::Function &from) {