RequireComponent at variable level?

I was wondering if you can use RequireComponent or any other sort of attribute to indicate that a variable of a component requires a component.

For example I have a component like so:

public class FormationController : MonoBehaviour
{
    public List<GameObject> targets;
	
	void Update() 
	{
		// loop round assume i is index
		// get the component off the targets and set data on target component
		var targetComponent = target*.GetComponent<SomeCustomComponent>();*
  •  targetComponent.SetSomeValue = 10;*
    
  • }*
    }
    Now I can use that and it would be fine, however it would be nice if in the GUI I can specify that a target can only be added via the editor if it has a component on it, much like I can at the class level to say this component can only be added to an entity with a required component.
    So can RequireComponent be used this way? and if not is there any other approach to get some more safety around the targets having the desired component?

I’m not sure I understood you correctly, but I’d suggest to declare array of desired component type instead of just GameObject.
e.g.:

public List<SomeCustomComponent> targets;
    
void Update() 
{
    // loop round assume i is index
    // get the component off the targets and set data on target component
    SomeCustomComponent targetComponent = target*;*

targetComponent.SetSomeValue = 10;
}