Browse Source

Fixed the generated C# indexers for specialisations of pointers.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/913/head
Dimitar Dobrev 8 years ago
parent
commit
173c1cd7b7
  1. 10
      src/Generator/Generators/CSharp/CSharpMarshal.cs
  2. 4
      tests/CSharp/CSharpTemplates.h

10
src/Generator/Generators/CSharp/CSharpMarshal.cs

@ -711,8 +711,8 @@ namespace CppSharp.Generators.CSharp @@ -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 @@ -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 @@ -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

4
tests/CSharp/CSharpTemplates.h

@ -455,7 +455,8 @@ void forceUseSpecializations(IndependentFields<int> _1, IndependentFields<bool> @@ -455,7 +455,8 @@ void forceUseSpecializations(IndependentFields<int> _1, IndependentFields<bool>
DependentValueFields<int> _5,
VirtualTemplate<int> _6, VirtualTemplate<bool> _7,
HasDefaultTemplateArgument<int, int> _8, DerivedChangesTypeName<T1> _9,
TemplateWithIndexer<int> _10, TemplateWithIndexer<T1> _11, std::string s);
TemplateWithIndexer<int> _10, TemplateWithIndexer<T1> _11,
TemplateWithIndexer<T2*> _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<int>;
@ -470,3 +471,4 @@ template class DLL_API HasDefaultTemplateArgument<int, int>; @@ -470,3 +471,4 @@ template class DLL_API HasDefaultTemplateArgument<int, int>;
template class DLL_API DerivedChangesTypeName<T1>;
template class DLL_API TemplateWithIndexer<int>;
template class DLL_API TemplateWithIndexer<T1>;
template class DLL_API TemplateWithIndexer<T2*>;

Loading…
Cancel
Save