How to serialize specific fields that are inside an array of classes?

If I have a script like that

public enum VariableToShow { First, Second, Third };

    public class TestSerialization : MonoBehaviour
    {
        public B[] ExampleField;
    }

    [Serializable]
    public class A
    {
        public B[] BInstances;
    }

    [Serializable]
    public class B
    {
        public VariableToShow ShowVariable;

        public int FirstVariable;
        public int SecondVariable;
        public int ThirdVariable;
    }

And I need to only show the field in class B that is being selected by ShowVariable (if ShowVariable == First, then show FirstVariable, ShowVariable == Second, then show SecondVariable, etc), how can I do that?
I know that I can use SerializedProperty and serializedObject in custom editor, but I can only do it if instead of an array of B there are just variables inside the MonoBehaviour, I would do it like that

public enum VariableToShow { First, Second, Third };

    public class TestSerialization : MonoBehaviour
    {
        public VariableToShow ShowVariable;

        public int FirstVariable;
        public int SecondVariable;
        public int ThirdVariable;
    }

And inside editor for that script:

public override void OnInspectorGUI()
        {
            serializedObject.Update();

            SerializedProperty iterator = serializedObject.GetIterator();

            List<string> includes = new List<string>() { "ShowVariable" };
            bool enterChildren = true;
            while (iterator.NextVisible(enterChildren))
            {
                enterChildren = false;

                if (!includes.Contains(iterator.propertyPath))
                    continue;

                if (iterator.propertyPath == "ShowVariable")
                {
                    VariableToShow showVariable = iterator.GetEnumValue<VariableToShow>();

                    switch (showVariable)
                    {
                        case VariableToShow.First:
                            includes.Add("FirstVariable");
                            break;
                        case VariableToShow.Second:
                            includes.Add("SecondVariable");
                            break;
                        case VariableToShow.Third:
                            includes.Add("ThirdVariable");
                            break;
                    }
                }

                EditorGUILayout.PropertyField(iterator, true);
            }

            serializedObject.ApplyModifiedProperties();
        }

Can I do something similar for nested fields in array of classes? I tried to use iterator.NextVisible and putting true in there, but it just printed them out weird even when I used EditorGUILayout.FoldOut and EditorGUI.indentLevel. Would really be glad if someone helped me with this!

Don’t mind the public fields, only using it rn to show an example

You can create a custom PropertyDrawer for class B, instead of a custom editor for the classes that contain instances of B. Then, everywhere that you have an instance of B serialized, including in an array of B’s, it will display how you script it to display.

Yes, that did exactly what I wanted, thanks a lot!