diff --git a/src/Generator/Generators/CLI/CLITextTemplate.cs b/src/Generator/Generators/CLI/CLITextTemplate.cs index 0521a070..1a98aa9e 100644 --- a/src/Generator/Generators/CLI/CLITextTemplate.cs +++ b/src/Generator/Generators/CLI/CLITextTemplate.cs @@ -86,6 +86,12 @@ namespace CppSharp.Generators.CLI if (method.OperatorKind == CXXOperatorKind.Conversion) return SafeIdentifier("operator " + method.ConversionType); + if (method.IsConstructor || method.IsDestructor) + { + var @class = (Class) method.Namespace; + return SafeIdentifier(@class.Name); + } + return SafeIdentifier(method.Name); } diff --git a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs index a7bc4ab4..85c7fa7f 100644 --- a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs +++ b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs @@ -418,7 +418,7 @@ namespace CppSharp.Generators.CSharp PushBlock(CSharpBlockKind.Method); GenerateDeclarationCommon(method); - var functionName = GetFunctionIdentifier(method); + var functionName = GetMethodIdentifier(method); Write("{0} {1}(", method.OriginalReturnType, functionName); @@ -1778,7 +1778,7 @@ namespace CppSharp.Generators.CSharp if (Driver.Options.GenerateAbstractImpls && method.IsPure) Write("abstract "); - var functionName = GetFunctionIdentifier(method); + var functionName = GetMethodIdentifier(method); if (method.IsConstructor || method.IsDestructor) Write("{0}(", functionName); @@ -2330,17 +2330,20 @@ namespace CppSharp.Generators.CSharp PopBlock(NewLineKind.BeforeNextBlock); } - public static string GetFunctionIdentifier(Function function) + public static string GetMethodIdentifier(Method method) { - var identifier = SafeIdentifier(function.Name); + if (method.IsConstructor || method.IsDestructor) + return method.Namespace.Name; - var method = function as Method; - if (method == null || !method.IsOperator) - return identifier; + return GetFunctionIdentifier(method); + } - identifier = Operators.GetOperatorIdentifier(method.OperatorKind); + public static string GetFunctionIdentifier(Function function) + { + if (function.IsOperator) + return Operators.GetOperatorIdentifier(function.OperatorKind); - return identifier; + return SafeIdentifier(function.Name); } public static string GetFunctionNativeIdentifier(Function function)