Browse Source

Introduce `GenerateFreeStandingFunctionsClassName` option

pull/1782/head
Salvage 3 years ago
parent
commit
dba683196f
No known key found for this signature in database
GPG Key ID: 1362C7A680BA7451
  1. 3
      src/Generator/Generators/CSharp/CSharpSources.cs
  2. 7
      src/Generator/Options.cs
  3. 2
      tests/dotnet/CSharp/CSharp.Gen.cs

3
src/Generator/Generators/CSharp/CSharpSources.cs

@ -250,7 +250,8 @@ namespace CppSharp.Generators.CSharp @@ -250,7 +250,8 @@ namespace CppSharp.Generators.CSharp
if (!context.Functions.Any(f => f.IsGenerated) && !hasGlobalVariables)
return;
var parentName = SafeIdentifier(context.TranslationUnit.FileNameWithoutExtension);
var parentName = SafeIdentifier(Context.Options.GenerateFreeStandingFunctionsClassName?.Invoke(context.TranslationUnit)
?? context.TranslationUnit.FileNameWithoutExtension);
var isStruct = EnumerateClasses()
.ToList()
.FindAll(cls => cls.IsValueType && cls.Name == parentName && context.QualifiedLogicalName == cls.Namespace.QualifiedLogicalName)

7
src/Generator/Options.cs

@ -172,6 +172,13 @@ namespace CppSharp @@ -172,6 +172,13 @@ namespace CppSharp
public string IncludePrefix;
public Func<TranslationUnit, string> GenerateName;
/// <summary>
/// By default the classes in which free standing functions are contained are named like the header they are in
/// this options allows you to customize this behavior.
/// </summary>
/// <remarks>C# only.</remarks>
public Func<TranslationUnit, string> GenerateFreeStandingFunctionsClassName;
/// <summary>
/// Set this option to the kind of comments that you want generated
/// in the source code. This overrides the default kind set by the

2
tests/dotnet/CSharp/CSharp.Gen.cs

@ -26,6 +26,8 @@ namespace CppSharp.Tests @@ -26,6 +26,8 @@ namespace CppSharp.Tests
driver.ParserOptions.UnityBuild = true;
driver.ParserOptions.AddSupportedFunctionTemplates("FunctionTemplate");
driver.Options.GenerateFreeStandingFunctionsClassName = t => t.FileNameWithoutExtension + "Cool";
}
public override void SetupPasses(Driver driver)

Loading…
Cancel
Save