Skip to content

Commit 0b58d28

Browse files
committed
Use msclr string marshallers
1 parent 7bbb4f5 commit 0b58d28

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

include/CppSharp.h

+27-10
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include <string>
1414
#include <ostream>
1515
#include <vcclr.h>
16-
#include <msclr/marshal.h>
16+
#include <msclr/marshal_cppstd.h>
1717

1818
public interface class ICppInstance
1919
{
@@ -24,6 +24,23 @@ public interface class ICppInstance
2424
}
2525
};
2626

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+
2744
// CLI extensions namespace
2845
namespace clix {
2946

@@ -202,18 +219,18 @@ namespace clix {
202219
/// </remarks>
203220
/// <param name="string">String to be marshalled to the other side</param>
204221
/// <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 =
211230
detail::IfManaged<SourceType>::Result ? detail::CxxFromNet : detail::NetFromCxx;
212231
using StringMarshaler = detail::StringMarshaler<direction>;
213-
214232
// 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);*/
217234
}
218235

219236
} // namespace clix

0 commit comments

Comments
 (0)