Skip to content
Permalink
Browse files

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
  • Loading branch information...
FiniteReality authored and tannergooding committed Aug 10, 2019
1 parent a264782 commit 57c618b2ca511a99394dc99556eb4fa3129aefaf
@@ -268,19 +268,25 @@ private void CloseOutputBuilder(Stream stream, OutputBuilder outputBuilder, bool
using var sw = new StreamWriter(stream, defaultStreamWriterEncoding, DefaultStreamWriterBufferSize, leaveStreamOpen);
sw.NewLine = "\n";

if (outputBuilder.UsingDirectives.Any() && _config.GenerateMultipleFiles)
if (_config.GenerateMultipleFiles)
{
sw.Write(_config.HeaderText);

foreach (var usingDirective in outputBuilder.UsingDirectives)
if (_config.HeaderText != string.Empty)
{
sw.Write("using");
sw.Write(' ');
sw.Write(usingDirective);
sw.WriteLine(';');
sw.WriteLine(_config.HeaderText);
}

sw.WriteLine();
if (outputBuilder.UsingDirectives.Any())
{
foreach (var usingDirective in outputBuilder.UsingDirectives)
{
sw.Write("using");
sw.Write(' ');
sw.Write(usingDirective);
sw.WriteLine(';');
}

sw.WriteLine();
}
}

var indentationString = outputBuilder.IndentationString;
@@ -1399,12 +1405,12 @@ private void VisitParmVarDecl(ParmVarDecl parmVarDecl, TypedefDecl typedefDecl)
var parameters = typedefDecl.CursorChildren.Where((cursor) => cursor is ParmVarDecl).Cast<ParmVarDecl>().ToList();
var index = parameters.IndexOf(parmVarDecl);
var lastIndex = parameters.Count - 1;

if (name.Equals("param"))
{
_outputBuilder.Write(index);
}

if (index != lastIndex)
{
_outputBuilder.Write(',');
@@ -51,7 +51,7 @@ public PInvokeGeneratorConfiguration(string libraryPath, string namespaceName, s
_options = options;

ExcludedNames = excludedNames;
HeaderText = headerFile is object ? File.ReadAllText(headerFile) : string.Empty;
HeaderText = string.IsNullOrWhiteSpace(headerFile) ? string.Empty : File.ReadAllText(headerFile);
LibraryPath = libraryPath;
MethodClassName = methodClassName;
MethodPrefixToStrip = methodPrefixToStrip;

0 comments on commit 57c618b

Please sign in to comment.
You can’t perform that action at this time.