Exemplo n.º 1
0
        /// <summary>
        /// Checks if the object is filtered by the provided <see cref="filters"/>.
        /// </summary>
        /// <param name="filters">Filters which must be satisfied.</param>
        /// <param name="obj">Object to check.</param>
        /// <returns>True if <see cref="obj"/> matches all filters.</returns>
        public static bool IsFilterMatch(IEnumerable <StringInstruction> filters, object obj)
        {
            foreach (var cmd in filters)
            {
                if (!ReflectUtil.HasProperty(obj, cmd.PropertyName, out var pi))
                {
                    return(false);
                }
                try
                {
                    if (pi == null)
                    {
                        continue;
                    }
                    if (pi.IsValueEqual(obj, cmd.PropertyValue) == cmd.Evaluator)
                    {
                        continue;
                    }
                }
#pragma warning disable CA1031 // Do not catch general exception types
                // User provided inputs can mismatch the type's required value format, and fail to be compared.
                catch (Exception e)
#pragma warning restore CA1031 // Do not catch general exception types
                {
                    Debug.WriteLine($"Unable to compare {cmd.PropertyName} to {cmd.PropertyValue}.");
                    Debug.WriteLine(e.Message);
                }
                return(false);
            }
            return(true);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Checks if the object is filtered by the provided <see cref="filters"/>.
 /// </summary>
 /// <param name="filters">Filters which must be satisfied.</param>
 /// <param name="obj">Object to check.</param>
 /// <returns>True if <see cref="obj"/> matches all filters.</returns>
 public static bool IsFilterMatch(IEnumerable <StringInstruction> filters, object obj)
 {
     foreach (var cmd in filters)
     {
         if (!ReflectUtil.HasProperty(obj, cmd.PropertyName, out var pi))
         {
             return(false);
         }
         try
         {
             if (pi == null)
             {
                 continue;
             }
             if (pi.IsValueEqual(obj, cmd.PropertyValue) == cmd.Evaluator)
             {
                 continue;
             }
         }
         catch (Exception e)
         {
             Debug.WriteLine($"Unable to compare {cmd.PropertyName} to {cmd.PropertyValue}.");
             Debug.WriteLine(e.Message);
         }
         return(false);
     }
     return(true);
 }
Exemplo n.º 3
0
 /// <summary>
 /// Checks if the <see cref="PKM"/> should be filtered due to the <see cref="StringInstruction"/> provided.
 /// </summary>
 /// <param name="cmd">Command Filter</param>
 /// <param name="pkm">Pokémon to check.</param>
 /// <param name="props">PropertyInfo cache (optional)</param>
 /// <returns>True if filtered, else false.</returns>
 private static bool IsPropertyFiltered(StringInstruction cmd, PKM pkm, IReadOnlyDictionary <string, PropertyInfo> props = null)
 {
     if (IsIdentifierFiltered(cmd, pkm))
     {
         return(true);
     }
     return(!props?.TryGetValue(cmd.PropertyName, out _) ?? !ReflectUtil.HasProperty(pkm, cmd.PropertyName, out _));
 }
Exemplo n.º 4
0
 /// <summary>
 /// Checks if the <see cref="PKM"/> should be filtered due to the <see cref="StringInstruction"/> provided.
 /// </summary>
 /// <param name="cmd">Command Filter</param>
 /// <param name="pkm">Pokémon to check.</param>
 /// <returns>True if filtered, else false.</returns>
 private static bool IsPropertyFiltered(StringInstruction cmd, PKM pkm)
 {
     if (IsIdentifierFiltered(cmd, pkm))
     {
         return(true);
     }
     if (!ReflectUtil.HasProperty(pkm, cmd.PropertyName, out var pi))
     {
         return(false);
     }
     return(pi.IsValueEqual(pkm, cmd.PropertyValue) == cmd.Evaluator);
 }