예제 #1
0
        public bool Match(object o)
        {
            var context = new SelectorContext();

            context.Debug(PSDocsResources.SelectorMatchTrace, Id);
            return(_Fn(context, o));
        }
예제 #2
0
        private static bool DebuggerFn(SelectorContext context, string path, SelectorExpressionOuterFn expression, object o)
        {
            var result = expression(context, o);

            context.Debug(PSDocsResources.SelectorTrace, path, result);
            return(result);
        }
예제 #3
0
        internal static bool Exists(SelectorContext context, SelectorInfo info, object[] args, object o)
        {
            var properties = GetProperties(args);

            if (TryPropertyBool(properties, EXISTS, out bool?propertyValue) && TryField(properties, out string field))
            {
                context.Debug(PSDocsResources.SelectorExpressionTrace, EXISTS, field, propertyValue);
                return(propertyValue == ExpressionHelpers.Exists(context, o, field, caseSensitive: false));
            }
            return(false);
        }
예제 #4
0
        internal static bool NotMatch(SelectorContext context, SelectorInfo info, object[] args, object o)
        {
            var properties = GetProperties(args);

            if (TryProperty(properties, NOTMATCH, out object propertyValue) && TryField(properties, out string field))
            {
                context.Debug(PSDocsResources.SelectorExpressionTrace, NOTMATCH, field, propertyValue);
                if (!ObjectHelper.GetField(context, o, field, caseSensitive: false, out object value))
                {
                    return(true);
                }

                return(!ExpressionHelpers.Match(propertyValue, value, caseSensitive: false));
            }
            return(false);
        }
예제 #5
0
        internal static bool HasValue(SelectorContext context, SelectorInfo info, object[] args, object o)
        {
            var properties = GetProperties(args);

            if (TryPropertyBool(properties, HASVALUE, out bool?propertyValue) && TryField(properties, out string field))
            {
                context.Debug(PSDocsResources.SelectorExpressionTrace, HASVALUE, field, propertyValue);
                if (!ObjectHelper.GetField(context, o, field, caseSensitive: false, out object value))
                {
                    return(!propertyValue.Value);
                }

                return(!propertyValue.Value == ExpressionHelpers.NullOrEmpty(value));
            }
            return(false);
        }
예제 #6
0
        internal static bool Equals(SelectorContext context, SelectorInfo info, object[] args, object o)
        {
            var properties = GetProperties(args);

            if (TryProperty(properties, EQUALS, out object propertyValue) && TryField(properties, out string field))
            {
                context.Debug(PSDocsResources.SelectorExpressionTrace, EQUALS, field, propertyValue);
                if (!ObjectHelper.GetField(context, o, field, caseSensitive: false, out object value))
                {
                    return(false);
                }

                // int, string, bool
                return(ExpressionHelpers.Equal(propertyValue, value, caseSensitive: false, convertExpected: true));
            }
            return(false);
        }
예제 #7
0
        internal static bool NotIn(SelectorContext context, SelectorInfo info, object[] args, object o)
        {
            var properties = GetProperties(args);

            if (TryPropertyArray(properties, NOTIN, out Array propertyValue) && TryField(properties, out string field))
            {
                context.Debug(PSDocsResources.SelectorExpressionTrace, NOTIN, field, propertyValue);
                if (!ObjectHelper.GetField(context, o, field, caseSensitive: false, out object value))
                {
                    return(true);
                }

                for (var i = 0; propertyValue != null && i < propertyValue.Length; i++)
                {
                    if (ExpressionHelpers.AnyValue(value, propertyValue.GetValue(i), caseSensitive: false, out _))
                    {
                        return(false);
                    }
                }
                return(true);
            }
            return(false);
        }
예제 #8
0
        internal static bool GreaterOrEquals(SelectorContext context, SelectorInfo info, object[] args, object o)
        {
            var properties = GetProperties(args);

            if (TryPropertyLong(properties, GREATEROREQUALS, out long?propertyValue) && TryField(properties, out string field))
            {
                context.Debug(PSDocsResources.SelectorExpressionTrace, GREATEROREQUALS, field, propertyValue);
                if (!ObjectHelper.GetField(context, o, field, caseSensitive: false, out object value))
                {
                    return(true);
                }

                if (value == null)
                {
                    return(0 >= propertyValue);
                }

                if (ExpressionHelpers.CompareNumeric(value, propertyValue, convert: false, compare: out int compare, value: out _))
                {
                    return(compare >= 0);
                }
            }
            return(false);
        }