Skip to content

Static Functions Issues #156

@tomspilman

Description

@tomspilman

I'm having issues with exporting static functions from C++ without getting weird looking wrappers.

My first try was just adding static methods to a class with private constructor. My thinking was that since the class had nothing but static methods, CppSharp would not make it constructible.... but that does not seem to be the case. The final class had constructors and dispose methods.

My next try was just putting plain methods in a header:

// MyStaticClass.h
#pragma once
#include "PreDecls.h"

__declspec(dllexport) bool MyStaticMethod();

What I got was this...

namespace MyNamespace
{
    public unsafe partial class MyNamespace_MyStaticClass
    {
        public struct Internal
        {
           // blah blah blah
        }

        public static bool MyStaticMethod()
        {
            var __ret = Internal.MyStaticMethod_0();
            return __ret;
        }
    }
}

Instead of having the class named after the header file... MyStaticClass... I got something with the assembly namespace prepended MyNamespace_MyStaticClass.

So what is the best way to get a C# style "static class" wrapper from C++?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions