Browse Source

Fixed the generated C# for templates with optional arguments.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/1033/head
Dimitar Dobrev 8 years ago
parent
commit
51c0f37aa3
  1. 8
      src/Generator/Generators/CSharp/CSharpTypePrinter.cs
  2. 12
      tests/CSharp/CSharpTemplates.h

8
src/Generator/Generators/CSharp/CSharpTypePrinter.cs

@ -356,8 +356,14 @@ namespace CppSharp.Generators.CSharp @@ -356,8 +356,14 @@ namespace CppSharp.Generators.CSharp
if (ContextKind == TypePrinterContextKind.Managed &&
decl == template.Template.TemplatedDecl &&
template.Arguments.All(IsValid))
{
List<TemplateArgument> args = template.Arguments;
var @class = (Class) template.Template.TemplatedDecl;
TemplateArgument lastArg = args.Last();
return $@"{VisitDeclaration(decl)}<{string.Join(", ",
template.Arguments.Select(VisitTemplateArgument))}>";
args.Concat(Enumerable.Range(0, @class.TemplateParameters.Count - args.Count).Select(
i => lastArg)).Select(this.VisitTemplateArgument))}>";
}
if (ContextKind == TypePrinterContextKind.Native)
return template.Desugared.Visit(this);

12
tests/CSharp/CSharpTemplates.h

@ -374,11 +374,18 @@ T& TemplateWithIndexer<T>::operator[](const char* string) @@ -374,11 +374,18 @@ T& TemplateWithIndexer<T>::operator[](const char* string)
return t[0];
}
template <typename T1 = void, typename T2 = void, typename T3 = void, typename T4 = void,
typename T5 = void, typename T6 = void, typename T7 = void, typename T8 = void>
class OptionalTemplateArgs
{
};
template <typename T>
class VirtualTemplate
{
public:
VirtualTemplate();
VirtualTemplate(OptionalTemplateArgs<T> optionalTemplateArgs);
virtual ~VirtualTemplate();
virtual int function();
};
@ -388,6 +395,11 @@ VirtualTemplate<T>::VirtualTemplate() @@ -388,6 +395,11 @@ VirtualTemplate<T>::VirtualTemplate()
{
}
template <typename T>
VirtualTemplate<T>::VirtualTemplate(OptionalTemplateArgs<T> optionalTemplateArgs)
{
}
template <typename T>
VirtualTemplate<T>::~VirtualTemplate()
{

Loading…
Cancel
Save