I'm creating a TryGetComponent(Type type, out Component component)
method, and then adding a TryGetComponent<T>(out T component)
overload for convenience:
public bool TryGetComponent(Type type, out Component component)
{
component = null;
if (type.IsAssignableFrom(typeof(Component)))
{
throw new ArgumentException($"Must get component using a type that is assignable to {nameof(Component)}: Parameter type was '{type}'", nameof(type));
}
return Components.TryGetValue(type, out component);
}
public bool TryGetComponent<T>(out T component) where T : Component
{
return TryGetComponent(typeof(T), out component);
}
But I get the following compile error regarding ```out component`` in the second function.
Cannot convert from out T to out component
Adding an explicit cast to T
gives the following error
The out parameter must be assigned before control leaves the current method.
I'm almost certain I've done this exact pattern before. No idea why it's not compiling.