Skip to content

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

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
wants to merge 1 commit into
base: master
Choose a base branch
from

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.

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