C#C
C#5mo ago
hutonahill

Static Members of an Interface

I am building an engine for an existing game as a library (first library).

This game has may things is suspect will gain more elements as time goes on and i want to support moding. These types include things like cards, missions, characters, and the like.

So i created some fundamental interfaces, ICard, ICharacter, etc. These are all marked with an attribute, ContentType.

However i also want to keep track of where each piece oICf content comes from. I want every card to point back to its base set. Think of this like Minecraft's Identifier system minecraf:dirt, or create:pipe. So there is also IExpantion. To mod the game you create a new IExpantion, point all your content towards it and the game loads it keeping track of all the content and preventing duplicates. I made a class to handle this, Identifier<T>.

Identifier is like a weird singleton. its T (i am sure there is a proper name for this, i don't know it) represents the ContentType, like ICard or ICharacter and it has two internal Types. One representing an IExpantion and one representing whatever is being saved.

For example we could have an Identifier<ICard>(typeof(TheBestMod), typeof(AceOfSpades)). ICard is the content type, TheBestMod is the expansion and AceOfSpades is the content being added.

Ok, the problem is i want the ContentType classes (ie, ICard, ICharacter, etc) to require their children, the actual content, to store their identifier as a static property. Then i can do AceOfSpades.Identifier to get that identifier.

ive considered two routes, i could define a property or a method.

It dosen't look like i can force a child to define a static property :(
Was this page helpful?