Esempio n. 1
0
 private static string GetPart(string part, Package package, Type recordType, string file, string name)
 {
     if (part.StartsWith("[") && part.EndsWith("]") && part.Length > 2)
     {
         string[] vars = part.Substring(1, part.Length - 2).Split(new[] { '.' });
         if (vars.Length != 2)
         {
             throw new InternalError("Invalid variable {0} for column {1} in {2}", part, name, file);
         }
         if (vars[0] == "Globals")
         {
             FieldInfo fi = typeof(Globals).GetField(vars[1], BindingFlags.Public | BindingFlags.Static);
             if (fi == null)
             {
                 throw new InternalError("Globals.{0} doesn't exist - column {1} in {2}", vars[1], name, file);
             }
             part = fi.GetValue(null).ToString();
         }
         else if (vars[0] == "Package")
         {
             VersionManager.AddOnProduct addonVersion = VersionManager.FindPackageVersion(package.AreaName);
             foreach (var type in addonVersion.SupportTypes)
             {
                 object o = Activator.CreateInstance(type);
                 if (o == null)
                 {
                     throw new InternalError($"Type {type.Name} can't be created for area {package.AreaName}");
                 }
                 FieldInfo fi = type.GetField(vars[1], BindingFlags.Public | BindingFlags.Static);
                 if (fi != null)
                 {
                     part = fi.GetValue(null).ToString();
                     break;
                 }
             }
         }
         else
         {
             throw new InternalError("Unknown variable {0} for column {1} in {2}", part, name, file);
         }
     }
     return(part);
 }