diff --git a/src/Generator/Driver.cs b/src/Generator/Driver.cs index 8c8109aa..bd16c0d7 100644 --- a/src/Generator/Driver.cs +++ b/src/Generator/Driver.cs @@ -73,7 +73,7 @@ namespace CppSharp { ValidateOptions(Options); - TypeDatabase.SetupTypeMaps(); + TypeDatabase.SetupTypeMaps(Options.GeneratorKind); Generator = CreateGeneratorFromKind(Options.GeneratorKind); } diff --git a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs index 7ac511dd..322f59ba 100644 --- a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs +++ b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs @@ -790,8 +790,8 @@ namespace CppSharp.Generators.CSharp // we do not support dependent fields yet, see https://github.com/mono/CppSharp/issues/197 Class @class; field.Type.TryGetClass(out @class); - if (field.Type.IsDependent && !field.Type.IsPointer() && - !(@class != null && @class.IsUnion)) + if ((field.Type.IsDependent && !field.Type.IsPointer() && + !(@class != null && @class.IsUnion)) || (@class != null && @class.TranslationUnit.IsSystemHeader)) return; var safeIdentifier = Helpers.SafeIdentifier(field.OriginalName); diff --git a/src/Generator/Types/Std/Stdlib.cs b/src/Generator/Types/Std/Stdlib.cs index 594b4fe8..515b2f03 100644 --- a/src/Generator/Types/Std/Stdlib.cs +++ b/src/Generator/Types/Std/Stdlib.cs @@ -26,7 +26,7 @@ namespace CppSharp.Types.Std } } - [TypeMap("std::string")] + [TypeMap("std::string", GeneratorKind.CLI)] public class String : TypeMap { public override string CLISignature(CLITypePrinterContext ctx) @@ -305,7 +305,7 @@ namespace CppSharp.Types.Std } } - [TypeMap("std::ostream")] + [TypeMap("std::ostream", GeneratorKind.CLI)] public class OStream : TypeMap { public override string CLISignature(CLITypePrinterContext ctx) diff --git a/src/Generator/Types/TypeMap.cs b/src/Generator/Types/TypeMap.cs index cedd4b23..a03ccac0 100644 --- a/src/Generator/Types/TypeMap.cs +++ b/src/Generator/Types/TypeMap.cs @@ -15,11 +15,18 @@ namespace CppSharp.Types public class TypeMapAttribute : Attribute { public string Type { get; private set; } + public GeneratorKind? GeneratorKind { get; set; } public TypeMapAttribute(string type) { Type = type; } + + public TypeMapAttribute(string type, GeneratorKind generatorKind) + { + Type = type; + GeneratorKind = generatorKind; + } } /// @@ -117,27 +124,28 @@ namespace CppSharp.Types TypeMaps = new Dictionary(); } - public void SetupTypeMaps() + public void SetupTypeMaps(GeneratorKind generatorKind) { var loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (var assembly in loadedAssemblies) { var types = assembly.FindDerivedTypes(typeof(TypeMap)); - SetupTypeMaps(types); + SetupTypeMaps(types, generatorKind); } } - private void SetupTypeMaps(IEnumerable types) + private void SetupTypeMaps(IEnumerable types, GeneratorKind generatorKind) { foreach (var typeMap in types) { var attrs = typeMap.GetCustomAttributes(typeof(TypeMapAttribute), true); - if (attrs == null) continue; - foreach (TypeMapAttribute attr in attrs) { - TypeMaps[attr.Type] = typeMap; + if (attr.GeneratorKind == null || attr.GeneratorKind == generatorKind) + { + TypeMaps[attr.Type] = typeMap; + } } } } diff --git a/tests/Basic/Basic.cpp b/tests/Basic/Basic.cpp index 5ed172db..3491e0af 100644 --- a/tests/Basic/Basic.cpp +++ b/tests/Basic/Basic.cpp @@ -308,3 +308,8 @@ void va_listFunction(va_list v) void TestDelegates::MarshalUnattributedDelegate(DelegateInGlobalNamespace del) { } + +std::string HasStdString::testStdString(std::string s) +{ + return s + "_test"; +} diff --git a/tests/Basic/Basic.h b/tests/Basic/Basic.h index 7627f08e..63bd1414 100644 --- a/tests/Basic/Basic.h +++ b/tests/Basic/Basic.h @@ -1,6 +1,7 @@ #include "../Tests.h" #include +#include class DLL_API IgnoredType { @@ -571,3 +572,11 @@ struct DLL_API TestEmptyName }; }; }; + +class DLL_API HasStdString +{ + // test if these are ignored with the C# back-end +public: + std::string testStdString(std::string s); + std::string s; +}; diff --git a/tests/CLITemp/CLITemp.Tests.cs b/tests/CLITemp/CLITemp.Tests.cs index 9870f259..5a58778a 100644 --- a/tests/CLITemp/CLITemp.Tests.cs +++ b/tests/CLITemp/CLITemp.Tests.cs @@ -1,7 +1,6 @@ using CppSharp.Utils; using NUnit.Framework; using CLITemp; -using System; public class CLITests : GeneratorTestFixture { @@ -20,4 +19,10 @@ public class CLITests : GeneratorTestFixture var s = date.ToString(); Assert.AreEqual("24/12/1924", s); } + + [Test] + public void TestStdString() + { + Assert.AreEqual("test_test", CLITemp.CLITemp.testStdString("test")); + } } \ No newline at end of file diff --git a/tests/CLITemp/CLITemp.cpp b/tests/CLITemp/CLITemp.cpp index 9ff8c037..7ab0c26d 100644 --- a/tests/CLITemp/CLITemp.cpp +++ b/tests/CLITemp/CLITemp.cpp @@ -4,3 +4,8 @@ int Types::AttributedSum(int A, int B) { return A + B; } + +std::string testStdString(std::string s) +{ + return s + "_test"; +} diff --git a/tests/CLITemp/CLITemp.h b/tests/CLITemp/CLITemp.h index 8d612e51..038bbd01 100644 --- a/tests/CLITemp/CLITemp.h +++ b/tests/CLITemp/CLITemp.h @@ -45,3 +45,5 @@ std::ostream& operator<<(std::ostream& os, const Date& dt) os << dt.mo << '/' << dt.da << '/' << dt.yr; return os; } + +DLL_API std::string testStdString(std::string s);