aboutsummaryrefslogtreecommitdiff
path: root/libs/installer_fomod_csharp/src/csharp_utils.h
blob: 5ede874379f3c1c62763d8e8d35a06358e115798 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// clang-format off

#ifndef CSHARP_UTILS_H
#define CSHARP_UTILS_H

#include <type_traits>
#include <string>

#include <QString>

#include <msclr\marshal_cppstd.h>

#using <System.dll>

namespace CSharp {

  /**
   * Handy functions.
   */
  inline std::string to_string(System::String^ value) {
    return msclr::interop::marshal_as<std::string>(value);
  }
  inline std::wstring to_wstring(System::String^ value) {
    return msclr::interop::marshal_as<std::wstring>(value);
  }
  inline QString to_qstring(System::String^ value) {
    msclr::interop::marshal_context ctx;
    return QString::fromWCharArray(ctx.marshal_as<const wchar_t*>(value));
  }

  template <class Str>
  inline System::String^ from_string(Str const& string) {
    return msclr::interop::marshal_as<System::String^>(string);
  }
  inline System::String^ from_string(QString const& string) {
    return msclr::interop::marshal_as<System::String^>(string.toStdWString().c_str());
  }

}

#endif