Skip to content

Commit 57c618b

Browse files
FiniteRealitytannergooding
authored andcommitted
Always write headers and check against empty paths (#80)
* Always write headers and check against empty paths This fixes #78 and fixes #79. Header files are written whenever a valid header file is passed, and null/empty paths are now ignored. * Skip generating the header in the method class It was already written earlier, so it is unnecessary. * Make suggested changes
1 parent a264782 commit 57c618b

2 files changed

Lines changed: 18 additions & 12 deletions

File tree

sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -268,19 +268,25 @@ private void CloseOutputBuilder(Stream stream, OutputBuilder outputBuilder, bool
268268
using var sw = new StreamWriter(stream, defaultStreamWriterEncoding, DefaultStreamWriterBufferSize, leaveStreamOpen);
269269
sw.NewLine = "\n";
270270

271-
if (outputBuilder.UsingDirectives.Any() && _config.GenerateMultipleFiles)
271+
if (_config.GenerateMultipleFiles)
272272
{
273-
sw.Write(_config.HeaderText);
274-
275-
foreach (var usingDirective in outputBuilder.UsingDirectives)
273+
if (_config.HeaderText != string.Empty)
276274
{
277-
sw.Write("using");
278-
sw.Write(' ');
279-
sw.Write(usingDirective);
280-
sw.WriteLine(';');
275+
sw.WriteLine(_config.HeaderText);
281276
}
282277

283-
sw.WriteLine();
278+
if (outputBuilder.UsingDirectives.Any())
279+
{
280+
foreach (var usingDirective in outputBuilder.UsingDirectives)
281+
{
282+
sw.Write("using");
283+
sw.Write(' ');
284+
sw.Write(usingDirective);
285+
sw.WriteLine(';');
286+
}
287+
288+
sw.WriteLine();
289+
}
284290
}
285291

286292
var indentationString = outputBuilder.IndentationString;
@@ -1399,12 +1405,12 @@ private void VisitParmVarDecl(ParmVarDecl parmVarDecl, TypedefDecl typedefDecl)
13991405
var parameters = typedefDecl.CursorChildren.Where((cursor) => cursor is ParmVarDecl).Cast<ParmVarDecl>().ToList();
14001406
var index = parameters.IndexOf(parmVarDecl);
14011407
var lastIndex = parameters.Count - 1;
1402-
1408+
14031409
if (name.Equals("param"))
14041410
{
14051411
_outputBuilder.Write(index);
14061412
}
1407-
1413+
14081414
if (index != lastIndex)
14091415
{
14101416
_outputBuilder.Write(',');

sources/ClangSharp.PInvokeGenerator/PInvokeGeneratorConfiguration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public PInvokeGeneratorConfiguration(string libraryPath, string namespaceName, s
5151
_options = options;
5252

5353
ExcludedNames = excludedNames;
54-
HeaderText = headerFile is object ? File.ReadAllText(headerFile) : string.Empty;
54+
HeaderText = string.IsNullOrWhiteSpace(headerFile) ? string.Empty : File.ReadAllText(headerFile);
5555
LibraryPath = libraryPath;
5656
MethodClassName = methodClassName;
5757
MethodPrefixToStrip = methodPrefixToStrip;

0 commit comments

Comments
 (0)