Пример #1
0
 public void Validate(JObject jsonPacket, PacketProblems problems)
 {
     foreach (string key in _requiredKeys)
     {
         if (IsMissingValue(jsonPacket[key]))
         {
             problems.Error($"Missing required key \'{key}\'");
         }
         else
         {
             problems.Information($"Required key \'{key}\' actually exists");
         }
     }
 }
Пример #2
0
 public void Validate(JObject jsonPacket, PacketProblems problems)
 {
     foreach (string key in _forbiddenKeys)
     {
         if (IsMissingValue(jsonPacket[key]))
         {
             problems.Information($"Forbidden key \'{key}\' does not exist");
         }
         else
         {
             problems.Error($"Forbidden key \'{key}\' actually exists");
         }
     }
 }
Пример #3
0
 public void Validate(JObject jsonPacket, PacketProblems problems)
 {
     foreach (string key in _forbiddenKeys)
     {
         JToken token = jsonPacket[key];
         // Tests as suggested by NewtonSoft recommendations
         if ((token == null) ||
             (token.Type == JTokenType.Array && !token.HasValues) ||
             (token.Type == JTokenType.Object && !token.HasValues) ||
             (token.Type == JTokenType.String && token.ToString() == String.Empty) ||
             (token.Type == JTokenType.Null))
         {
             problems.Information("Forbidden key '" + key + "' does not exist");
         }
         else
         {
             problems.Error("Forbidden key '" + key + "' actually exists");
         }
     }
 }