diff --git a/src/Generator/Generators/CSharp/CSharpSources.cs b/src/Generator/Generators/CSharp/CSharpSources.cs index 7c0ae294..edb61a84 100644 --- a/src/Generator/Generators/CSharp/CSharpSources.cs +++ b/src/Generator/Generators/CSharp/CSharpSources.cs @@ -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) diff --git a/src/Generator/Options.cs b/src/Generator/Options.cs index df924b86..9df9cfa6 100644 --- a/src/Generator/Options.cs +++ b/src/Generator/Options.cs @@ -172,6 +172,13 @@ namespace CppSharp public string IncludePrefix; public Func GenerateName; + /// + /// 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. + /// + /// C# only. + public Func GenerateFreeStandingFunctionsClassName; + /// /// Set this option to the kind of comments that you want generated /// in the source code. This overrides the default kind set by the diff --git a/tests/dotnet/CSharp/CSharp.Gen.cs b/tests/dotnet/CSharp/CSharp.Gen.cs index 3e48a759..38c2e5d6 100644 --- a/tests/dotnet/CSharp/CSharp.Gen.cs +++ b/tests/dotnet/CSharp/CSharp.Gen.cs @@ -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)