I have some problems with initialization of static member objects. In my project are 3 class files:
Feat, Class (RPG-style not c# class), and Race.
Each of them has some static member objects that can be accessed by for example Feat.General.MightyBlow, Race.Dwarf, or Class.Base.Warrior while MightyBlow.GetType() -> Feat, Dwarf.GetType() -> Race, and Warrior.GetType() -> Class. A feat can be dependent on other feats, classes and races, same goes with classes and races. Each of those 3 categories is not referenced by a true class/feat/race but by a name string that can be looked up in a dictionary like: Class someClass = Class.Implemented[someClassesName].
Some minimal example:
public static Feat ArmorHeavy = new Feat(
"ArmorHeavy",
Req.Feats(ArmorLight.GetName),
);
public static Feat ArmorLight = new Feat(
"ArmorLight",
Req.Feats(),
);
As you can see ArmorHeavy needs ArmorLight first to be available and that requirement is only identified by ArmorLight's name (simply a string "ArmorLight").
I get no compiler errors but when run this I get the following error
NullReferenceException: Object reference not set to an instance of an object Feat+Proficiency..cctor ()
I thought during initializing of ArmorHeavy C# reaches the point, where ArmorLight.GetName gets called, now jumping to initialization of ArmorLight and finishing ArmorHeavy after ArmorLight was initialized. This is not the case because if I interchange the position of those two member objects or delete the requirement there will be no errors.
How can I solve this? Please don't tell me that I have to order all feats accordingly.
ArmorHeavydependent onArmorLight? Presumably they should both be dependent on some more abstractArmortype, no?