Exemplo n.º 1
0
        public CAMLBuilder Add(CAMLFilter filter, Closure closure = Closure.And)
        {
            if (filter == null)
            {
                throw new ArgumentNullException("filter");
            }

            if (_query == null)
            {
                _query = filter;
                return(this);
            }

            CAMLFilter newQuery;

            switch (closure)
            {
            case Closure.And:
                newQuery = CAMLFilter.And(_query, filter);
                break;

            case Closure.Or:
                newQuery = CAMLFilter.Or(_query, filter);
                break;

            default:
                throw new ArgumentException("Invalid closure type.", "closure");
            }
            _query = newQuery;
            return(this);
        }
Exemplo n.º 2
0
        public static CAMLFilter Or(CAMLFilter filter1, CAMLFilter filter2)
        {
            var filter = new CAMLFilter();

            filter.FilterExpression = string.Format("<Or>{0}{1}</Or>", filter1, filter2);
            return(filter);
        }
Exemplo n.º 3
0
        public static CAMLFilter Unary(Operator @operator, string name)
        {
            var filter = new CAMLFilter();

            filter.FilterExpression = string.Format(CultureInfo.InvariantCulture,
                                                    "<{0}><FieldRef Name='{1}'/></{0}>", @operator, name);
            return(filter);
        }
Exemplo n.º 4
0
        public static CAMLFilter Filter(Operator @operator, Guid fieldId, object value, SPFieldType camlType)
        {
            var filter = new CAMLFilter();

            filter.FilterExpression = string.Format(CultureInfo.InvariantCulture,
                                                    "<{0}><FieldRef ID='{1}' {4}/><Value Type='{2}'>{3}</Value></{0}>",
                                                    @operator, fieldId, camlType, value, camlType == SPFieldType.User || camlType == SPFieldType.Lookup ? "LookupId='TRUE'" : "");
            return(filter);
        }
Exemplo n.º 5
0
        public static CAMLFilter In(Guid fieldId, IList <object> values, SPFieldType camlType)
        {
            if (!values.Any())
            {
                throw new ArgumentException("values");
            }

            var filter     = new CAMLFilter();
            var valuesCaml = values.Select(x => string.Format("<Value Type='{0}'>{1}</Value>", camlType, x));

            filter.FilterExpression = string.Format(CultureInfo.InvariantCulture,
                                                    "<{0}><FieldRef ID='{1}' {2}/><Values>{3}</Values></{0}>",
                                                    Operator.In, fieldId, camlType == SPFieldType.User || camlType == SPFieldType.Lookup ? "LookupId='TRUE'" : "", string.Join("", valuesCaml));
            return(filter);
        }