Skip to content

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