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
{ {
var replacement = param.Replacement.Type.Desugar(); var replacement = param.Replacement.Type.Desugar();
Class @class; Class @class;
Context.Return.Write($@"{(replacement.TryGetClass(out @class) ? if (!replacement.IsAddress() && !replacement.TryGetClass(out @class))
string.Empty : $"({replacement}) (object) ")}"); Context.Return.Write($"({replacement}) (object) ");
return base.VisitTemplateParameterSubstitutionType(param, quals); return base.VisitTemplateParameterSubstitutionType(param, quals);
} }
@ -756,10 +756,10 @@ namespace CppSharp.Generators.CSharp
Class @interface; Class @interface;
var finalType = type.GetFinalPointee() ?? type; var finalType = type.GetFinalPointee() ?? type;
var templateType = finalType as TemplateParameterSubstitutionType; var templateType = finalType as TemplateParameterSubstitutionType;
type = Context.Parameter.Type.Desugar();
if (finalType.TryGetClass(out @interface) && if (finalType.TryGetClass(out @interface) &&
@interface.IsInterface) @interface.IsInterface)
paramInstance = string.Format("{0}.__PointerTo{1}", paramInstance = $"{param}.__PointerTo{@interface.OriginalClass.Name}";
param, @interface.OriginalClass.Name);
else else
paramInstance = $@"{ paramInstance = $@"{
(templateType != null ? $"(({@class.Visit(typePrinter)}) (object) " : string.Empty)}{ (templateType != null ? $"(({@class.Visit(typePrinter)}) (object) " : string.Empty)}{
@ -777,7 +777,7 @@ namespace CppSharp.Generators.CSharp
Context.Return.Write("{0}{1}", Context.Return.Write("{0}{1}",
method != null && method.OperatorKind == CXXOperatorKind.EqualEqual method != null && method.OperatorKind == CXXOperatorKind.EqualEqual
? string.Empty ? string.Empty
: string.Format("ReferenceEquals({0}, null) ? global::System.IntPtr.Zero : ", param), : $"ReferenceEquals({param}, null) ? global::System.IntPtr.Zero : ",
paramInstance); paramInstance);
} }
else else

4
tests/CSharp/CSharpTemplates.h

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

Loading…
Cancel
Save