Click here to Skip to main content
15,893,663 members
Articles / Programming Languages / C#

CAMLBuilder Expressions

Rate me:
Please Sign up or sign in to vote.
4.70/5 (13 votes)
25 Nov 2009CPOL7 min read 66.4K   1.7K   26  
Building CAML queries programmatically using Expressions
using System;
using System.Collections.Generic;
using System.Text;

namespace TK.SPTools.CAMLBuilder.Expressions
{
    public class SimpleCriteria : Criteria
    {
        protected SimpleCriteria()
        {
        }

        internal SimpleCriteria(string fieldName, CriteriaType criteriaType)
            : base(fieldName, criteriaType)
        {
        }

        public override string Value
        {
            get
            {
                throw new NotSupportedException("SimpleCriteria does not have a Value element.");
            }
            set
            {
                throw new NotSupportedException("SimpleCriteria does not have a Value element.");
            }
        } 

        protected internal override string GetCAMLInternal()
        {
            string str = @"<{0}>
                               <FieldRef Name='{1}' {2}/>
                          </{0}>";

            return string.Format(str, GetCriteriaSymbol(), _fieldName, GetAttributes(_fieldRefAttributes));
        }

        public override Criteria AddValueAttribute(string name, string value)
        {
            throw new NotSupportedException("Simple criteria does not have Value element.");
        }

        public override Criteria AddFieldRefAttribute(string name, string value)
        {
            _fieldRefAttributes.Add(name, value);

            return this;
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Ireland Ireland
.NET Developer.

Comments and Discussions