© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•7mo ago•
71 replies
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
ICard
,
ICharacter
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
minecraf:dirt
, or
create:pipe
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<T>
.

Identifier is like a weird singleton. its
T
T
(i am sure there is a proper name for this, i don't know it) represents the ContentType, like
ICard
ICard
or
ICharacter
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))
Identifier<ICard>(typeof(TheBestMod), typeof(AceOfSpades))
. ICard is the content type,
TheBestMod
TheBestMod
is the expansion and
AceOfSpades
AceOfSpades
is the content being added.

Ok, the problem is i want the ContentType classes (ie,
ICard
ICard
,
ICharacter
ICharacter
, etc) to require their children, the actual content, to store their identifier as a static property. Then i can do
AceOfSpades.Identifier
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 :(
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements
Next page

Similar Threads

❔ Static interface methods
C#CC# / help
3y ago
✅ Can I use static abstract interface members in netstandard2.1?
C#CC# / help
4y ago
✅ The interface has static abstract members without implementations. How to fix?
C#CC# / help
6mo ago