Skip to content

Fix for #175 (Inheritance for static methods)#336

Open
OmidRezaT wants to merge 1 commit intomoonsharp-devs:legacy/2.0from
OmidRezaT:master
Open

Fix for #175 (Inheritance for static methods)#336
OmidRezaT wants to merge 1 commit intomoonsharp-devs:legacy/2.0from
OmidRezaT:master

Conversation

@OmidRezaT
Copy link

Fix for #175
When registering a class, static methods of the target base class not get registered even though, other kind of base class members such as fields, properties, or even non-static methods did get registered.

public void RegisterExampleType()
{
    //Registering Type
    UserData.RegisterType<ExampleClass>();
}

public class ExampleClass : ExampleClassBase
{
    //✅ Get Registered and accessible
    public static int GetStaticValueChild() => 0;
    
    //✅ Get Registered and accessible
    public int ChildMethod() => 0;
}


public class ExampleClassBase
{
    //✅ Get Registered and accessible
    public int BaseMember;
    
    //✅ Get Registered and accessible
    public int NonStaticMethod() => 0; 
    
    //❌ Not get registered 
    public static int StaticBaseMethod() => 0;
}

The was because of the BindingFlags which FrameworkClrBase use to find methods lacks BindingFlags.FlattenHierarchy flag which is required for retrieving the static methods from the target base class.

this is a documented behavior of Type.GetMethods(BindingFlags) method:

Specify BindingFlags.FlattenHierarchy to include public and protected static members up the hierarchy; private static members in inherited classes are not included.

Simoxus added a commit to Simoxus/moonsharp that referenced this pull request Jan 8, 2026
@Benjamin-Dobell Benjamin-Dobell changed the base branch from master to legacy/2.0 March 3, 2026 06:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant