How to display computed getter in inspector?

I’m aware of the answers here on how to display public fields as read-only in the inspector, and I’m also aware of [SerializeField] to display private fields, which is the answer many gave for exposing getter/setter in the inspector.

However, I’d like to expose a read-only value in the inspector that is a getter of a computed value. So the value is not stored in any private fields. I do not wish to add any extra private fields to store the computed result, as there could be many of such getters and I don’t wish to bloat it up.

For example:

public float a;
public float b;

// just an example. could be other formula
[HowToExposeInInspectorAsReadOnly?]
public float x { get { return a + 2 * b; } } 

So when the values of a and b changes, you can also observe the read-only value of x in the inspector, for debugging purposes.

I used a mixed approach.

First, I implemented the solution from @lev-lukomskyi How to make a readonly property in inspector? - Questions & Answers - Unity Discussions

Then I used an approach from @mattrix to use the OnValidate event Detect when a property is changed on a ScriptableObject Asset - Questions & Answers - Unity Discussions

    [Range(1, 100)]
    public int level;
    [ReadOnly]
    public float speed;
    public float speedBase;
    public float speedMultiplier;

    private void Awake()
    {
        ComputeValues();
    }

    private void OnEnable()
    {
        ComputeValues();
    }

    private void OnValidate()
    {
        ComputeValues();
    }

    public void ComputeValues()
    {
        speed = (float)level * speedMultiplier * speedBase;
    }

You could implement a custom inspector for that type, call the default inspector and then labels, showing the computed results. This should get you started.

using UnityEngine;
using System.Collections;
using UnityEditor;

[CustomEditor(typeof(MyType))]
public class MyTypeEditor : Editor
{
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();
        
        MyType myObject = (MyType ) target;

        EditorGUILayout.LabelField("X x Y: ", myObject.x * myObject.y);

    }
}