I have this class that, when run in a console app, produces a formatted json string. Now I want to call this method and return the result.
I'm calling it this way var typeRefPath = GetLists.GetTechType(); But it tells me that it is returning null.
What am I doing wrong?
using System.Linq;
using System.IO;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace AutosortLockers
{
class GetLists
{
public static string TechList { get; set; }
public static string GetTechType()
{
// Load categories.json
JObject catObj = JObject.Load(new JsonTextReader(File.OpenText(Mod.GetModPath() + "/categories.json")));
// Load techtypes.json
JObject ttObj = JObject.Load(new JsonTextReader(File.OpenText(Mod.GetModPath() + "/techtypes.json")));
foreach (var categoriesJson in catObj)
{
// Filter variables
var gameVersions = new HashSet<char> { 'A', '2' };
var categoryIDs = new HashSet<string> { "metals", "tablets" };
var useInMod = new HashSet<bool> { true };
// Right outer join on catObj. Select all Items[*] array items
var query = from c in catObj.SelectTokens("Categories[*]").OfType<JObject>()
// Join catObj with ttObj on CategoryID
join t in ttObj.SelectTokens("TechTypes[*]") on (string)c["CategoryID"] equals (string)t["CategoryID"]
// Process the filters
where categoryIDs.Count() > 0 ?
useInMod.Contains((bool)c["UseInMod"])
&& gameVersions.Contains((char)c["GameVersion"])
&& gameVersions.Contains((char)t["GameVersion"])
&& categoryIDs.Contains((string)c["CategoryID"]) :
useInMod.Contains((bool)c["UseInMod"])
&& gameVersions.Contains((char)c["GameVersion"])
&& gameVersions.Contains((char)t["GameVersion"])
select new
{
CategoryDescription = c["CategoryDescription"],
CategoryID = c["CategoryID"],
TechName = t["TechName"],
TechType = t["TechType"],
TechID = t["TechID"],
GameVersion = t["GameVersion"]
};
// Materialize the query into a list of results.
TechList = JsonConvert.SerializeObject(query.ToArray(), Formatting.Indented);
}
return TechList;
}
}
}```