Ejemplo n.º 1
0
 /// <summary>
 /// Adds the techs for every registered building to the database.
 /// </summary>
 internal static void AddAllTechs()
 {
     if (buildingTable == null)
     {
         throw new InvalidOperationException("Building table not loaded");
     }
     lock (PSharedData.GetLock(PRegistry.KEY_BUILDING_LOCK)) {
         PRegistry.LogPatchDebug("Register techs for {0:D} buildings".F(
                                     buildingTable.Count));
         foreach (var building in buildingTable)
         {
             if (building != null)
             {
                 var trBuilding = Traverse.Create(building);
                 // Building is of type object because it is in another assembly
                 var addTech = Traverse.Create(building).Method(nameof(AddTech));
                 if (addTech.MethodExists())
                 {
                     addTech.GetValue();
                 }
                 else
                 {
                     PRegistry.LogPatchWarning("Invalid building technology!");
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Adds the techs for every registered building to the database.
 /// </summary>
 internal static void AddAllTechs()
 {
     if (buildingTable == null)
     {
         throw new InvalidOperationException("Building table not loaded");
     }
     lock (PSharedData.GetLock(PRegistry.KEY_BUILDING_LOCK)) {
         PRegistry.LogPatchDebug("Register techs for {0:D} buildings".F(
                                     buildingTable.Count));
         foreach (var building in buildingTable)
         {
             if (building != null)
             {
                 try {
                     var trBuilding = Traverse.Create(building);
                     // Building is of type object because it is in another assembly
                     var addTech = Traverse.Create(building).Method(nameof(AddTech));
                     if (addTech.MethodExists())
                     {
                         addTech.GetValue();
                     }
                     else
                     {
                         PRegistry.LogPatchWarning("Invalid building technology!");
                     }
                 } catch (System.Reflection.TargetInvocationException e) {
                     // Log errors when registering building from another mod
                     PUtil.LogError("Unable to add building tech for " +
                                    building.GetType().Assembly?.GetNameSafe() + ":");
                     PUtil.LogException(e.GetBaseException());
                 }
             }
         }
     }
 }