3#include <msclr/gcroot.h>
4#include <msclr/marshal.h>
5#include <msclr/marshal_cppstd.h>
15 template <
typename ToType>
18 template <
typename FromType>
19 static ToType From(
const FromType& from)
21 return msclr::interop::marshal_as<ToType>(from);
25 static ToType From(
const ToType& from)
35 static std::string From(String^
const & mString)
37 if (mString ==
nullptr)
42 return msclr::interop::marshal_as<std::string>(mString);
45 template <
typename FromType>
46 static std::string From(
const FromType& from)
48 return msclr::interop::marshal_as<std::string>(from);
54 struct MarshalTo<Datamine::MineTrustConnector::Core::LogEvent>
58 return static_cast<Datamine::MineTrustConnector::Core::LogEvent
>(value);
64 struct MarshalTo<MineTrustConnector::CppCliInterop::LogEvent>
72 template <
typename ToDataType>
75 template <
typename FromDataType>
76 static std::unique_ptr<ToDataType> From(System::Nullable<FromDataType> value)
78 std::unique_ptr<ToDataType> res;
82 res = std::make_unique<ToDataType>(MarshalTo<ToDataType>::From(value.Value));
89 template <
typename ToDataType>
92 template <
typename FromDataType>
93 static System::Nullable<ToDataType> From(
const std::unique_ptr<FromDataType>& value)
97 return System::Nullable<ToDataType>(MarshalTo<ToDataType>::From(*value));
101 return System::Nullable<ToDataType>();
107 template <
typename ToItemType>
110 template <
typename FromType,
typename ... ExtraArgs>
111 static auto From(FromType&& list, ExtraArgs&&... extraArgs)
113 std::vector<ToItemType> mList;
120 for each (
auto item
in list)
122 mList.emplace_back(MarshalTo<ToItemType>::From(item, std::forward<ExtraArgs>(extraArgs)...));
130 template <
typename ToKeyType,
typename ToValueType>
131 struct MarshalTo<std::unordered_map<ToKeyType, ToValueType>>
133 template <
typename FromType>
134 static auto From(FromType&& dictionary)
136 std::unordered_map<ToKeyType, ToValueType> mDictionary;
138 if (
nullptr == dictionary)
143 mDictionary.reserve(dictionary->Count);
145 for each (
auto dictionaryEntry
in dictionary)
147 mDictionary[MarshalTo<ToKeyType>::From(dictionaryEntry.Key)] = MarshalTo<ToValueType>::From(dictionaryEntry.Value);
155 template <
typename ToItemType>
156 struct MarshalTo<Collections::Generic::IEnumerable<ToItemType>^>
158 template <
typename FromType,
typename ... ExtraArgs>
159 static Collections::Generic::List<ToItemType>^ From(FromType&& list, ExtraArgs&&... extraArgs)
166 auto mList = gcnew Collections::Generic::List<ToItemType>(
static_cast<int>(list.size()));
168 for (
const auto& item : list)
170 mList->Add(MarshalTo<ToItemType>::From(item, std::forward<ExtraArgs>(extraArgs)...));
177 template <
typename ToItemType>
180 template <
typename FromType,
typename ... ExtraArgs>
181 static array<ToItemType>^ From(FromType&& list, ExtraArgs&&... extraArgs)
188 auto mArray = gcnew array<ToItemType>(
static_cast<int>(list.size()));
191 for (
const auto& item : list)
193 mArray[index] = MarshalTo<ToItemType>::From(item, std::forward<ExtraArgs>(extraArgs)...);
202 template <
typename ToKeyType,
typename ToValueType>
203 struct MarshalTo<Collections::Generic::IDictionary<ToKeyType, ToValueType>^>
205 template <
typename FromType>
206 static Collections::Generic::Dictionary<ToKeyType, ToValueType>^ From(FromType&& dictionary)
208 if (dictionary.empty())
213 auto mDictionary = gcnew Collections::Generic::Dictionary<ToKeyType, ToValueType>();
215 for (
const auto& it : dictionary)
217 mDictionary[MarshalTo<ToKeyType>::From(it.first)] = MarshalTo<ToValueType>::From(it.second);
230 using clock = std::chrono::system_clock;
231 using duration = clock::duration;
232 using time_point = clock::time_point;
234 static time_point From(DateTime value)
236 const DateTime epochCpp(1970, 1, 1);
237 const DateTime epochClr(1, 1, 1);
238 const TimeSpan epochDiff = epochCpp - epochClr;
239 return time_point(duration((value - epochDiff).Ticks));
244template <
typename ToType,
typename FromType,
typename ... ExtraArgs>
245ToType Marshal(
const FromType& fromObject, ExtraArgs&&... extraArgs)
247 return detail::MarshalTo<ToType>::From(fromObject, std::forward<ExtraArgs>(extraArgs)...);
250template <
typename ManagedType>
251msclr::gcroot<ManagedType^> MakeGcRoot(ManagedType^ managedType)
LogEvent
Definition CppCliInterop.h:32
Definition MarshalUtils.h:17