diff --git a/src/Generator.Tests/AST/TestAST.cs b/src/Generator.Tests/AST/TestAST.cs
index 612a4eb4..0117a3e9 100644
--- a/src/Generator.Tests/AST/TestAST.cs
+++ b/src/Generator.Tests/AST/TestAST.cs
@@ -3,6 +3,7 @@ using CppSharp.Passes;
using CppSharp.AST;
using CppSharp.AST.Extensions;
using NUnit.Framework;
+using CppSharp.Generators.CSharp;
namespace CppSharp.Generator.Tests.AST
{
@@ -36,10 +37,10 @@ namespace CppSharp.Generator.Tests.AST
Modifier = PointerType.TypeModifier.LVReference,
QualifiedPointee = new QualifiedType(
new BuiltinType(PrimitiveType.Short),
- new TypeQualifiers() { IsConst = true })
+ new TypeQualifiers { IsConst = true })
}),
new QualifiedType(
- new PointerType()
+ new PointerType
{
Modifier = PointerType.TypeModifier.Pointer,
QualifiedPointee = new QualifiedType(new BuiltinType(PrimitiveType.Int))
@@ -304,5 +305,38 @@ namespace CppSharp.Generator.Tests.AST
c => !c.IsCopyConstructor && !c.IsMoveConstructor).InstantiatedFrom,
classTemplate.TemplatedClass.Constructors.First(c => !c.IsCopyConstructor && !c.IsMoveConstructor));
}
+
+ [Test]
+ public void TestComments()
+ {
+ var @class = AstContext.FindCompleteClass("TestComments");
+ var commentClass = @class.Comment.FullComment.CommentToString(Options.CommentPrefix);
+ Assert.AreEqual(@"///
+/// Hash set/map base class.
+/// Note that to prevent extra memory use due to vtable pointer, %HashBase intentionally does not declare a virtual destructor
+/// and therefore %HashBase pointers should never be used.
+/// ".Replace("\r", string.Empty), commentClass.Replace("\r", string.Empty));
+
+ var method = @class.Methods.First(m => m.Name == "GetIOHandlerControlSequence");
+ var commentMethod = method.Comment.FullComment.CommentToString(Options.CommentPrefix);
+ Assert.AreEqual(@"///
+/// Get the string that needs to be written to the debugger stdin file
+/// handle when a control character is typed.
+///
+///
+/// Some GUI programs will intercept "control + char" sequences and want
+/// to have them do what normally would happen when using a real
+/// terminal, so this function allows GUI programs to emulate this
+/// functionality.
+///
+///
+/// The character that was typed along with the control key
+///
+///
+/// The string that should be written into the file handle that is
+/// feeding the input stream for the debugger, or NULL if there is
+/// no string for this control key.
+/// ".Replace("\r", string.Empty), commentMethod.Replace("\r", string.Empty));
+ }
}
}
diff --git a/src/Generator/Generators/CSharp/CSharpCommentPrinter.cs b/src/Generator/Generators/CSharp/CSharpCommentPrinter.cs
index d59935d0..b03a5b98 100644
--- a/src/Generator/Generators/CSharp/CSharpCommentPrinter.cs
+++ b/src/Generator/Generators/CSharp/CSharpCommentPrinter.cs
@@ -71,7 +71,7 @@ namespace CppSharp.Generators.CSharp
break;
case CommentKind.TextComment:
var section = sections.Last();
- sections.Last().Lines.Add(GetText(comment,
+ section.Lines.Add(GetText(comment,
section.Type == CommentElement.Returns || section.Type == CommentElement.Param));
if (sections.Count == 1)
sections.Add(new Section(CommentElement.Remarks));
@@ -119,7 +119,7 @@ namespace CppSharp.Generators.CSharp
foreach (var section in sections.Where(s => s.Lines.Count > 0))
{
var tag = section.Type.ToString().ToLowerInvariant();
- commentBuilder.AppendFormat("<{0}{1}>",
+ commentBuilder.AppendFormat("{0} <{1}{2}>", commentPrefix,
tag + (section.Attributes.Count == 0 ? string.Empty : " "),
string.Join(" ", section.Attributes));
commentBuilder.AppendLine();
@@ -128,7 +128,7 @@ namespace CppSharp.Generators.CSharp
commentBuilder.AppendFormat("{0} {1}", commentPrefix, line);
commentBuilder.AppendLine();
}
- commentBuilder.AppendFormat("{0}>", tag);
+ commentBuilder.AppendFormat("{0} {1}>", commentPrefix, tag);
commentBuilder.AppendLine();
}
if (commentBuilder.Length > 0)
diff --git a/src/Generator/Generators/Template.cs b/src/Generator/Generators/Template.cs
index 31a16f0d..d43e40cc 100644
--- a/src/Generator/Generators/Template.cs
+++ b/src/Generator/Generators/Template.cs
@@ -134,16 +134,9 @@ namespace CppSharp.Generators
if (!string.IsNullOrWhiteSpace(line))
builder.Append(new string(' ', (int)totalIndent));
-
- if (childBlock.Kind == BlockKind.BlockComment &&
- !line.StartsWith(options.CommentPrefix))
- {
- builder.Append(options.CommentPrefix);
- builder.Append(' ');
- }
builder.Append(line);
- if (!line.EndsWith(Environment.NewLine))
+ if (!line.EndsWith(Environment.NewLine, StringComparison.Ordinal))
builder.AppendLine();
}
diff --git a/tests/Common/Common.cpp b/tests/Common/Common.cpp
index 2434959d..6248d528 100644
--- a/tests/Common/Common.cpp
+++ b/tests/Common/Common.cpp
@@ -581,11 +581,6 @@ int OverridesNonDirectVirtual::retInt()
return 3;
}
-const char * TestComments::GetIOHandlerControlSequence(char ch)
-{
- return 0;
-}
-
AbstractWithVirtualDtor::AbstractWithVirtualDtor()
{
}
diff --git a/tests/Common/Common.h b/tests/Common/Common.h
index d0e302a0..c64424c6 100644
--- a/tests/Common/Common.h
+++ b/tests/Common/Common.h
@@ -983,33 +983,6 @@ AbstractTemplate::AbstractTemplate()
{
}
-/// Hash set/map base class.
-/** Note that to prevent extra memory use due to vtable pointer, %HashBase intentionally does not declare a virtual destructor
-and therefore %HashBase pointers should never be used.
-*/
-class DLL_API TestComments
-{
-public:
- //----------------------------------------------------------------------
- /// Get the string that needs to be written to the debugger stdin file
- /// handle when a control character is typed.
- ///
- /// Some GUI programs will intercept "control + char" sequences and want
- /// to have them do what normally would happen when using a real
- /// terminal, so this function allows GUI programs to emulate this
- /// functionality.
- ///
- /// @param[in] ch
- /// The character that was typed along with the control key
- ///
- /// @return
- /// The string that should be written into the file handle that is
- /// feeding the input stream for the debugger, or NULL if there is
- /// no string for this control key.
- //----------------------------------------------------------------------
- const char * GetIOHandlerControlSequence(char ch);
-};
-
class DLL_API AbstractWithVirtualDtor
{
public:
diff --git a/tests/Native/AST.h b/tests/Native/AST.h
index 8791b564..e7b872b4 100644
--- a/tests/Native/AST.h
+++ b/tests/Native/AST.h
@@ -122,3 +122,29 @@ void instantiatesTemplate(TestSpecializationArguments t)
{
}
+/// Hash set/map base class.
+/** Note that to prevent extra memory use due to vtable pointer, %HashBase intentionally does not declare a virtual destructor
+and therefore %HashBase pointers should never be used.
+*/
+class TestComments
+{
+public:
+ //----------------------------------------------------------------------
+ /// Get the string that needs to be written to the debugger stdin file
+ /// handle when a control character is typed.
+ ///
+ /// Some GUI programs will intercept "control + char" sequences and want
+ /// to have them do what normally would happen when using a real
+ /// terminal, so this function allows GUI programs to emulate this
+ /// functionality.
+ ///
+ /// @param[in] ch
+ /// The character that was typed along with the control key
+ ///
+ /// @return
+ /// The string that should be written into the file handle that is
+ /// feeding the input stream for the debugger, or NULL if there is
+ /// no string for this control key.
+ //----------------------------------------------------------------------
+ const char * GetIOHandlerControlSequence(char ch);
+};