-
Hi, because of the way I code, I often end up in not working situations like: public abstract class GenericEntityDescriptor<T, U, V> : IEntityDescriptor
where T : struct, _IInternalEntityComponent where U : struct, _IInternalEntityComponent where V : struct, _IInternalEntityComponent
{
static readonly IComponentBuilder[] _componentBuilders;
static GenericEntityDescriptor()
{
_componentBuilders = new IComponentBuilder[]
{
new ComponentBuilder().Create<T>(),
new ComponentBuilder().Create<U>(),
new ComponentBuilder().Create<V>()
};
}
public IComponentBuilder[] componentsToBuild => _componentBuilders;
} with something like public static class ComponentExtensionsA
{
public static IComponentBuilder Create<T>(in this ComponentBuilder c) where T:struct, IManagedComponent //implements _IInternalEntityComponent
{
return new ComponentBuilder<T>(); //works only if T is struct, IManagedComponent
}
}
public static class ComponentExtensionsB
{
public static IComponentBuilder Create<T>(in this ComponentBuilder c) where T:unmanaged, IEntityComponent //implements _IInternalEntityComponent
{
return new UnmanagedComponentBuilder<T>(); //works only if T is T:unmanaged, IEntityComponent
}
} if I want this kind of specialization, I will need to get rid of however, if I had something like public static class ComponentExtensionsA
{
public static IComponentBuilder Create<T>(in this ComponentBuilder c) where T:struct, _IInternalEntityComponent
{
if (CompileTimeCheck<T>.Is(IManagedComponent))
return new ComponentBuilder().Create<T>();
if (CompileTimeCheck<T>.Is(IEntityComponent))
return new UnmanagedComponentBuilder<T>();
throw new Exception(); //or something
}
} this would be easily solved. Now I wonder more out of curiosity if this is technically possible because if it is, I'd be interested in opening a proposal. The point being the compiler should be able to know that T is compatible with the specialised template so it can execute and ignore the other cases. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
This is a duplicate of #6308. |
Beta Was this translation helpful? Give feedback.
This is a duplicate of #6308.