Browse Source

Avoid generating an interface with a Dispose method if we already inherit from IDisposable. (#1486)

pull/1489/head
josetr 5 years ago committed by GitHub
parent
commit
cb7e35dfa1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      src/Generator/Generators/CSharp/CSharpSources.cs

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

@ -480,7 +480,8 @@ namespace CppSharp.Generators.CSharp @@ -480,7 +480,8 @@ namespace CppSharp.Generators.CSharp
GenerateClassSpecifier(@class);
if (@class.Bases.Count == 0)
var shouldInheritFromIDisposable = !@class.HasBase;
if (shouldInheritFromIDisposable)
Write(" : IDisposable");
NewLine();
@ -489,7 +490,8 @@ namespace CppSharp.Generators.CSharp @@ -489,7 +490,8 @@ namespace CppSharp.Generators.CSharp
foreach (var method in @class.Methods.Where(m =>
(m.OriginalFunction == null ||
!ASTUtils.CheckIgnoreFunction(m.OriginalFunction)) &&
m.Access == AccessSpecifier.Public))
m.Access == AccessSpecifier.Public &&
(!shouldInheritFromIDisposable || !IsDisposeMethod(m))))
{
PushBlock(BlockKind.Method);
GenerateDeclarationCommon(method);
@ -530,6 +532,11 @@ namespace CppSharp.Generators.CSharp @@ -530,6 +532,11 @@ namespace CppSharp.Generators.CSharp
PopBlock(NewLineKind.BeforeNextBlock);
}
public static bool IsDisposeMethod(Method method)
{
return method.Name == "Dispose" && method.Parameters.Count == 0 && method.ReturnType.Type.Desugar().IsPrimitiveType(PrimitiveType.Void);
}
public void GenerateClassInternals(Class @class)
{
var sequentialLayout = Options.GenerateSequentialLayout && CanUseSequentialLayout(@class);

Loading…
Cancel
Save