Beispiel #1
0
        public static string ToSalesforceString(this NSCompoundPredicateType type)
        {
            switch (type)
            {
            case NSCompoundPredicateType.And:
                return(" AND ");

            case NSCompoundPredicateType.Or:
                return(" OR ");

            case NSCompoundPredicateType.Not:
                throw new NotSupportedException("This probably should be supported");

            default:
                return(string.Empty);
            }
        }
        // -------------------------------------------------------------------------------
        //	spotlightFriendlyPredicate:predicate
        //
        //	This method will "clean up" an NSPredicate to make it ready for Spotlight, or return nil if the predicate can't be cleaned.
        //
        //	Foundation's Spotlight support in NSMetdataQuery places the following requirements on an NSPredicate:
        //		- Value-type (always YES or NO) predicates are not allowed
        //		- Any compound predicate (other than NOT) must have at least two subpredicates
        // -------------------------------------------------------------------------------
        private NSPredicate spotlightFriendlyPredicate(NSPredicate predicate)
        {
            if (predicate.Equals(NSPredicate.FromValue(true)) || predicate.Equals(NSPredicate.FromValue(false)))
            {
                return(null);
            }

            if (predicate is NSCompoundPredicate)
            {
                NSCompoundPredicate     compoundPredicate = predicate as NSCompoundPredicate;
                NSCompoundPredicateType type = compoundPredicate.Type;

                List <NSPredicate> cleanSubPredicates = new List <NSPredicate> ();

                foreach (var dirtySubpredicate in compoundPredicate.Subpredicates)
                {
                    NSPredicate cleanSubPredicate = this.spotlightFriendlyPredicate(dirtySubpredicate);
                    if (cleanSubPredicate != null)
                    {
                        cleanSubPredicates.Add(cleanSubPredicate);
                    }
                }

                if (cleanSubPredicates.Count == 0)
                {
                    return(null);
                }

                if (cleanSubPredicates.Count == 1 && type != NSCompoundPredicateType.Not)
                {
                    return(cleanSubPredicates.First());
                }
                else
                {
                    return(new NSCompoundPredicate(type, cleanSubPredicates.ToArray()));
                }
            }
            else
            {
                return(predicate);
            }
        }
 public NSCompoundPredicate(NSCompoundPredicateType type, AnyObject[] subpredicates)
 {
 }