diff --git a/src/Generator/Generators/CSharp/CSharpMarshal.cs b/src/Generator/Generators/CSharp/CSharpMarshal.cs index dfde7954..f78ec12f 100644 --- a/src/Generator/Generators/CSharp/CSharpMarshal.cs +++ b/src/Generator/Generators/CSharp/CSharpMarshal.cs @@ -711,8 +711,8 @@ namespace CppSharp.Generators.CSharp { var replacement = param.Replacement.Type.Desugar(); Class @class; - Context.Return.Write($@"{(replacement.TryGetClass(out @class) ? - string.Empty : $"({replacement}) (object) ")}"); + if (!replacement.IsAddress() && !replacement.TryGetClass(out @class)) + Context.Return.Write($"({replacement}) (object) "); return base.VisitTemplateParameterSubstitutionType(param, quals); } @@ -756,10 +756,10 @@ namespace CppSharp.Generators.CSharp Class @interface; var finalType = type.GetFinalPointee() ?? type; var templateType = finalType as TemplateParameterSubstitutionType; + type = Context.Parameter.Type.Desugar(); if (finalType.TryGetClass(out @interface) && @interface.IsInterface) - paramInstance = string.Format("{0}.__PointerTo{1}", - param, @interface.OriginalClass.Name); + paramInstance = $"{param}.__PointerTo{@interface.OriginalClass.Name}"; else paramInstance = $@"{ (templateType != null ? $"(({@class.Visit(typePrinter)}) (object) " : string.Empty)}{ @@ -777,7 +777,7 @@ namespace CppSharp.Generators.CSharp Context.Return.Write("{0}{1}", method != null && method.OperatorKind == CXXOperatorKind.EqualEqual ? string.Empty - : string.Format("ReferenceEquals({0}, null) ? global::System.IntPtr.Zero : ", param), + : $"ReferenceEquals({param}, null) ? global::System.IntPtr.Zero : ", paramInstance); } else diff --git a/tests/CSharp/CSharpTemplates.h b/tests/CSharp/CSharpTemplates.h index 31505d9d..13de4bd6 100644 --- a/tests/CSharp/CSharpTemplates.h +++ b/tests/CSharp/CSharpTemplates.h @@ -455,7 +455,8 @@ void forceUseSpecializations(IndependentFields _1, IndependentFields DependentValueFields _5, VirtualTemplate _6, VirtualTemplate _7, HasDefaultTemplateArgument _8, DerivedChangesTypeName _9, - TemplateWithIndexer _10, TemplateWithIndexer _11, std::string s); + TemplateWithIndexer _10, TemplateWithIndexer _11, + TemplateWithIndexer _12, std::string s); // force the symbols for the template instantiations because we do not have the auto-compilation for the generated C++ source template class DLL_API IndependentFields; @@ -470,3 +471,4 @@ template class DLL_API HasDefaultTemplateArgument; template class DLL_API DerivedChangesTypeName; template class DLL_API TemplateWithIndexer; template class DLL_API TemplateWithIndexer; +template class DLL_API TemplateWithIndexer;