예제 #1
0
        /// <summary>
        /// Used internaly to get CAML markup from elements.
        /// </summary>
        public virtual string GetCaml()
        {
            var tag = new CamlTag(Tag.ToString());
            var properties = GetType().GetProperties();

            foreach (var property in properties)
            {
                var attribute = (CQAttributeAttribute)property.GetCustomAttributes(typeof(CQAttributeAttribute), true).FirstOrDefault();
                if (attribute == null) continue;

                var name = attribute.Name ?? property.Name;

                tag.MergeAttribute(name, property.GetValue(this, null));
            }

            if (_elements.Count != 0)
            {
                var builder = new StringBuilder();

                foreach (var element in _elements)
                {
                    builder.Append(element.GetCaml());
                }

                tag.InnerText = builder.ToString();
            }
            else
            {
                tag.InnerText = InnerText;
            }

            return tag.ToString();
        }
예제 #2
0
        public void CamlTag_CreatesSelfClosingTagWithSpecifiedName()
        {
            Expected = "<Tag />";

            var tag = new CamlTag("Tag");
            var caml = tag.ToString();

            Assert.That(caml, Is.EqualTo(Expected));
        }
예제 #3
0
        public void CamlTag_CreatesTagWithInnerValue()
        {
            Expected = "<Tag>x</Tag>";

            var tag = new CamlTag("Tag");
            tag.InnerText = "x";
            var caml = tag.ToString();

            Assert.That(caml, Is.EqualTo(Expected));
        }
예제 #4
0
        public void CamlTag_CreatesTagWithAttribute()
        {
            Expected = "<Tag Attr='a1' />";

            var tag = new CamlTag("Tag");
            tag.MergeAttribute("Attr", "a1");
            var caml = tag.ToString();

            Assert.That(caml, Is.EqualTo(Expected));
        }
예제 #5
0
        public void CamlTag_CreatesTagWithValueAndAttributes()
        {
            Expected = "<Tag Attr='a1' Xy='zz'>x</Tag>";

            var tag = new CamlTag("Tag");
            tag.MergeAttribute("Attr", "a1");
            tag.MergeAttribute("Xy", "zz");
            tag.InnerText = "x";
            var caml = tag.ToString();

            Assert.That(caml, Is.EqualTo(Expected));
        }