CppAst.CodeGen icon indicating copy to clipboard operation
CppAst.CodeGen copied to clipboard

Custom type mapping

Open anchurcn opened this issue 1 year ago • 1 comments

  1. I want to add custom mapping rules. eg: vec3_t => Vector3f
  2. For pointer type in C directly map to pointer type in C# too.

anchurcn avatar Apr 10 '24 13:04 anchurcn

  1. 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;
    }
}
  1. For pointer type in C directly map to pointer type in C# too.

Latest version should do this by default.

xoofx avatar May 17 '24 04:05 xoofx