sp00ktober
sp00ktober
Explore posts from servers
CC#
Created by sp00ktober on 3/24/2023 in #help
❔ nested generic interface throws cast exception when added to list
Im working on a mod project and for this i need to handle different updates which are represented by individual classes that all inherit from the same generic interfaces. To accomplish the handling i also wrote a generic interface which can then be implemented by a class that should handle one specific class. In the end i want to have a list of handlers over which i can iterate to process the updates. This is my interface signature
internal interface IComponentUpdateHandler<T, H, C> where T : IComponentMetaclass where H : IComponentUpdate<T> where C : IComponentData<T>
internal interface IComponentUpdateHandler<T, H, C> where T : IComponentMetaclass where H : IComponentUpdate<T> where C : IComponentData<T>
These are the interfaces for the update and data interfaces
public interface IComponentUpdate<C> where C : IComponentMetaclass
public interface IComponentData<C> where C : IComponentMetaclass
public interface IComponentUpdate<C> where C : IComponentMetaclass
public interface IComponentData<C> where C : IComponentMetaclass
This is the signature of one of my handler classes
internal class InventoryModificationState_Handler : IComponentUpdateHandler<InventoryModificationState, InventoryModificationState.Update, InventoryModificationState.Data>
internal class InventoryModificationState_Handler : IComponentUpdateHandler<InventoryModificationState, InventoryModificationState.Update, InventoryModificationState.Data>
These are the signatures of the update and data classes
public class Update : IComponentUpdate<InventoryModificationState>
public class Data : IComponentData<InventoryModificationState>
public class Update : IComponentUpdate<InventoryModificationState>
public class Data : IComponentData<InventoryModificationState>
This is the signature of the base class
public class InventoryModificationState : IComponentMetaclass, IComponentFactory
public class InventoryModificationState : IComponentMetaclass, IComponentFactory
This is how i create the List and fill it with values
private List<IComponentUpdateHandler<IComponentMetaclass, IComponentUpdate<IComponentMetaclass>, IComponentData<IComponentMetaclass>>> handler { get; set; }
private ComponentUpdateManager()
{
handler = new List<IComponentUpdateHandler<IComponentMetaclass, IComponentUpdate<IComponentMetaclass>, IComponentData<IComponentMetaclass>>>
{
new InventoryModificationState_Handler(),
new PlayerCraftingInteractionState_Handler()
};
}
private List<IComponentUpdateHandler<IComponentMetaclass, IComponentUpdate<IComponentMetaclass>, IComponentData<IComponentMetaclass>>> handler { get; set; }
private ComponentUpdateManager()
{
handler = new List<IComponentUpdateHandler<IComponentMetaclass, IComponentUpdate<IComponentMetaclass>, IComponentData<IComponentMetaclass>>>
{
new InventoryModificationState_Handler(),
new PlayerCraftingInteractionState_Handler()
};
}
Im happy for any input as im stuck on this for some hours now 😄
27 replies