CppSharp
CppSharp copied to clipboard
Suppress Generation of Copy Constructors
Is it possible to supress generation of copy constructors in generated C# code for all the classes
There is no option available for this, but you should be able to do it by writing a pass.
It should be relatively simple, override VisitMethod
and check if its a copy constructor, if so ignore it.
Hopefully that does it without bad side effects on the code generator.
It should be relatively simple, override
VisitMethod
and check if its a copy constructor, if so ignore it.
How do you recommend to override the pass in a program that references the CppSharp DLL? I see that VisitMethod
is defined in DeclConverter
.
DeclConverter
should not be used for this. The class I mentioned is TranslationUnitPass
defined in Pass.cs
and the method name should be VisitMethodDecl
from its base AstVisitor
in https://github.com/mono/CppSharp/blob/main/src/AST/ASTVisitor.cs#L473.
DeclConverter
should not be used for this. The class I mentioned isTranslationUnitPass
defined inPass.cs
and the method name should beVisitMethodDecl
from its basedAstVisitor
in https://github.com/mono/CppSharp/blob/main/src/AST/ASTVisitor.cs#L473.
Gotcha, makes sense. Given that TranslationUnitPass
is the base class for each existing pass, how should I override TranslationUnitPass
in my project when CppSharp is included as a DLL, such that the behavior of VisitMethodDecl()
is changed for all passes? Or is that not necessary?
DeclConverter
should not be used for this. The class I mentioned isTranslationUnitPass
defined inPass.cs
and the method name should beVisitMethodDecl
from its basedAstVisitor
in https://github.com/mono/CppSharp/blob/main/src/AST/ASTVisitor.cs#L473.Gotcha, makes sense. Given that
TranslationUnitPass
is the base class for each existing pass, how should I overrideTranslationUnitPass
in my project when CppSharp is included as a DLL, such that the behavior ofVisitMethodDecl()
is changed for all passes? Or is that not necessary?
You should create your own class that derives from TranslationUnitPass
and then either add it with driver.TranslationUnitPasses.AddPass
on SetupPasses
or run it from Preprocess
. See for instance https://github.com/mono/CppSharp/blob/main/src/CppParser/Bootstrap/IgnoreMethodsWithParametersPass.cs#L10 and https://github.com/mono/CppSharp/blob/main/src/CppParser/Bootstrap/Bootstrap.cs#L92.
You should create your own class that derives from
TranslationUnitPass
and then either add it withdriver.TranslationUnitPasses.AddPass
onSetupPasses
or run it fromPreprocess
. See for instance https://github.com/mono/CppSharp/blob/main/src/CppParser/Bootstrap/IgnoreMethodsWithParametersPass.cs#L10 and https://github.com/mono/CppSharp/blob/main/src/CppParser/Bootstrap/Bootstrap.cs#L92.
Works well, thank you!