Ejemplo n.º 1
0
        public static SentinelsSheet LoadJsonText(string text)
        {
            JsonSerializerSettings sss = new JsonSerializerSettings();

            sss.DefaultValueHandling = DefaultValueHandling.Ignore;
            sss.NullValueHandling    = NullValueHandling.Ignore;
            sss.ContractResolver     = new CamelCasePropertyNamesContractResolver();
            sss.Error += (object?sender, Newtonsoft.Json.Serialization.ErrorEventArgs e) => ErrorHandler(sender, e, "");

            SentinelsSheet ss = JsonConvert.DeserializeObject <SentinelsSheet>(text, sss) !;

            ss.SetupSheet();
            return(ss);
        }
Ejemplo n.º 2
0
 public static SentinelsSheet LoadJsonFile(string filename)
 {
     using (StreamReader file = File.OpenText(filename))
     {
         try
         {
             JsonSerializer serializer = new JsonSerializer();
             serializer.DefaultValueHandling = DefaultValueHandling.Ignore;
             serializer.NullValueHandling    = NullValueHandling.Ignore;
             serializer.ContractResolver     = new CamelCasePropertyNamesContractResolver();
             serializer.Error += (object?sender, Newtonsoft.Json.Serialization.ErrorEventArgs e) => ErrorHandler(sender, e, filename);
             SentinelsSheet ss = (SentinelsSheet)serializer.Deserialize(file, typeof(SentinelsSheet)) !;
             ss.SetupSheet();
             return(ss);
         }
         catch (JsonReaderException e)
         {
             throw new InvalidDataException("This file does not match the format for JSON. Check if it isn't corrupted by opening it in Notepad or another text editor.", e);
         }
     }
 }