Ошибка компиляции оператора ? :

Этот код приводит к ошибке компиляции:

InputActionMap currentActionMap
= Menu.ESC_Controller.IS_PAUSED
? myDroneInputController.myPlayerInputData.MenuControls
: myDroneInputController.myPlayerInputData.PlayerControls;

Структуры и класс прописаны так:

public partial class @PlayerInputData : IInputActionCollection2, IDisposable {
...
     public struct PlayerControlsActions { }
     public PlayerControlsActions @PlayerControls => new 
     PlayerControlsActions(this);
...
     public struct MenuControlsActions { }
     public MenuControlsActions @MenuControls => new MenuControlsActions(this);
...
} 


public sealed class InputActionMap : ICloneable, ISerializationCallbackReceiver, IInputActionCollection2, IInputActionCollection, IEnumerable<InputAction>, IEnumerable, IDisposable
{....
}

// MenuControls 
public struct MenuControlsActions
{
        private @PlayerInputData m_Wrapper;
        public MenuControlsActions(@PlayerInputData wrapper) { m_Wrapper = wrapper; }
        public InputAction @ESC_MenuESC => m_Wrapper.m_MenuControls_ESC_MenuESC;
}

// PlayerControls:
 public struct PlayerControlsActions
{
        private @PlayerInputData m_Wrapper;
        public PlayerControlsActions(@PlayerInputData wrapper) { m_Wrapper = wrapper; }
        public InputAction @ESC => m_Wrapper.m_PlayerControls_ESC;
}

Ошибка выглядит так:

Type of conditional expression cannot be determined because there is no implicit conversion between 'PlayerInputData.MenuControlsActions' and 'PlayerInputData.PlayerControlsActions'

VS говорит:

Feature 'target-typed conditional expression' is not available in C# 8.0. Please use language version 9.0 or greater

  1. Обьясните пожалуйста как version 9.0 будет преобразовывать объект типа struct в class?
  2. Почему оператор ? : здесь не работает, а if()-else работает?

Ответы (0 шт):