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); }
internal static bool Not(SelectorContext context, SelectorInfo info, object[] args, object o) { var inner = GetInner(args); if (inner.Length > 0) { return(!inner[0](context, o)); } return(false); }
internal static bool AllOf(SelectorContext context, SelectorInfo info, object[] args, object o) { var inner = GetInner(args); for (var i = 0; i < inner.Length; i++) { if (!inner[i](context, o)) { return(false); } } return(true); }
private SelectorExpressionOuterFn Operator(string path, SelectorOperator expression) { var inner = new List <SelectorExpressionOuterFn>(expression.Children.Count); for (var i = 0; i < expression.Children.Count; i++) { var childPath = string.Concat(path, OpenBracket, i, CloseBracket); inner.Add(Expression(childPath, expression.Children[i])); } var innerA = inner.ToArray(); var info = new SelectorInfo(path); return((context, o) => expression.Descriptor.Fn(context, info, innerA, o)); }
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); }
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); }
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); }
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); }
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); }
internal static bool StartsWith(SelectorContext context, SelectorInfo info, object[] args, object o) { var properties = GetProperties(args); if (TryPropertyStringArray(properties, STARTSWITH, out string[] propertyValue) && TryOperand(context, o, properties, out object operand))
private static SelectorExpressionOuterFn Condition(string path, SelectorCondition expression) { var info = new SelectorInfo(path); return((context, o) => expression.Descriptor.Fn(context, info, new object[] { expression.Property }, o)); }