13
13
#include < string>
14
14
#include < ostream>
15
15
#include < vcclr.h>
16
- #include < msclr/marshal .h>
16
+ #include < msclr/marshal_cppstd .h>
17
17
18
18
public interface class ICppInstance
19
19
{
@@ -24,6 +24,23 @@ public interface class ICppInstance
24
24
}
25
25
};
26
26
27
+ namespace msclr {
28
+ namespace interop {
29
+
30
+ template <>
31
+ inline System::String^ marshal_as(const std::string_view& _from_obj)
32
+ {
33
+ return details::InternalAnsiToStringHelper (_from_obj.data (), _from_obj.length ());
34
+ }
35
+
36
+ template <>
37
+ inline System::String^ marshal_as(const std::wstring_view& _from_obj)
38
+ {
39
+ return details::InternalUnicodeToStringHelper (_from_obj.data (), _from_obj.length ());
40
+ }
41
+ }
42
+ }
43
+
27
44
// CLI extensions namespace
28
45
namespace clix {
29
46
@@ -202,18 +219,18 @@ namespace clix {
202
219
// / </remarks>
203
220
// / <param name="string">String to be marshalled to the other side</param>
204
221
// / <returns>The marshaled representation of the string</returns>
205
- template <Encoding encoding, typename SourceType>
206
- typename detail::IfManaged<SourceType>::Select::Either<
207
- typename detail::StringTypeSelector<encoding>::Type,
208
- System::String ^
209
- >::Type marshalString (SourceType string) {
210
- constexpr detail::MarshalingDirection direction =
222
+ template <Encoding encoding, typename SourceType, class ResultType =
223
+ typename detail::IfManaged<SourceType>::Select::Either<
224
+ typename detail::StringTypeSelector<encoding>::Type,
225
+ System::String^>::Type
226
+ >
227
+ ResultType marshalString (SourceType string) {
228
+ return msclr::interop::marshal_as<ResultType>(string);
229
+ /* constexpr detail::MarshalingDirection direction =
211
230
detail::IfManaged<SourceType>::Result ? detail::CxxFromNet : detail::NetFromCxx;
212
231
using StringMarshaler = detail::StringMarshaler<direction>;
213
-
214
232
// Pass on the call to our nifty template routines
215
- return StringMarshaler::template marshal<encoding, SourceType>(string);
216
-
233
+ return StringMarshaler::template marshal<encoding, SourceType>(string);*/
217
234
}
218
235
219
236
} // namespace clix
0 commit comments