Skip to content

Custom type mapping #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
anchurcn opened this issue Apr 10, 2024 · 1 comment
Open

Custom type mapping #35

anchurcn opened this issue Apr 10, 2024 · 1 comment
Labels
question Further information is requested

Comments

@anchurcn
Copy link

  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.
@xoofx xoofx added the question Further information is requested label Apr 30, 2024
@xoofx
Copy link
Owner

xoofx commented May 17, 2024

  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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants