CppAst.CodeGen
CppAst.CodeGen copied to clipboard
Custom type mapping
- I want to add custom mapping rules. eg: vec3_t => Vector3f
- For pointer type in C directly map to pointer type in C# too.
- I want to add custom mapping rules. eg: vec3_t => Vector3f
It is indeed something not covered out of the box, but you can maybe add your own type resolver to the plugin architecture:
var options = new CSharpConverterOptions()
{
MappingRules =
{
e => e.Map<CppClass>("vec3_t").Discard()
}
};
options.Plugins.Add(new MyVec3TypeResolver());
public class MyVec3TypeResolver : ICSharpConverterPlugin
{
public void Register(CSharpConverter converter, CSharpConverterPipeline pipeline)
{
pipeline.GetCSharpTypeResolvers.Add(GetType);
}
public static CSharpType? GetType(CSharpConverter converter, CppType cppType, CSharpElement context, bool nested)
{
if (cppType is CppClass cppClass && cppClass.Name == "vec3_t")
{
return new CSharpFreeType("global::System.Numerics.Vector3");
}
return null;
}
}
- For pointer type in C directly map to pointer type in C# too.
Latest version should do this by default.