Facepunch / sbox-issues

175 stars 12 forks source link

TypeLibrary can't get static properties #6461

Open badandbest opened 1 month ago

badandbest commented 1 month ago

Describe the bug

TypeLibrary can't get static properties

To Reproduce

namespace Sandbox;

public class MyComponent : Component
{
    public string MyProperty => "My Property";

    public static string MyStaticProperty => "My Static Property";

    [Button]
    public void Reproduction()
    {
        var type = TypeLibrary.GetType<MyComponent>();

        var value = type.GetValue( instance: this, "MyProperty" );
        var staticValue = type.GetValue( instance: null, "MyStaticProperty" );

        Log.Info( value );
        Log.Info( staticValue );
    }
}
2024/09/20 15:09:36.6957    [GameMenu] My Property  
2024/09/20 15:09:36.6957    [GameMenu]  

Expected behavior

TypeLibrary should get the static property.

Media/Files

No response

Additional context

Same thing with EditorTypeLibrary

badandbest commented 1 month ago

This might be intended behaviour. :( image

Coomzy commented 1 month ago

Is this intended behaviour? You can get it by doing the following code: var MyStaticProperty = type.Properties.First(x => x.IsStatic && x.IsName("MyStaticProperty")).GetValue(null); That !x.IsStatic restriction seems arbitrary

badandbest commented 1 month ago

You know what you are right. I'm reopening this.